@@ -7,6 +7,7 @@ export interface IWeb3AuthContext {
77 web3Auth : Web3Auth | null ;
88 provider : IProvider | null ;
99 isLoading : boolean ;
10+ isReady : boolean ;
1011 user : unknown ;
1112 chain : string ;
1213 login : ( ) => Promise < void > ;
@@ -29,6 +30,7 @@ export const Web3AuthContext = createContext<IWeb3AuthContext>({
2930 isLoading : false ,
3031 user : null ,
3132 chain : "" ,
33+ isReady : false ,
3234 login : async ( ) => { } ,
3335 logout : async ( ) => { } ,
3436 getUserInfo : async ( ) => { } ,
@@ -66,6 +68,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
6668 const [ wsPlugin , setWsPlugin ] = useState < WalletServicesPluginType | null > ( null ) ;
6769 const [ user , setUser ] = useState < unknown | null > ( null ) ;
6870 const [ isLoading , setIsLoading ] = useState ( false ) ;
71+ const [ isReady , setIsReady ] = useState ( false ) ;
6972
7073 useEffect ( ( ) => {
7174 const subscribeAuthEvents = ( web3auth : Web3Auth ) => {
@@ -88,6 +91,11 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
8891 web3auth . on ( CONNECTOR_EVENTS . ERRORED , ( error ) => {
8992 console . error ( "some error or user has cancelled login request" , error ) ;
9093 } ) ;
94+
95+ web3auth . on ( CONNECTOR_EVENTS . READY , ( ) => {
96+ console . log ( "web3auth is ready" ) ;
97+ setIsReady ( true ) ;
98+ } ) ;
9199 } ;
92100
93101 const subscribePluginEvents = ( plugin : WalletServicesPluginType ) => {
@@ -109,63 +117,51 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
109117 console . error ( "some error on plugin login" , error ) ;
110118 } ) ;
111119 } ;
120+ const controller = new AbortController ( ) ;
112121
113122 async function init ( ) {
114123 try {
115124 const currentChainConfig = CHAIN_CONFIG [ chain ] ;
116125 setIsLoading ( true ) ;
117126 const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ" ;
118-
119127 const web3AuthInstance = new Web3Auth ( {
120128 // get your client id from https://dashboard.web3auth.io
121129 clientId,
122130 web3AuthNetwork,
123- accountAbstractionConfig : {
124- smartAccountType : SMART_ACCOUNT . SAFE ,
125- bundlerConfig : {
126- url : `https://api.pimlico.io/v2/11155111/rpc?apikey=${ pimlicoAPIKey } ` ,
127- } ,
128- paymasterConfig : {
129- url : `https://api.pimlico.io/v2/11155111/rpc?apikey=${ pimlicoAPIKey } ` ,
130- } ,
131- } ,
132131 chains : [ currentChainConfig ] ,
133132 uiConfig : {
134- uxMode : "redirect" ,
135133 appName : "W3A Heroes" ,
136134 appUrl : "https://web3auth.io/" ,
137135 theme : {
138136 primary : "#5f27cd" ,
139137 onPrimary : "white" ,
140138 } ,
141- logoLight : "https://web3auth.io/images/web3auth-logo.svg" ,
142- logoDark : "https://web3auth.io/images/web3auth-logo.svg" ,
143139 defaultLanguage : "en" , // en, de, ja, ko, zh, es, fr, pt, nl, tr
144140 mode : "auto" , // whether to enable dark mode. defaultValue: auto
145141 // useLogoLoader: true,
146142 loginGridCol : 3 ,
147143 primaryButton : "socialLogin" ,
148144 } ,
149145 enableLogging : true ,
150- plugins : [ walletServicesPlugin ( ) ] ,
146+ authBuildEnv : "testing"
151147 } ) ;
152148
153- setWsPlugin ( wsPlugin ) ;
154149
155150 subscribeAuthEvents ( web3AuthInstance ) ;
156151 setWeb3Auth ( web3AuthInstance ) ;
157- await web3AuthInstance . init ( ) ;
152+ await web3AuthInstance . initModal ( { signal : controller . signal } ) ;
158153
159- const plugin = web3AuthInstance . getPlugin ( EVM_PLUGINS . WALLET_SERVICES ) as WalletServicesPluginType ;
160- setWsPlugin ( plugin ) ;
161- subscribePluginEvents ( plugin ) ;
162154 } catch ( error ) {
163155 console . error ( error ) ;
164156 } finally {
165157 setIsLoading ( false ) ;
166158 }
167159 }
168160 init ( ) ;
161+
162+ return ( ) => {
163+ controller . abort ( ) ;
164+ } ;
169165 } , [ chain , web3AuthNetwork ] ) ;
170166
171167 const login = async ( ) => {
@@ -304,6 +300,7 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
304300 provider,
305301 user,
306302 isLoading,
303+ isReady,
307304 login,
308305 logout,
309306 getUserInfo,
0 commit comments