From a7ea8e310fb9657a6402d4505aad2f52c2fd8c96 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:50:33 +1100 Subject: [PATCH] chore: cleanup --- .../ManageAccountsDrawer/components/ImportAccounts.tsx | 5 +++++ src/components/MultiHopTrade/hooks/useReceiveAddress.tsx | 2 +- .../WalletProvider/KeepKey/components/Passphrase.tsx | 2 +- src/context/WalletProvider/KeepKey/components/Pin.tsx | 6 +++--- src/context/WalletProvider/Ledger/components/Chains.tsx | 9 +++++---- .../NativeWallet/components/EnterPassword.tsx | 4 +--- .../NativeWallet/hooks/useNativeEventHandler.ts | 5 ----- .../WalletConnectV2/useWalletConnectV2EventHandler.ts | 3 +-- src/context/WalletProvider/WalletProvider.tsx | 5 ----- src/context/WalletProvider/WalletViewsSwitch.tsx | 5 ----- src/pages/Accounts/AddAccountModal.tsx | 1 + 11 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/components/ManageAccountsDrawer/components/ImportAccounts.tsx b/src/components/ManageAccountsDrawer/components/ImportAccounts.tsx index c2d1d342cb3..a48015e1a32 100644 --- a/src/components/ManageAccountsDrawer/components/ImportAccounts.tsx +++ b/src/components/ManageAccountsDrawer/components/ImportAccounts.tsx @@ -317,6 +317,11 @@ export const ImportAccounts = ({ chainId, onClose }: ImportAccountsProps) => { return } + if (!walletDeviceId) { + console.error('Missing walletDeviceId') + return + } + setIsSubmitting(true) // For every new account that is active, fetch the account and upsert it into the redux state diff --git a/src/components/MultiHopTrade/hooks/useReceiveAddress.tsx b/src/components/MultiHopTrade/hooks/useReceiveAddress.tsx index f8825d8d403..b530157cd25 100644 --- a/src/components/MultiHopTrade/hooks/useReceiveAddress.tsx +++ b/src/components/MultiHopTrade/hooks/useReceiveAddress.tsx @@ -66,7 +66,7 @@ export const useReceiveAddress = ({ ? skipToken : async () => { // Already partially covered in isInitializing, but TypeScript lyfe mang. - if (!buyAsset || !wallet || !buyAccountId || !buyAccountMetadata) { + if (!buyAsset || !wallet || !buyAccountId || !buyAccountMetadata || !deviceId) { return undefined } diff --git a/src/context/WalletProvider/KeepKey/components/Passphrase.tsx b/src/context/WalletProvider/KeepKey/components/Passphrase.tsx index 76559c9d7f6..67b77ed3b6f 100644 --- a/src/context/WalletProvider/KeepKey/components/Passphrase.tsx +++ b/src/context/WalletProvider/KeepKey/components/Passphrase.tsx @@ -22,7 +22,7 @@ export const KeepKeyPassphrase = () => { state: { deviceId, keyring }, dispatch, } = useWallet() - const wallet = keyring.get(deviceId) + const wallet = keyring.get(deviceId ?? '') const walletId = useAppSelector(selectWalletId) const appDispatch = useAppDispatch() diff --git a/src/context/WalletProvider/KeepKey/components/Pin.tsx b/src/context/WalletProvider/KeepKey/components/Pin.tsx index f599ba70e7c..7e66c002bc1 100644 --- a/src/context/WalletProvider/KeepKey/components/Pin.tsx +++ b/src/context/WalletProvider/KeepKey/components/Pin.tsx @@ -38,7 +38,7 @@ export const KeepKeyPin = ({ }, dispatch, } = useWallet() - const wallet = keyring.get(deviceId) + const wallet = keyring.get(deviceId ?? '') const pinFieldRef = useRef(null) @@ -138,10 +138,10 @@ export const KeepKeyPin = ({ } } - keyring.on(['KeepKey', deviceId, String(MessageType.FAILURE)], handleError) + keyring.on(['KeepKey', deviceId ?? '', String(MessageType.FAILURE)], handleError) return () => { - keyring.off(['KeepKey', deviceId, String(MessageType.FAILURE)], handleError) + keyring.off(['KeepKey', deviceId ?? '', String(MessageType.FAILURE)], handleError) } }, [deviceId, keyring]) diff --git a/src/context/WalletProvider/Ledger/components/Chains.tsx b/src/context/WalletProvider/Ledger/components/Chains.tsx index fb4d50c6d85..5ba95951e08 100644 --- a/src/context/WalletProvider/Ledger/components/Chains.tsx +++ b/src/context/WalletProvider/Ledger/components/Chains.tsx @@ -52,7 +52,8 @@ export const LedgerChains = () => { const handleConnectClick = useCallback( async (chainId: ChainId) => { - if (!walletState?.wallet) { + const { wallet, deviceId } = walletState ?? {} + if (!wallet || !deviceId) { console.error('No wallet found') return } @@ -67,7 +68,7 @@ export const LedgerChains = () => { ]({ accountNumber: 0, chainIds, - wallet: walletState.wallet, + wallet, isSnapInstalled: false, }) @@ -102,7 +103,7 @@ export const LedgerChains = () => { const accountMetadata = accountMetadataByAccountId[accountId] const payload = { accountMetadataByAccountId: { [accountId]: accountMetadata }, - walletId: walletState.deviceId, + walletId: deviceId, } dispatch(portfolio.actions.upsertAccountMetadata(payload)) @@ -120,7 +121,7 @@ export const LedgerChains = () => { setLoadingChains(prevLoading => ({ ...prevLoading, [chainId]: false })) } }, - [dispatch, walletState.deviceId, walletState.wallet], + [dispatch, walletState], ) const chainsRows = useMemo( diff --git a/src/context/WalletProvider/NativeWallet/components/EnterPassword.tsx b/src/context/WalletProvider/NativeWallet/components/EnterPassword.tsx index 3e0073ea51f..5bd48c4c05d 100644 --- a/src/context/WalletProvider/NativeWallet/components/EnterPassword.tsx +++ b/src/context/WalletProvider/NativeWallet/components/EnterPassword.tsx @@ -47,9 +47,6 @@ export const EnterPassword = () => { const [showPw, setShowPw] = useState(false) - // TODO: this is always null - console.log('EnterPassword', deviceId) - const { setError, handleSubmit, @@ -61,6 +58,7 @@ export const EnterPassword = () => { const onSubmit = useCallback( async (values: FieldValues) => { try { + if (!deviceId) return const wallet = keyring.get(deviceId) const Vault = await import('@shapeshiftoss/hdwallet-native-vault').then(m => m.Vault) const vault = await Vault.open(deviceId, values.password) diff --git a/src/context/WalletProvider/NativeWallet/hooks/useNativeEventHandler.ts b/src/context/WalletProvider/NativeWallet/hooks/useNativeEventHandler.ts index 81d8272a5cc..70b1f3c2fb7 100644 --- a/src/context/WalletProvider/NativeWallet/hooks/useNativeEventHandler.ts +++ b/src/context/WalletProvider/NativeWallet/hooks/useNativeEventHandler.ts @@ -24,11 +24,6 @@ export const useNativeEventHandler = (state: InitialState, dispatch: Dispatch { // This effect should never run for wallets other than WalletConnectV2 since we explicitly tap into @walletconnect/ethereum-provider provider diff --git a/src/context/WalletProvider/WalletProvider.tsx b/src/context/WalletProvider/WalletProvider.tsx index bc84abd16fe..c80e0b4a0e7 100644 --- a/src/context/WalletProvider/WalletProvider.tsx +++ b/src/context/WalletProvider/WalletProvider.tsx @@ -145,7 +145,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => { store.dispatch(portfolioSlice.actions.setWalletMeta(undefined)) } const { deviceId, name, wallet, icon, meta, isDemoWallet, connectedType } = action.payload - console.log('SET_WALLET', deviceId) // set wallet metadata in redux store const walletMeta = { walletId: deviceId, @@ -220,7 +219,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => { } return newState case WalletActions.NATIVE_PASSWORD_OPEN: - console.log('NATIVE_PASSWORD_OPEN', action.payload) return { ...state, modal: action.payload.modal, @@ -328,8 +326,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => { initialRoute: KeepKeyRoutes.Disconnect, } case WalletActions.SET_NATIVE_PENDING_DEVICE_ID: - console.log('SET_NATIVE_PENDING_DEVICE_ID') - store.dispatch(localWalletSlice.actions.clearLocalWallet()) store.dispatch(portfolioSlice.actions.setWalletMeta(undefined)) return { @@ -340,7 +336,6 @@ const reducer = (state: InitialState, action: ActionTypes): InitialState => { nativeWalletPendingDeviceId: action.payload, } case WalletActions.RESET_NATIVE_PENDING_DEVICE_ID: - console.log('RESET_NATIVE_PENDING_DEVICE_ID') return { ...state, nativeWalletPendingDeviceId: null, diff --git a/src/context/WalletProvider/WalletViewsSwitch.tsx b/src/context/WalletProvider/WalletViewsSwitch.tsx index b500dac2fd0..65a2566231a 100644 --- a/src/context/WalletProvider/WalletViewsSwitch.tsx +++ b/src/context/WalletProvider/WalletViewsSwitch.tsx @@ -15,8 +15,6 @@ import { Route, Switch, useHistory, useLocation, useRouteMatch } from 'react-rou import { SlideTransition } from 'components/SlideTransition' import { WalletActions } from 'context/WalletProvider/actions' import { useWallet } from 'hooks/useWallet/useWallet' -import { localWalletSlice } from 'state/slices/localWalletSlice/localWalletSlice' -import { store } from 'state/store' import { SUPPORTED_WALLETS } from './config' import { KeyManager } from './KeyManager' @@ -63,14 +61,11 @@ export const WalletViewsSwitch = () => { if (disposition === 'initializing' || disposition === 'recovering') { await wallet?.cancel() disconnect() - store.dispatch(localWalletSlice.actions.clearLocalWallet()) dispatch({ type: WalletActions.OPEN_KEEPKEY_DISCONNECT }) } else { history.replace(INITIAL_WALLET_MODAL_ROUTE) if (disconnectOnCloseModal) { disconnect() - dispatch({ type: WalletActions.RESET_STATE }) - store.dispatch(localWalletSlice.actions.clearLocalWallet()) } else { dispatch({ type: WalletActions.SET_WALLET_MODAL, payload: false }) } diff --git a/src/pages/Accounts/AddAccountModal.tsx b/src/pages/Accounts/AddAccountModal.tsx index 3b00b600744..5bcc970067d 100644 --- a/src/pages/Accounts/AddAccountModal.tsx +++ b/src/pages/Accounts/AddAccountModal.tsx @@ -98,6 +98,7 @@ export const AddAccountModal = () => { if (!wallet) return if (!selectedChainId) return if (!nextAccountNumber) return + if (!walletDeviceId) return ;(async () => { const accountNumber = nextAccountNumber const chainIds = [selectedChainId]