From 6a1edf01129d9bb751056444684acb2f6ffb9ce4 Mon Sep 17 00:00:00 2001 From: schmanu Date: Wed, 4 Oct 2023 09:43:22 +0200 Subject: [PATCH] fix: test, refactor, remove console.logs --- .../settings/SignerAccountMFA/index.tsx | 18 +++++++++--------- .../wallets/mpc/__tests__/useMPCWallet.test.ts | 2 +- src/hooks/wallets/mpc/useMPCWallet.ts | 3 --- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/components/settings/SignerAccountMFA/index.tsx b/src/components/settings/SignerAccountMFA/index.tsx index 6518cccdc5..fae01a8191 100644 --- a/src/components/settings/SignerAccountMFA/index.tsx +++ b/src/components/settings/SignerAccountMFA/index.tsx @@ -64,15 +64,15 @@ const SignerAccountMFA = () => { } const hasDeviceShare = await deviceShareModule.isEnabled() - if (hasDeviceShare !== storeDeviceShare) { - if (storeDeviceShare) { - await deviceShareModule.createAndStoreDeviceFactor() - } else { - // Switch to password recovery factor such that we can delete the device factor - await mpcCoreKit.inputFactorKey(new BN(securityQuestionFactor, 'hex')) - - await deviceShareModule.removeDeviceFactor() - } + + if (!hasDeviceShare && storeDeviceShare) { + await deviceShareModule.createAndStoreDeviceFactor() + } + + if (hasDeviceShare && !storeDeviceShare) { + // Switch to password recovery factor such that we can delete the device factor + await mpcCoreKit.inputFactorKey(new BN(securityQuestionFactor, 'hex')) + await deviceShareModule.removeDeviceFactor() } } catch (error) { console.error(error) diff --git a/src/hooks/wallets/mpc/__tests__/useMPCWallet.test.ts b/src/hooks/wallets/mpc/__tests__/useMPCWallet.test.ts index ebb0e7fc7a..0efea9dec0 100644 --- a/src/hooks/wallets/mpc/__tests__/useMPCWallet.test.ts +++ b/src/hooks/wallets/mpc/__tests__/useMPCWallet.test.ts @@ -156,7 +156,7 @@ describe('useMPCWallet', () => { it('should throw if mpcCoreKit is not initialized', () => { const { result } = renderHook(() => useMPCWallet()) expect(result.current.resetAccount()).rejects.toEqual( - new Error('MPC Core Kit is not initialized or the user is not logged in'), + new Error('MPC Core Kit is not initialized or the user is not logged in'), ) }) it('should reset an account by overwriting the metadata', async () => { diff --git a/src/hooks/wallets/mpc/useMPCWallet.ts b/src/hooks/wallets/mpc/useMPCWallet.ts index d2d0a1e5fd..e4fb5ee68c 100644 --- a/src/hooks/wallets/mpc/useMPCWallet.ts +++ b/src/hooks/wallets/mpc/useMPCWallet.ts @@ -77,16 +77,13 @@ export const useMPCWallet = (): MPCWalletHook => { }) if (mpcCoreKit.status === COREKIT_STATUS.REQUIRED_SHARE) { - console.log('Share required') // Check if we have a device share stored const deviceFactor = await getWebBrowserFactor(mpcCoreKit) if (deviceFactor) { - console.log('Using device factor') // Recover from device factor const deviceFactorKey = new BN(deviceFactor, 'hex') await mpcCoreKit.inputFactorKey(deviceFactorKey) } else { - console.log('using password') // Check password recovery if (securityQuestions.isEnabled()) { setWalletState(MPCWalletState.MANUAL_RECOVERY)