useEffect(() => {
const init = async () => {
try {
const web3auth = new Web3Auth({
clientId,
chainConfig: flareConfig,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
// uiConfig refers to the whitelabeling options, which is available only on Growth Plan and above
// Please remove this parameter if you’re on the Base Plan
uiConfig: {
appName: “W3A”,
theme: {
primary: “blue”,
},
mode: “light”,
logoLight: “https://web3auth.io/images/web3auth-logo.svg”,
logoDark: “https://web3auth.io/images/web3auth-logo---Dark.svg”,
defaultLanguage: “en”, // en, de, ja, ko, zh, es, fr, pt, nl
loginGridCol: 3,
primaryButton: “externalLogin”, // “externalLogin” | “socialLogin” | “emailLogin”
},
});
const openloginAdapter = new OpenloginAdapter({
loginSettings: {
mfaLevel: "optional",
},
adapterSettings: {
uxMode: "redirect", // "redirect" | "popup"
whiteLabel: {
logoLight: "https://web3auth.io/images/web3auth-logo.svg",
logoDark: "https://web3auth.io/images/web3auth-logo---Dark.svg",
defaultLanguage: "en", // en, de, ja, ko, zh, es, fr, pt, nl
mode: "dark", // whether to enable dark, light or auto mode. defaultValue: auto [ system theme]
},
mfaSettings: {
deviceShareFactor: {
enable: true,
priority: 1,
mandatory: true,
},
backUpShareFactor: {
enable: true,
priority: 2,
mandatory: false,
},
socialBackupFactor: {
enable: true,
priority: 3,
mandatory: false,
},
passwordFactor: {
enable: true,
priority: 4,
mandatory: false,
},
},
},
});
web3auth.configureAdapter(openloginAdapter);
const torusPlugin = new TorusWalletConnectorPlugin({
torusWalletOpts: {},
walletInitOptions: {
whiteLabel: {
theme: { isDark: true, colors: { primary: "#00a8ff" } },
logoDark: "https://web3auth.io/images/web3auth-logo.svg",
logoLight: "https://web3auth.io/images/web3auth-logo---Dark.svg",
},
useWalletConnect: true,
enableLogging: true,
},
});
setTorusPlugin(torusPlugin);
await web3auth.addPlugin(torusPlugin);
// read more about adapters here: https://web3auth.io/docs/sdk/pnp/web/adapters/
// adding wallet connect v2 adapter
const defaultWcSettings = await getWalletConnectV2Settings(
"eip155",
[1],
"04309ed1007e77d1f119b85205bb779d"
);
const walletConnectV2Adapter = new WalletConnectV2Adapter({
adapterSettings: { ...defaultWcSettings.adapterSettings },
loginSettings: { ...defaultWcSettings.loginSettings },
});
web3auth.configureAdapter(walletConnectV2Adapter);
// adding metamask adapter
const metamaskAdapter = new MetamaskAdapter({
clientId,
sessionTime: 3600, // 1 hour in seconds
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
chainConfig: flareConfig,
});
// we can change the above settings using this function
metamaskAdapter.setAdapterSettings({
sessionTime: 86400, // 1 day in seconds
chainConfig: flareConfig,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
});
// it will add/update the metamask adapter in to web3auth class
web3auth.configureAdapter(metamaskAdapter);
const torusWalletAdapter = new TorusWalletAdapter({
clientId,
});
// it will add/update the torus-evm adapter in to web3auth class
web3auth.configureAdapter(torusWalletAdapter);
setWeb3auth(web3auth);
await web3auth.initModal({
modalConfig: {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: "openlogin",
loginMethods: {
// Disable facebook and reddit
facebook: {
name: "facebook",
showOnModal: false,
},
reddit: {
name: "reddit",
showOnModal: false,
},
google: {
name: "google",
showOnModal: false,
},
discord: {
name: "discord",
showOnModal: false,
},
twitch: {
name: "twitch",
showOnModal: false,
},
apple: {
name: "apple",
showOnModal: false,
},
line: {
name: "line",
showOnModal: false,
},
github: {
name: "github",
showOnModal: false,
},
kakao: {
name: "kakao",
showOnModal: false,
},
linkedin: {
name: "linkedin",
showOnModal: false,
},
twitter: {
name: "twitter",
showOnModal: false,
},
weibo: {
name: "weibo",
showOnModal: false,
},
wechat: {
name: "wechat",
showOnModal: false,
},
sms_passwordless: {
name: "sms_passwordless",
showOnModal: false,
},
},
},
},
});
if (web3auth.connected) {
setLoggedIn(true);
}
} catch (error) {
console.log("wallet--init--catch", error);
}
};
init();
}, []);