Fix passphrase scanner (#2292)
* Fix passphrase scanner * Fix scanner trying to play sound on scan
This commit is contained in:
parent
d5c9ffbddf
commit
56a185d477
@ -1350,8 +1350,10 @@ function PasswordScanner ({ onScan, text }) {
|
|||||||
<Scanner
|
<Scanner
|
||||||
formats={['qr_code']}
|
formats={['qr_code']}
|
||||||
onScan={([{ rawValue: result }]) => {
|
onScan={([{ rawValue: result }]) => {
|
||||||
|
if (result) {
|
||||||
onScan(result)
|
onScan(result)
|
||||||
onClose()
|
onClose()
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
styles={{
|
styles={{
|
||||||
video: {
|
video: {
|
||||||
@ -1366,6 +1368,7 @@ function PasswordScanner ({ onScan, text }) {
|
|||||||
}
|
}
|
||||||
onClose()
|
onClose()
|
||||||
}}
|
}}
|
||||||
|
components={{ audio: false }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -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,11 +45,19 @@ export default function Wallet () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keyError === KeyStatus.WRONG_KEY) {
|
if (keyError === KeyStatus.WRONG_KEY) {
|
||||||
return (
|
return showPassphrasePrompt
|
||||||
|
? (
|
||||||
|
<WalletLayout>
|
||||||
|
<div className='py-5 d-flex flex-column align-items-center justify-content-center flex-grow-1 mx-auto' style={{ maxWidth: '500px' }}>
|
||||||
|
<PassphrasePrompt />
|
||||||
|
</div>
|
||||||
|
</WalletLayout>
|
||||||
|
)
|
||||||
|
: (
|
||||||
<WalletLayout>
|
<WalletLayout>
|
||||||
<div className='py-5 text-center d-flex flex-column align-items-center justify-content-center flex-grow-1'>
|
<div className='py-5 text-center d-flex flex-column align-items-center justify-content-center flex-grow-1'>
|
||||||
<Button
|
<Button
|
||||||
onClick={passphrasePrompt}
|
onClick={togglePassphrasePrompt}
|
||||||
size='md' variant='secondary'
|
size='md' variant='secondary'
|
||||||
>unlock wallets
|
>unlock wallets
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -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 })
|
||||||
close()
|
|
||||||
}, [savePassphrase])
|
}, [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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user