@@ -24,7 +24,7 @@ import { GetCredentialDefinitionRequest, GetSchemaRequest } from '@hyperledger/i
24
24
import AsyncStorage from '@react-native-async-storage/async-storage'
25
25
import { CommonActions , useNavigation } from '@react-navigation/native'
26
26
import moment from 'moment'
27
- import React , { useEffect , useState } from 'react'
27
+ import React , { useEffect , useState , useRef } from 'react'
28
28
import { useTranslation } from 'react-i18next'
29
29
import { StyleSheet , View , Text , Image , useWindowDimensions , ScrollView } from 'react-native'
30
30
import { Config } from 'react-native-config'
@@ -62,6 +62,7 @@ const resumeOnboardingAt = (
62
62
showPreface ?: boolean
63
63
}
64
64
) : Screens => {
65
+ console . log ( '********** resumeOnboardingAt' , state , params )
65
66
const termsVer = params . termsVersion ?? true
66
67
if (
67
68
( state . didSeePreface || ! params . showPreface ) &&
@@ -114,13 +115,14 @@ const resumeOnboardingAt = (
114
115
*/
115
116
const Splash = ( ) => {
116
117
const { width } = useWindowDimensions ( )
117
- const { setAgent } = useAgent ( )
118
+ const { agent , setAgent } = useAgent ( )
118
119
const { t } = useTranslation ( )
119
120
const [ store , dispatch ] = useStore < BCState > ( )
120
121
const navigation = useNavigation ( )
121
122
const { walletSecret } = useAuth ( )
122
123
const { ColorPallet, Assets } = useTheme ( )
123
124
const [ mounted , setMounted ] = useState ( false )
125
+ const hasMounted = useRef ( false )
124
126
const [ stepText , setStepText ] = useState < string > ( t ( 'Init.Starting' ) )
125
127
const [ progressPercent , setProgressPercent ] = useState ( 0 )
126
128
const [ initOnboardingCount , setInitOnboardingCount ] = useState ( 0 )
@@ -145,6 +147,10 @@ const Splash = () => {
145
147
TOKENS . CACHE_SCHEMAS ,
146
148
] )
147
149
150
+ useEffect ( ( ) => {
151
+ console . log ( `************* Splash screen mounted, ${ mounted } , ${ Math . floor ( Math . random ( ) * 10 ) + 1 } ` )
152
+ } , [ mounted ] )
153
+
148
154
const steps : string [ ] = [
149
155
t ( 'Init.Starting' ) ,
150
156
t ( 'Init.FetchingPreferences' ) ,
@@ -201,7 +207,10 @@ const Splash = () => {
201
207
202
208
// navigation calls that occur before the screen is fully mounted will fail
203
209
useEffect ( ( ) => {
204
- setMounted ( true )
210
+ if ( ! hasMounted . current ) {
211
+ setMounted ( true )
212
+ hasMounted . current = true
213
+ }
205
214
} , [ ] )
206
215
207
216
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -321,14 +330,40 @@ const Splash = () => {
321
330
return
322
331
}
323
332
333
+ if ( agent ) {
334
+ logger . info ( 'Agent already initialized, restarting...' )
335
+
336
+ try {
337
+ await agent . wallet . open ( {
338
+ id : walletSecret . id ,
339
+ key : walletSecret . key ,
340
+ } )
341
+ } catch ( error ) {
342
+ logger . error ( 'Error opening existing wallet' , error )
343
+ }
344
+
345
+ await agent . mediationRecipient . initiateMessagePickup ( )
346
+
347
+ setStep ( 9 )
348
+ navigation . dispatch (
349
+ CommonActions . reset ( {
350
+ index : 0 ,
351
+ routes : [ { name : Stacks . TabStack } ] ,
352
+ } )
353
+ )
354
+
355
+ return
356
+ }
357
+
358
+ logger . info ( 'No agent initialized, creating a new one' )
359
+
324
360
setStep ( 3 )
325
361
326
362
await ( ocaBundleResolver as RemoteOCABundleResolver ) . checkForUpdates ?.( )
327
363
328
364
setStep ( 4 )
329
365
const cachedLedgers = await loadCachedLedgers ( )
330
366
const ledgers = cachedLedgers ?? indyLedgers
331
-
332
367
const options = {
333
368
config : {
334
369
label : store . preferences . walletName || 'BC Wallet' ,
0 commit comments