diff --git a/components/form.js b/components/form.js index 44c1c5e1..852c24f8 100644 --- a/components/form.js +++ b/components/form.js @@ -1350,8 +1350,10 @@ function PasswordScanner ({ onScan, text }) { { - onScan(result) - onClose() + if (result) { + onScan(result) + onClose() + } }} styles={{ video: { @@ -1366,6 +1368,7 @@ function PasswordScanner ({ onScan, text }) { } onClose() }} + components={{ audio: false }} /> )} diff --git a/pages/wallets/index.js b/pages/wallets/index.js index 6acfd46e..278a1fd9 100644 --- a/pages/wallets/index.js +++ b/pages/wallets/index.js @@ -19,7 +19,7 @@ export default function Wallet () { const [showWallets, setShowWallets] = useState(false) const templates = useTemplates() const showPassphrase = useShowPassphrase() - const passphrasePrompt = usePassphrasePrompt() + const [showPassphrasePrompt, togglePassphrasePrompt, PassphrasePrompt] = usePassphrasePrompt() const setWalletPriorities = useSetWalletPriorities() const [searchFilter, setSearchFilter] = useState(() => (text) => true) @@ -45,18 +45,26 @@ export default function Wallet () { } if (keyError === KeyStatus.WRONG_KEY) { - return ( - -
- - your passphrase is required -
-
- ) + return showPassphrasePrompt + ? ( + +
+ +
+
+ ) + : ( + +
+ + your passphrase is required +
+
+ ) } if (walletsError) { diff --git a/wallets/client/hooks/crypto.js b/wallets/client/hooks/crypto.js index d4016ee2..fbb2d6c1 100644 --- a/wallets/client/hooks/crypto.js +++ b/wallets/client/hooks/crypto.js @@ -1,4 +1,4 @@ -import { useCallback, useMemo } from 'react' +import { useCallback, useMemo, useState } from 'react' import { fromHex, toHex } from '@/lib/hex' import { useMe } from '@/components/me' import { useIndexedDB } from '@/components/use-indexeddb' @@ -210,21 +210,21 @@ const passphraseSchema = ({ hash, salt }) => object().shape({ }) export function usePassphrasePrompt () { - const showModal = useShowModal() const savePassphrase = useSavePassphrase() const hash = useRemoteKeyHash() const salt = useKeySalt() const showPassphrase = useShowPassphrase() const resetPassphrase = useResetPassphrase() - const onSubmit = useCallback((close) => - async ({ passphrase }) => { - await savePassphrase({ passphrase }) - close() - }, [savePassphrase]) + const onSubmit = useCallback(async ({ passphrase }) => { + await savePassphrase({ passphrase }) + }, [savePassphrase]) - return useCallback(() => { - showModal(close => ( + const [showPassphrasePrompt, setShowPassphrasePrompt] = useState(false) + const togglePassphrasePrompt = useCallback(() => setShowPassphrasePrompt(v => !v), []) + + const Prompt = useMemo(() => + () => (

Wallet decryption

@@ -239,7 +239,7 @@ export function usePassphrasePrompt () {

- + save
- )) - }, [showModal, savePassphrase, hash, salt]) + ), [showPassphrase, resetPassphrase, togglePassphrasePrompt, onSubmit, hash, salt]) + + return useMemo( + () => [showPassphrasePrompt, togglePassphrasePrompt, Prompt], + [showPassphrasePrompt, togglePassphrasePrompt, Prompt] + ) } export async function deriveKey (passphrase, salt) {