@@ -2,7 +2,6 @@ import { useEffect, useState } from "react";
22import {
33 Web3AuthMPCCoreKit ,
44 WEB3AUTH_NETWORK ,
5- SubVerifierDetailsParams ,
65 COREKIT_STATUS ,
76 makeEthereumSigner ,
87 AggregateVerifierLoginParams ,
@@ -117,9 +116,9 @@ export const DEFAULT_CHAIN_CONFIG: CustomChainConfig = {
117116} ;
118117
119118function App ( ) {
120- const { coreKitInstance, passkeyPlugin, setCoreKitInstance, coreKitStatus, setCoreKitStatus, provider, setProvider, setWeb3 } = useCoreKit ( ) ;
119+ const { coreKitInstance, passkeyPlugin, setCoreKitInstance, coreKitStatus, setCoreKitStatus, provider, setProvider, setWeb3, setUserInfo , globalLoading , getShareDescriptions } = useCoreKit ( ) ;
121120
122- const [ isLoading , setIsLoading ] = useState ( false ) ;
121+ const [ isLoading , setIsLoading ] = useState ( true ) ;
123122 const navigate = useNavigate ( ) ;
124123 const [ selectedTssLib , setSelectedTssLib ] = useState < TssLib > ( tssLibDkls ) ;
125124
@@ -136,16 +135,17 @@ function App() {
136135 // decide whether to rehydrate session
137136 const init = async ( ) => {
138137 // Example config to handle redirect result manually
138+ setIsLoading ( true ) ;
139139 if ( coreKitInstance . status === COREKIT_STATUS . NOT_INITIALIZED ) {
140- await coreKitInstance . init ( { rehydrate : true , handleRedirectResult : true } ) ;
140+ await coreKitInstance . init ( { rehydrate : true , handleRedirectResult : false } ) ;
141141 setCoreKitInstance ( coreKitInstance ) ;
142142 await passkeyPlugin . initWithMpcCoreKit ( coreKitInstance ) ;
143- if ( window . location . hash . includes ( "state" ) ) {
144- // await coreKitInstance.handleRedirectResult();
145- }
143+ setIsLoading ( false ) ;
146144 }
147145 if ( coreKitInstance . status === COREKIT_STATUS . LOGGED_IN ) {
148146 await setupProvider ( ) ;
147+ setUserInformation ( ) ;
148+ setIsLoading ( false ) ;
149149 }
150150
151151 if ( coreKitInstance . status === COREKIT_STATUS . REQUIRED_SHARE ) {
@@ -154,16 +154,31 @@ function App() {
154154 "required more shares, please enter your backup/ device factor key, or reset account unrecoverable once reset, please use it with caution]"
155155 ) ;
156156 }
157-
158157 console . log ( "coreKitInstance.status" , coreKitInstance . status ) ;
159158 setCoreKitStatus ( coreKitInstance . status ) ;
160159 } ;
161160
161+ useEffect ( ( ) => {
162+ const checkForRecoveryInitiation = async ( ) => {
163+ if ( coreKitInstance . status === COREKIT_STATUS . REQUIRED_SHARE ) {
164+ navigate ( "/recovery" ) ;
165+ uiConsole (
166+ "required more shares, please enter your backup/ device factor key, or reset account unrecoverable once reset, please use it with caution]"
167+ ) ;
168+ }
169+ }
170+ checkForRecoveryInitiation ( ) ;
171+ } , [ coreKitStatus ] )
172+
173+ useEffect ( ( ) => {
174+ setIsLoading ( globalLoading || false ) ;
175+ } , [ globalLoading ] ) ;
176+
162177 useEffect ( ( ) => {
163178 const instance = new Web3AuthMPCCoreKit ( {
164179 web3AuthClientId : "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ" ,
165180 web3AuthNetwork : selectedNetwork ,
166- uxMode : "redirect " ,
181+ uxMode : "popup " ,
167182 manualSync : false ,
168183 storage : window . localStorage ,
169184 tssLib : selectedTssLib ,
@@ -190,32 +205,30 @@ function App() {
190205 if ( ! coreKitInstance ) {
191206 throw new Error ( "initiated to login" ) ;
192207 }
193- const verifierConfig = {
194- aggregateVerifierIdentifier : "web-aggregate-core-kit" ,
195- subVerifierDetailsArray : [
196- {
197- typeOfLogin : "google" ,
198- verifier : "web3-aggreate-google" ,
199- clientId : "759944447575-6rm643ia1i9ngmnme3eq5viiep5rp6s0.apps.googleusercontent.com" ,
200- jwtParams : {
201- verifierIdField : "email" ,
202- } ,
203- } ,
204- ] ,
205- } ;
208+ const verifierConfig = {
209+ subVerifierDetails : {
210+ typeOfLogin : "google" ,
211+ verifier : "w3a-google-demo" ,
212+ clientId : "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com" ,
213+ } ,
214+ } ;
206215 // const verifierConfig = {
207- // subVerifierDetails: {
208- // typeOfLogin: "google",
209- // verifier: "w3-google-temp",
210- // clientId: "759944447575-6rm643ia1i9ngmnme3eq5viiep5rp6s0.apps.googleusercontent.com",
211- // },
212- // } as SubVerifierDetailsParams;
216+ // aggregateVerifierIdentifier: "web-aggregate-core-kit",
217+ // subVerifierDetails: [
218+ // {
219+ // typeOfLogin: "google",
220+ // verifier: "web3-aggreate-google",
221+ // clientId: "759944447575-6rm643ia1i9ngmnme3eq5viiep5rp6s0.apps.googleusercontent.com",
222+ // },
223+ // ],
224+ // };
213225
214226 await coreKitInstance . loginWithOAuth ( verifierConfig as any ) ;
215227 if ( coreKitInstance . status === COREKIT_STATUS . LOGGED_IN ) {
216228 await coreKitInstance . commitChanges ( ) ; // Needed for new accounts
217229 }
218230 setCoreKitStatus ( coreKitInstance . status ) ;
231+ setUserInformation ( ) ;
219232 } catch ( error : unknown ) {
220233 console . error ( error ) ;
221234 } finally {
@@ -249,17 +262,23 @@ function App() {
249262
250263 await coreKitInstance . loginWithOAuth ( verifierConfig ) ;
251264 // IMP END - Login
252- setCoreKitStatus ( coreKitInstance . status ) ;
253265 if ( coreKitInstance . status === COREKIT_STATUS . LOGGED_IN ) {
254266 await coreKitInstance . commitChanges ( ) ; // Needed for new accounts
255267 }
268+ setCoreKitStatus ( coreKitInstance . status ) ;
269+ setUserInformation ( ) ;
256270 } catch ( error : unknown ) {
257271 uiConsole ( error ) ;
258272 } finally {
259273 setIsLoading ( false ) ;
260274 }
261275 } ;
262276
277+ const setUserInformation = ( ) => {
278+ const userInfo = coreKitInstance . getUserInfo ( ) ;
279+ setUserInfo ( userInfo ) ;
280+ getShareDescriptions ( ) ;
281+ }
263282 return (
264283 < div className = "container bg-app-gray-100 dark:bg-app-gray-900" >
265284 { isLoading ? (
@@ -274,7 +293,9 @@ function App() {
274293 coreKitStatus === COREKIT_STATUS . LOGGED_IN ? (
275294 < HomePage />
276295 ) : (
277- < LoginCard handleEmailPasswordLess = { loginWithAuth0EmailPasswordless } handleSocialLogin = { login } />
296+ < >
297+ < LoginCard handleEmailPasswordLess = { loginWithAuth0EmailPasswordless } handleSocialLogin = { login } />
298+ </ >
278299 )
279300 }
280301 </ >
0 commit comments