Fix passphrase scanner (#2292)

* Fix passphrase scanner

* Fix scanner trying to play sound on scan
This commit is contained in:
ekzyis 2025-07-18 00:06:58 +02:00 committed by GitHub
parent d5c9ffbddf
commit 56a185d477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 28 deletions

View File

@ -1350,8 +1350,10 @@ function PasswordScanner ({ onScan, text }) {
<Scanner <Scanner
formats={['qr_code']} formats={['qr_code']}
onScan={([{ rawValue: result }]) => { onScan={([{ rawValue: result }]) => {
onScan(result) if (result) {
onClose() onScan(result)
onClose()
}
}} }}
styles={{ styles={{
video: { video: {
@ -1366,6 +1368,7 @@ function PasswordScanner ({ onScan, text }) {
} }
onClose() onClose()
}} }}
components={{ audio: false }}
/> />
)} )}
</div> </div>

View File

@ -19,7 +19,7 @@ export default function Wallet () {
const [showWallets, setShowWallets] = useState(false) const [showWallets, setShowWallets] = useState(false)
const templates = useTemplates() const templates = useTemplates()
const showPassphrase = useShowPassphrase() const showPassphrase = useShowPassphrase()
const passphrasePrompt = usePassphrasePrompt() const [showPassphrasePrompt, togglePassphrasePrompt, PassphrasePrompt] = usePassphrasePrompt()
const setWalletPriorities = useSetWalletPriorities() const setWalletPriorities = useSetWalletPriorities()
const [searchFilter, setSearchFilter] = useState(() => (text) => true) const [searchFilter, setSearchFilter] = useState(() => (text) => true)
@ -45,18 +45,26 @@ export default function Wallet () {
} }
if (keyError === KeyStatus.WRONG_KEY) { if (keyError === KeyStatus.WRONG_KEY) {
return ( return showPassphrasePrompt
<WalletLayout> ? (
<div className='py-5 text-center d-flex flex-column align-items-center justify-content-center flex-grow-1'> <WalletLayout>
<Button <div className='py-5 d-flex flex-column align-items-center justify-content-center flex-grow-1 mx-auto' style={{ maxWidth: '500px' }}>
onClick={passphrasePrompt} <PassphrasePrompt />
size='md' variant='secondary' </div>
>unlock wallets </WalletLayout>
</Button> )
<small className='d-block mt-3 text-muted'>your passphrase is required</small> : (
</div> <WalletLayout>
</WalletLayout> <div className='py-5 text-center d-flex flex-column align-items-center justify-content-center flex-grow-1'>
) <Button
onClick={togglePassphrasePrompt}
size='md' variant='secondary'
>unlock wallets
</Button>
<small className='d-block mt-3 text-muted'>your passphrase is required</small>
</div>
</WalletLayout>
)
} }
if (walletsError) { if (walletsError) {

View File

@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react' import { useCallback, useMemo, useState } from 'react'
import { fromHex, toHex } from '@/lib/hex' import { fromHex, toHex } from '@/lib/hex'
import { useMe } from '@/components/me' import { useMe } from '@/components/me'
import { useIndexedDB } from '@/components/use-indexeddb' import { useIndexedDB } from '@/components/use-indexeddb'
@ -210,21 +210,21 @@ const passphraseSchema = ({ hash, salt }) => object().shape({
}) })
export function usePassphrasePrompt () { export function usePassphrasePrompt () {
const showModal = useShowModal()
const savePassphrase = useSavePassphrase() const savePassphrase = useSavePassphrase()
const hash = useRemoteKeyHash() const hash = useRemoteKeyHash()
const salt = useKeySalt() const salt = useKeySalt()
const showPassphrase = useShowPassphrase() const showPassphrase = useShowPassphrase()
const resetPassphrase = useResetPassphrase() const resetPassphrase = useResetPassphrase()
const onSubmit = useCallback((close) => const onSubmit = useCallback(async ({ passphrase }) => {
async ({ passphrase }) => { await savePassphrase({ passphrase })
await savePassphrase({ passphrase }) }, [savePassphrase])
close()
}, [savePassphrase])
return useCallback(() => { const [showPassphrasePrompt, setShowPassphrasePrompt] = useState(false)
showModal(close => ( const togglePassphrasePrompt = useCallback(() => setShowPassphrasePrompt(v => !v), [])
const Prompt = useMemo(() =>
() => (
<div> <div>
<h4>Wallet decryption</h4> <h4>Wallet decryption</h4>
<p className='line-height-md mt-3'> <p className='line-height-md mt-3'>
@ -239,7 +239,7 @@ export function usePassphrasePrompt () {
<Form <Form
schema={passphraseSchema({ hash, salt })} schema={passphraseSchema({ hash, salt })}
initial={{ passphrase: '' }} initial={{ passphrase: '' }}
onSubmit={onSubmit(close)} onSubmit={onSubmit}
> >
<PasswordInput <PasswordInput
label='passphrase' label='passphrase'
@ -252,14 +252,18 @@ export function usePassphrasePrompt () {
<div className='mt-3'> <div className='mt-3'>
<div className='d-flex justify-content-between align-items-center'> <div className='d-flex justify-content-between align-items-center'>
<Button className='me-auto' variant='danger' onClick={resetPassphrase}>reset</Button> <Button className='me-auto' variant='danger' onClick={resetPassphrase}>reset</Button>
<Button className='me-3 text-muted nav-link fw-bold' variant='link' onClick={close}>cancel</Button> <Button className='me-3 text-muted nav-link fw-bold' variant='link' onClick={togglePassphrasePrompt}>cancel</Button>
<SubmitButton variant='primary'>save</SubmitButton> <SubmitButton variant='primary'>save</SubmitButton>
</div> </div>
</div> </div>
</Form> </Form>
</div> </div>
)) ), [showPassphrase, resetPassphrase, togglePassphrasePrompt, onSubmit, hash, salt])
}, [showModal, savePassphrase, hash, salt])
return useMemo(
() => [showPassphrasePrompt, togglePassphrasePrompt, Prompt],
[showPassphrasePrompt, togglePassphrasePrompt, Prompt]
)
} }
export async function deriveKey (passphrase, salt) { export async function deriveKey (passphrase, salt) {