-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable submit button for masp tx when using disconnected ledge…
…r device (#1572) * feat: disable submit button for masp tx using disconnected ledger * fix: do not check for conencted ledger while tx is submitting
- Loading branch information
1 parent
e8c86ce
commit a7567d8
Showing
10 changed files
with
145 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ledgerUSBList } from "@namada/sdk/web"; | ||
import { LedgerError } from "@zondax/ledger-namada"; | ||
import { isLedgerAccountAtom } from "atoms/accounts"; | ||
import { atom } from "jotai"; | ||
|
||
import { atomWithQuery } from "jotai-tanstack-query"; | ||
import { getSdkInstance } from "utils/sdk"; | ||
|
||
export type LedgerStatus = { | ||
connected: boolean; | ||
errorMessage: string; | ||
}; | ||
|
||
const ledgerStatusStopAtom = atom(false); | ||
|
||
export const ledgerStatusAtom = atomWithQuery<LedgerStatus | undefined>(() => { | ||
return { | ||
refetchInterval: 1000, | ||
queryKey: ["ledger-status"], | ||
queryFn: async () => { | ||
const devices = await ledgerUSBList(); | ||
|
||
if (devices.length > 0) { | ||
try { | ||
// Disable console.warn to prevent the warning from showing up in the UI in the loop | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(console as any).warnOld = console.warn; | ||
console.warn = () => {}; | ||
|
||
const sdk = await getSdkInstance(); | ||
const ledger = await sdk.initLedger(); | ||
const { | ||
version: { returnCode, errorMessage }, | ||
} = await ledger.status(); | ||
|
||
const connected = returnCode === LedgerError.NoErrors; | ||
|
||
await ledger.closeTransport(); | ||
|
||
return { | ||
connected, | ||
errorMessage, | ||
}; | ||
} catch (e) { | ||
return { | ||
connected: false, | ||
errorMessage: `${e}`, | ||
}; | ||
} finally { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
console.warn = (console as any).warnOld; | ||
} | ||
} | ||
|
||
return { | ||
connected: false, | ||
errorMessage: "Ledger device not detected", | ||
}; | ||
}, | ||
}; | ||
}); | ||
|
||
export const ledgerStatusDataAtom = atom( | ||
(get) => { | ||
const isLedgerAccount = get(isLedgerAccountAtom); | ||
const ledgetStatusStop = get(ledgerStatusStopAtom); | ||
|
||
if (isLedgerAccount && !ledgetStatusStop) { | ||
return get(ledgerStatusAtom).data; | ||
} | ||
}, | ||
(_, set, stop: boolean) => { | ||
set(ledgerStatusStopAtom, stop); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./atoms"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters