1- import { CONNECTOR_EVENTS , IProvider , PLUGIN_EVENTS , WalletServicesPlugin , Web3Auth , WEB3AUTH_NETWORK_TYPE , SMART_ACCOUNT } from "@web3auth/modal" ;
1+ import { CONNECTOR_EVENTS , IProvider , PLUGIN_EVENTS , WalletServicesPluginType , Web3Auth , WEB3AUTH_NETWORK_TYPE , SMART_ACCOUNT , walletServicesPlugin , EVM_PLUGINS } from "@web3auth/modal" ;
22import { createContext , FunctionComponent , ReactNode , useContext , useEffect , useState } from "react" ;
33import { CHAIN_CONFIG , CHAIN_CONFIG_TYPE } from "../config/chainConfig" ;
44import * as ethHandler from "./ethHandler" ;
@@ -63,7 +63,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
6363 const [ web3Auth , setWeb3Auth ] = useState < Web3Auth | null > ( null ) ;
6464 const [ provider , setProvider ] = useState < IProvider | null > ( null ) ;
6565 const [ waasProvider , setWaasProvider ] = useState < IProvider | null > ( null ) ;
66- const [ walletServicesPlugin , setWalletServicesPlugin ] = useState < WalletServicesPlugin | null > ( null ) ;
66+ const [ wsPlugin , setWsPlugin ] = useState < WalletServicesPluginType | null > ( null ) ;
6767 const [ user , setUser ] = useState < unknown | null > ( null ) ;
6868 const [ isLoading , setIsLoading ] = useState ( false ) ;
6969
@@ -90,7 +90,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
9090 } ) ;
9191 } ;
9292
93- const subscribePluginEvents = ( plugin : WalletServicesPlugin ) => {
93+ const subscribePluginEvents = ( plugin : WalletServicesPluginType ) => {
9494 // Can subscribe to all PLUGIN_EVENTS and LOGIN_MODAL_EVENTS
9595 plugin . on ( PLUGIN_EVENTS . CONNECTED , ( data : unknown ) => {
9696 console . log ( "Yeah!, you are successfully logged in to plugin" ) ;
@@ -147,19 +147,18 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
147147 primaryButton : "socialLogin" ,
148148 } ,
149149 enableLogging : true ,
150+ plugins : [ walletServicesPlugin ( ) ] ,
150151 } ) ;
151152
152- // Wallet Services Plugin
153-
154- const walletServicesPlugin = new WalletServicesPlugin ( ) ;
155-
156- subscribePluginEvents ( walletServicesPlugin ) ;
157- setWalletServicesPlugin ( walletServicesPlugin ) ;
158- web3AuthInstance . addPlugin ( walletServicesPlugin ) ;
153+ setWsPlugin ( wsPlugin ) ;
159154
160155 subscribeAuthEvents ( web3AuthInstance ) ;
161156 setWeb3Auth ( web3AuthInstance ) ;
162- await web3AuthInstance . initModal ( ) ;
157+ await web3AuthInstance . init ( ) ;
158+
159+ const plugin = web3AuthInstance . getPlugin ( EVM_PLUGINS . WALLET_SERVICES ) as WalletServicesPluginType ;
160+ setWsPlugin ( plugin ) ;
161+ subscribePluginEvents ( plugin ) ;
163162 } catch ( error ) {
164163 console . error ( error ) ;
165164 } finally {
@@ -265,7 +264,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
265264 } ;
266265
267266 const showWalletConnectScanner = async ( ) => {
268- if ( ! walletServicesPlugin ) {
267+ if ( ! wsPlugin ) {
269268 console . log ( "walletServicesPlugin not initialized yet" ) ;
270269 uiConsole ( "walletServicesPlugin not initialized yet" ) ;
271270 return ;
@@ -275,11 +274,11 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
275274 uiConsole ( "web3Auth not initialized yet" ) ;
276275 return ;
277276 }
278- await walletServicesPlugin . showWalletConnectScanner ( ) ;
277+ await wsPlugin . showWalletConnectScanner ( ) ;
279278 } ;
280279
281280 const showWalletUi = async ( ) => {
282- if ( ! walletServicesPlugin ) {
281+ if ( ! wsPlugin ) {
283282 console . log ( "walletServicesPlugin not initialized yet" ) ;
284283 uiConsole ( "walletServicesPlugin not initialized yet" ) ;
285284 return ;
@@ -289,7 +288,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
289288 uiConsole ( "web3Auth not initialized yet" ) ;
290289 return ;
291290 }
292- await walletServicesPlugin . showWalletUi ( ) ;
291+ await wsPlugin . showWalletUi ( ) ;
293292 } ;
294293
295294 const uiConsole = ( ...args : unknown [ ] ) : void => {
0 commit comments