Skip to content

Commit

Permalink
feat: gm, she compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Oct 17, 2023
1 parent e57f316 commit 764ea6b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/context/WalletProvider/KeepKey/components/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand All @@ -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') {
Expand Down
4 changes: 3 additions & 1 deletion src/context/WalletProvider/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const WalletProvider = ({ children }: { children: React.ReactNode }): JSX
const [walletType, setWalletType] = useState<KeyManagerWithProvider | null>(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
Expand All @@ -381,6 +381,8 @@ export const WalletProvider = ({ children }: { children: React.ReactNode }): JSX
}
}

if (!adapterInstance) return null

return adapterInstance
},
[isDarkMode, state.adapters, state.keyring],
Expand Down
2 changes: 1 addition & 1 deletion src/context/WalletProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export type AdaptersByKeyManager = {

export type GetAdapter = <K extends keyof AdaptersByKeyManager>(
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<AdaptersByKeyManager[K] | null>

0 comments on commit 764ea6b

Please sign in to comment.