ankit.thakur:
Inpageprovider
const subscribeAuthEvents = (
web3auth: Web3Auth,
torusPlugin: TorusWalletConnectorPlugin,
dispatch: any,
setTorusPlugins: any
) => {
web3auth.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, (isVisible) => {
});
web3auth.on(LOGIN_MODAL_EVENTS.INIT_EXTERNAL_WALLETS, () => {});
web3auth.on(ADAPTER_EVENTS.CONNECTED, (data: unknown) => {
setTorusPlugins(torusPlugin);
dispatch(setProvider(web3auth?.provider));
});
web3auth.on(ADAPTER_EVENTS.NOT_READY, () => {});
web3auth.on(ADAPTER_EVENTS.CONNECTING, () => {
// setLoaderLogin(true);
});
web3auth.on(ADAPTER_EVENTS.DISCONNECTED, () => {
});
web3auth.on(ADAPTER_EVENTS.ERRORED, (error) => {
});
};
export const initializeWeb3 = async (
dispatch: any,
setTorusPlugins: any,
torusPlugin: any
) => {
try {
const web3auth = new Web3Auth({
clientId:envs.CLIENT_ID, // Get your Client ID from Web3Auth Dashboard
web3AuthNetwork: “testnet”,
uiConfig: {
appName: “W3A”, // ← Your dApp Name
appLogo: “https://web3auth.io/images/w3a-L-Favicon-1.svg ”, // Your dApp Logo URL
theme: “dark”, // “light” | “dark” | “auto”
loginMethodsOrder: [
“google”,
“facebook”,
“apple”,
“twitter”,
“github”,
“linkedin”,
“twitch”,
“discord”,
],
},
chainConfig: {
chainNamespace: “eip155”,
chainId: “0x5”, // Please use 0x5 for Goerli Testnet
rpcTarget:
“https://goerli.infura.io/v3/a9f5841536114cf7a67969365e45ad69 ”,
displayName: “Goerli Test Network”,
ticker: “ETH”,
tickerName: “Ethereum”,
},
});
const openloginAdapter = new OpenloginAdapter({
loginSettings: {
mfaLevel: “none”,
},
adapterSettings: {
uxMode: “popup”, // “redirect” | “popup”,
// NETWORK
network: “testnet”,
// clientId,
whiteLabel: {
name: “eew”,
theme: {
primary: “#FFA500 ”,
},
defaultLanguage: “en”,
},
},
});
web3auth.configureAdapter(openloginAdapter);
const torusPlugin = new TorusWalletConnectorPlugin({
torusWalletOpts: {},
walletInitOptions: {
whiteLabel: {
theme: { isDark: true, colors: { primary: “#00a8ff ” } },
logoDark: “https://web3auth.io/images/w3a-L-Favicon-1.svg ”,
logoLight: “https://web3auth.io/images/w3a-D-Favicon-1.svg ”,
},
// showTorusButton: true,
useWalletConnect: true,
enableLogging: true,
},
});
console.log(torusPlugin, "kjkhjikhwihewwe2");
setTorusPlugins(torusPlugin);
await web3auth.addPlugin(torusPlugin);
// adding wallet connect v1 adapter
const walletConnectV1Adapter = new WalletConnectV1Adapter({});
web3auth.configureAdapter(walletConnectV1Adapter);
// adding metamask adapter
const metamaskAdapter = new MetamaskAdapter({
sessionTime: 86400, // 1 day in seconds
web3AuthNetwork: "testnet",
});
// it will add/update the metamask adapter in to web3auth class
web3auth.configureAdapter(metamaskAdapter);
const torusWalletAdapter = new TorusWalletAdapter({
clientId:envs.CLIENT_ID,
});
web3auth.configureAdapter(torusWalletAdapter);
subscribeAuthEvents(web3auth, torusPlugin, dispatch, setTorusPlugins);
// web3auth.configureAdapter(openloginAdapter);
await web3auth.initModal();
dispatch(setweb3auth(web3auth));
if (torusPlugin) {
dispatch(setProvider(web3auth.provider));
}
console.log(web3auth.provider);
dispatch(setProvider(web3auth.provider));
} catch (er: any) {
toasts.error(er?.message);
console.log(“skajfksa”, er);
return;
}
};