diff --git a/src/context/WalletProvider/KeepKey/components/Connect.tsx b/src/context/WalletProvider/KeepKey/components/Connect.tsx index ecbf9452fba..ea9130b95b1 100644 --- a/src/context/WalletProvider/KeepKey/components/Connect.tsx +++ b/src/context/WalletProvider/KeepKey/components/Connect.tsx @@ -6,6 +6,7 @@ import { ModalBody, ModalHeader, } from '@chakra-ui/react' +import type { KkRestAdapter } from '@keepkey/hdwallet-keepkey-rest' import type { Event } from '@shapeshiftoss/hdwallet-core' import { useCallback, useState } from 'react' import { CircularProgress } from 'components/CircularProgress/CircularProgress' @@ -52,9 +53,7 @@ export const KeepKeyConnect = () => { setError(null) setLoading(true) - const keepKeyAdapters = await getAdapter(KeyManager.KeepKey) - if (!keepKeyAdapters) return - const { rest: firstAdapter, usb: secondAdapter } = keepKeyAdapters + const firstAdapter = (await getAdapter(KeyManager.KeepKey)) as KkRestAdapter | null if (firstAdapter) { const wallet = await (async () => { try { @@ -67,7 +66,7 @@ export const KeepKeyConnect = () => { } return wallet } catch (e) { - // const secondAdapter = await getAdapter(KeyManager.KeepKey, 1) + const secondAdapter = await getAdapter(KeyManager.KeepKey, 1) // @ts-ignore TODO(gomes): FIXME, most likely borked because of WebUSBKeepKeyAdapter const wallet = await secondAdapter.pairDevice().catch(err => { if (err.name === 'ConflictingApp') { diff --git a/src/context/WalletProvider/WalletProvider.tsx b/src/context/WalletProvider/WalletProvider.tsx index 6c2a25503a9..900660e91e9 100644 --- a/src/context/WalletProvider/WalletProvider.tsx +++ b/src/context/WalletProvider/WalletProvider.tsx @@ -354,7 +354,7 @@ export const WalletProvider = ({ children }: { children: React.ReactNode }): JSX const [walletType, setWalletType] = useState(null) const getAdapter: GetAdapter = useCallback( - async (keyManager, index) => { + async (keyManager, index = 0) => { let currentStateAdapters = state.adapters // ?? ({} as AdaptersByKeyManager) // Check if adapter is already in the state @@ -381,6 +381,8 @@ export const WalletProvider = ({ children }: { children: React.ReactNode }): JSX } } + if (!adapterInstance) return null + return adapterInstance }, [isDarkMode, state.adapters, state.keyring], diff --git a/src/context/WalletProvider/types.ts b/src/context/WalletProvider/types.ts index d3354076be7..efcfe2d02ff 100644 --- a/src/context/WalletProvider/types.ts +++ b/src/context/WalletProvider/types.ts @@ -25,5 +25,5 @@ export type AdaptersByKeyManager = { export type GetAdapter = ( keyManager: K, - index: K extends KeyManager.KeepKey ? 0 | 1 : 0, // only used for keepkey + index?: K extends KeyManager.KeepKey ? 0 | 1 : 0, // only used for keepkey ) => Promise