mirror of
https://github.com/joinmarket-webui/jam.git
synced 2026-08-17 13:07:34 +02:00
fix(settings): render-phase state update in AccountXpubsDialog (#1223)
fix(settings): cleanup render state updates, stabilize seedQueryOptions, and related fixes
This commit is contained in:
parent
37b2c438ab
commit
998bdf7812
1 changed files with 23 additions and 11 deletions
|
|
@ -191,12 +191,8 @@ export const AccountXpubsDialog = ({
|
|||
const { t } = useTranslation()
|
||||
|
||||
const [passwordVerifiedAt, setPasswordVerifiedAt] = useState<number>()
|
||||
const isPasswordVerified = useMemo(() => passwordVerifiedAt !== undefined, [passwordVerifiedAt])
|
||||
const [timeLeft, setTimeLeft] = useState(autoCloseTimeout)
|
||||
|
||||
if (timeLeft <= 0 && passwordVerifiedAt !== undefined) {
|
||||
setPasswordVerifiedAt(undefined)
|
||||
}
|
||||
const isPasswordVerified = passwordVerifiedAt !== undefined && timeLeft > 0
|
||||
|
||||
const secondsLeft = Math.max(0, Math.round(timeLeft / 1_000))
|
||||
|
||||
|
|
@ -206,10 +202,14 @@ export const AccountXpubsDialog = ({
|
|||
const queryClient = useQueryClient()
|
||||
const { jars } = useJars()
|
||||
|
||||
const seedQueryOptions = getseedOptions({
|
||||
client,
|
||||
path: { walletname: walletFileName },
|
||||
})
|
||||
const seedQueryOptions = useMemo(
|
||||
() =>
|
||||
getseedOptions({
|
||||
client,
|
||||
path: { walletname: walletFileName },
|
||||
}),
|
||||
[client, walletFileName],
|
||||
)
|
||||
|
||||
const {
|
||||
data: seedQueryData,
|
||||
|
|
@ -225,7 +225,7 @@ export const AccountXpubsDialog = ({
|
|||
select: (data) => data.seedphrase.split(/\s+/) as MnemonicPhrase,
|
||||
})
|
||||
|
||||
const accountXpubsQueryKey = [walletFileName, 'xpubs']
|
||||
const accountXpubsQueryKey = useMemo(() => [walletFileName, 'xpubs'], [walletFileName])
|
||||
|
||||
const accountXpubs = useQuery({
|
||||
queryKey: accountXpubsQueryKey,
|
||||
|
|
@ -256,7 +256,12 @@ export const AccountXpubsDialog = ({
|
|||
|
||||
const xpubsDisplayedAt = Math.max(accountXpubs.dataUpdatedAt, passwordVerifiedAt)
|
||||
const interval = setInterval(() => {
|
||||
setTimeLeft(Math.max(0, xpubsDisplayedAt + autoCloseTimeout - Date.now()))
|
||||
const nextTimeLeft = Math.max(0, xpubsDisplayedAt + autoCloseTimeout - Date.now())
|
||||
setTimeLeft(nextTimeLeft)
|
||||
if (nextTimeLeft <= 0) {
|
||||
clearInterval(interval)
|
||||
setPasswordVerifiedAt(undefined)
|
||||
}
|
||||
}, 333)
|
||||
|
||||
return () => {
|
||||
|
|
@ -264,6 +269,13 @@ export const AccountXpubsDialog = ({
|
|||
}
|
||||
}, [accountXpubs.dataUpdatedAt, passwordVerifiedAt, autoCloseTimeout])
|
||||
|
||||
useEffect(() => {
|
||||
if (timeLeft > 0) return
|
||||
|
||||
queryClient.removeQueries({ queryKey: seedQueryOptions.queryKey })
|
||||
queryClient.removeQueries({ queryKey: accountXpubsQueryKey })
|
||||
}, [queryClient, seedQueryOptions.queryKey, accountXpubsQueryKey, timeLeft])
|
||||
|
||||
const handleClose = () => {
|
||||
onOpenChange(false)
|
||||
setPasswordVerifiedAt(undefined)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue