Skip to content

Commit

Permalink
fix: better handle open wallet (#2194)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason C. Leach <[email protected]>
  • Loading branch information
jleach authored Oct 3, 2024
1 parent 520660f commit 3532dee
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions app/src/screens/Splash.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Agent, HttpOutboundTransport, MediatorPickupStrategy, WsOutboundTransport } from '@credo-ts/core'
import { Agent, HttpOutboundTransport, MediatorPickupStrategy, WsOutboundTransport, WalletError } from '@credo-ts/core'
import { IndyVdrPoolConfig, IndyVdrPoolService } from '@credo-ts/indy-vdr/build/pool'
import { useAgent } from '@credo-ts/react-hooks'
import { agentDependencies } from '@credo-ts/react-native'
Expand Down Expand Up @@ -154,24 +154,30 @@ const Splash = () => {
TOKENS.CACHE_SCHEMAS,
])

const steps: string[] = useMemo(() => [
t('Init.Starting'),
t('Init.FetchingPreferences'),
t('Init.VerifyingOnboarding'),
t('Init.GettingCredentials'),
t('Init.RegisteringTransports'),
t('Init.InitializingAgent'),
t('Init.CacheWarmup'),
t('Init.ConnectingLedgers'),
t('Init.SettingAgent'),
t('Init.Finishing'),
], [t])

const setStep = useCallback((stepIdx: number) => {
setStepText(steps[stepIdx])
const percent = Math.floor(((stepIdx + 1) / steps.length) * 100)
setProgressPercent(percent)
}, [steps])
const steps: string[] = useMemo(
() => [
t('Init.Starting'),
t('Init.FetchingPreferences'),
t('Init.VerifyingOnboarding'),
t('Init.GettingCredentials'),
t('Init.RegisteringTransports'),
t('Init.InitializingAgent'),
t('Init.CacheWarmup'),
t('Init.ConnectingLedgers'),
t('Init.SettingAgent'),
t('Init.Finishing'),
],
[t]
)

const setStep = useCallback(
(stepIdx: number) => {
setStepText(steps[stepIdx])
const percent = Math.floor(((stepIdx + 1) / steps.length) * 100)
setProgressPercent(percent)
},
[steps]
)

const styles = StyleSheet.create({
screenContainer: {
Expand Down Expand Up @@ -362,14 +368,22 @@ const Splash = () => {
key: walletSecret.key,
})
} catch (error) {
logger.error('Error opening existing wallet', error as Error)

throw new BifoldError(
'Wallet Service',
'There was a problem unlocking the wallet.',
(error as Error).message,
1047
)
// Credo does not use error codes but this will be in the
// the error message if the wallet is already open
const catchPhrase = 'instance already opened'

if (error instanceof WalletError && error.message.includes(catchPhrase)) {
logger.warn('Wallet already open, nothing to do')
} else {
logger.error('Error opening existing wallet:', error as Error)

throw new BifoldError(
'Wallet Service',
'There was a problem unlocking the wallet.',
(error as Error).message,
1047
)
}
}

await agent.mediationRecipient.initiateMessagePickup()
Expand Down

0 comments on commit 3532dee

Please sign in to comment.