From 3532deebb9be60c7406f300abdfabdf3f0a04aa9 Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Thu, 3 Oct 2024 14:42:22 -0700 Subject: [PATCH] fix: better handle open wallet (#2194) Signed-off-by: Jason C. Leach --- app/src/screens/Splash.tsx | 68 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/app/src/screens/Splash.tsx b/app/src/screens/Splash.tsx index d5cbb39a..3243d57d 100644 --- a/app/src/screens/Splash.tsx +++ b/app/src/screens/Splash.tsx @@ -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' @@ -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: { @@ -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()