From 44820f06be979d3a30d2e66c430e212e28ca6052 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 10 Jan 2024 14:44:10 -0300 Subject: save challenge id when 2fa is required --- packages/demobank-ui/src/pages/OperationState/state.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'packages/demobank-ui/src/pages/OperationState/state.ts') diff --git a/packages/demobank-ui/src/pages/OperationState/state.ts b/packages/demobank-ui/src/pages/OperationState/state.ts index 477146d1e..b214a400d 100644 --- a/packages/demobank-ui/src/pages/OperationState/state.ts +++ b/packages/demobank-ui/src/pages/OperationState/state.ts @@ -24,9 +24,11 @@ import { useBackendState } from "../../hooks/backend.js"; import { usePreferences } from "../../hooks/preferences.js"; import { assertUnreachable } from "../WithdrawalOperationPage.js"; import { Props, State } from "./index.js"; +import { useBankState } from "../../hooks/bank-state.js"; export function useComponentState({ currency, onClose }: Props): utils.RecursiveState { - const [settings, updateSettings] = usePreferences() + const [settings] = usePreferences() + const [bankState, updateBankState] = useBankState(); const { state: credentials } = useBackendState() const creds = credentials.status !== "loggedIn" ? undefined : credentials const { api } = useBankCoreApiContext() @@ -46,11 +48,11 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive setFailure(resp) return; } - updateSettings("currentWithdrawalOperationId", resp.body.withdrawal_id) + updateBankState("currentWithdrawalOperationId", resp.body.withdrawal_id) } - const withdrawalOperationId = settings.currentWithdrawalOperationId + const withdrawalOperationId = bankState.currentWithdrawalOperationId useEffect(() => { if (withdrawalOperationId === undefined) { doSilentStart() @@ -77,7 +79,7 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive if (!creds) return; const resp = await api.abortWithdrawalById(creds, wid); if (resp.type === "ok") { - updateSettings("currentWithdrawalOperationId", undefined) + updateBankState("currentWithdrawalOperationId", undefined) onClose(); } else { return resp; @@ -140,7 +142,7 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive status: "aborted", error: undefined, onClose: async () => { - updateSettings("currentWithdrawalOperationId", undefined) + updateBankState("currentWithdrawalOperationId", undefined) onClose() }, } @@ -155,7 +157,7 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive status: "aborted", error: undefined, onClose: async () => { - updateSettings("currentWithdrawalOperationId", undefined) + updateBankState("currentWithdrawalOperationId", undefined) onClose() }, } @@ -163,14 +165,14 @@ export function useComponentState({ currency, onClose }: Props): utils.Recursive if (data.status === "confirmed") { if (!settings.showWithdrawalSuccess) { - updateSettings("currentWithdrawalOperationId", undefined) + updateBankState("currentWithdrawalOperationId", undefined) onClose() } return { status: "confirmed", error: undefined, onClose: async () => { - updateSettings("currentWithdrawalOperationId", undefined) + updateBankState("currentWithdrawalOperationId", undefined) onClose() }, } -- cgit v1.2.3