diff options
author | Sebastian <sebasjm@gmail.com> | 2024-01-11 16:41:24 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-01-11 16:41:42 -0300 |
commit | 82d4ed90caa4a6ea3bdda1fb80ccecf3dc3637f9 (patch) | |
tree | 59162f0565311e8699ca643a8bd60337ee7f582b /packages/demobank-ui/src/pages/business/CreateCashout.tsx | |
parent | ca67640f9f94f1150c0fb67c148dc79daa9d3fa0 (diff) | |
download | wallet-core-82d4ed90caa4a6ea3bdda1fb80ccecf3dc3637f9.tar.xz |
2fa
Diffstat (limited to 'packages/demobank-ui/src/pages/business/CreateCashout.tsx')
-rw-r--r-- | packages/demobank-ui/src/pages/business/CreateCashout.tsx | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index d97a00a2e..e4fda8fb6 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -14,6 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ import { + AbsoluteTime, Amounts, HttpStatusCode, TalerCorebankApi, @@ -36,7 +37,7 @@ import { import { Fragment, VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js"; -import { useBankCoreApiContext } from "../../context/config.js"; +import { VersionHint, useBankCoreApiContext } from "../../context/config.js"; import { useAccountDetails } from "../../hooks/access.js"; import { useBackendState } from "../../hooks/backend.js"; import { @@ -55,7 +56,7 @@ import { useBankState } from "../../hooks/bank-state.js"; interface Props { account: string; focus?: boolean, - onComplete: (id: string) => void; + onAuthorizationRequired: () => void, onCancel?: () => void; } @@ -72,7 +73,7 @@ type ErrorFrom<T> = { export function CreateCashout({ account: accountName, - onComplete, + onAuthorizationRequired, focus, onCancel, }: Props): VNode { @@ -86,7 +87,7 @@ export function CreateCashout({ const creds = credentials.status !== "loggedIn" ? undefined : credentials const [, updateBankState] = useBankState() - const { api, config } = useBankCoreApiContext() + const { api, config, hints } = useBankCoreApiContext() const [form, setForm] = useState<Partial<FormType>>({ isDebit: true, }); const [notification, notify, handleError] = useLocalNotification() const info = useConversionInfo(); @@ -96,6 +97,9 @@ export function CreateCashout({ <i18n.Translate>The bank configuration does not support cashout operations.</i18n.Translate> </Attention> } + + const OLD_CASHOUT_API = hints.indexOf(VersionHint.CASHOUT_BEFORE_2FA) !== -1 + if (!resultAccount) { return <Loading /> } @@ -179,33 +183,37 @@ export function CreateCashout({ : Amounts.isZero(calc.credit) ? i18n.str`the total transfer at destination will be zero` : undefined, - channel: !form.channel ? i18n.str`required` : undefined, + channel: OLD_CASHOUT_API && !form.channel ? i18n.str`required` : undefined, }); const trimmedAmountStr = form.amount?.trim(); async function createCashout() { const request_uid = encodeCrock(getRandomBytes(32)) await handleError(async () => { - const validChannel = config.supported_tan_channels.length === 0 || form.channel + //new cashout api doesn't require channel + const validChannel = !OLD_CASHOUT_API || config.supported_tan_channels.length === 0 || form.channel if (!creds || !form.subject || !validChannel) return; - const resp = await api.createCashout(creds, { + const request = { request_uid, amount_credit: Amounts.stringify(calc.credit), amount_debit: Amounts.stringify(calc.debit), subject: form.subject, tan_channel: form.channel, - }) + } + const resp = await api.createCashout(creds, request) if (resp.type === "ok") { notifyInfo(i18n.str`Cashout created`) } else { switch (resp.case) { case HttpStatusCode.Accepted: { - updateBankState("currentChallengeId", resp.body.challenge_id) - return notify({ - type: "info", - title: i18n.str`Cashout created but confirmation is required.`, - }); + updateBankState("currentChallenge", { + operation: "create-cashout", + id: String(resp.body.challenge_id), + sent: AbsoluteTime.never(), + request, + }) + return onAuthorizationRequired() } case HttpStatusCode.NotFound: return notify({ type: "error", @@ -444,8 +452,8 @@ export function CreateCashout({ </div> )} - {/* channel */} - {config.supported_tan_channels.length === 0 ? + {/* channel, not shown if new cashout api */} + {!OLD_CASHOUT_API ? undefined : config.supported_tan_channels.length === 0 ? <div class="sm:col-span-5"> <Attention type="warning" title={i18n.str`No cashout channel available`}> <i18n.Translate> |