From 8aa9ce6d20b41b7eb9b438a56ccd34cb0da35f80 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 21 Mar 2024 12:11:31 -0300 Subject: wip --- .../bank-ui/src/pages/regional/CreateCashout.tsx | 159 ++------------------- 1 file changed, 14 insertions(+), 145 deletions(-) (limited to 'packages/bank-ui/src/pages/regional/CreateCashout.tsx') diff --git a/packages/bank-ui/src/pages/regional/CreateCashout.tsx b/packages/bank-ui/src/pages/regional/CreateCashout.tsx index 20d6b0bff..393240dee 100644 --- a/packages/bank-ui/src/pages/regional/CreateCashout.tsx +++ b/packages/bank-ui/src/pages/regional/CreateCashout.tsx @@ -37,7 +37,7 @@ import { import { Fragment, VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js"; -import { VersionHint, useBankCoreApiContext } from "../../context/config.js"; +import { useBankCoreApiContext } from "@gnu-taler/web-util/browser"; import { useAccountDetails } from "../../hooks/account.js"; import { useBankState } from "../../hooks/bank-state.js"; import { @@ -46,7 +46,7 @@ import { useConversionInfo, } from "../../hooks/regional.js"; import { useSessionState } from "../../hooks/session.js"; -import { RouteDefinition } from "../../route.js"; +import { RouteDefinition } from "@gnu-taler/web-util/browser"; import { TanChannel, undefinedIfEmpty } from "../../utils.js"; import { LoginForm } from "../LoginForm.js"; import { @@ -90,7 +90,7 @@ export function CreateCashout({ const creds = credentials.status !== "loggedIn" ? undefined : credentials; const [, updateBankState] = useBankState(); - const { bank: api, config, hints } = useBankCoreApiContext(); + const { lib: { bank: api }, config, hints } = useBankCoreApiContext(); const [form, setForm] = useState>({ isDebit: true }); const [notification, notify, handleError] = useLocalNotification(); const info = useConversionInfo(); @@ -116,8 +116,6 @@ export function CreateCashout({ ); } - const OLD_CASHOUT_API = hints.indexOf(VersionHint.CASHOUT_BEFORE_2FA) !== -1; - if (!resultAccount) { return ; } @@ -198,8 +196,7 @@ export function CreateCashout({ * depending on the isDebit flag */ const inputAmount = Amounts.parseOrThrow( - `${form.isDebit ? regional_currency : fiat_currency}:${ - !form.amount ? "0" : form.amount + `${form.isDebit ? regional_currency : fiat_currency}:${!form.amount ? "0" : form.amount }`, ); @@ -240,19 +237,17 @@ export function CreateCashout({ : Amounts.cmp(limit, calc.debit) === -1 ? i18n.str`Balance is not enough` : form.isDebit && - Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) < 1 - ? i18n.str`Needs to be higher than ${ - Amounts.stringifyValueWithSpec( - Amounts.parseOrThrow(conversionInfo.cashout_min_amount), - regional_currency_specification, - ).normal + Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) < 1 + ? i18n.str`Needs to be higher than ${Amounts.stringifyValueWithSpec( + Amounts.parseOrThrow(conversionInfo.cashout_min_amount), + regional_currency_specification, + ).normal }` : calculationResult === "amount-is-too-small" ? i18n.str`Amount needs to be higher` : Amounts.isZero(calc.credit) ? i18n.str`The total transfer at destination will be zero` : undefined, - channel: OLD_CASHOUT_API && !form.channel ? i18n.str`Required` : undefined, }); const trimmedAmountStr = form.amount?.trim(); @@ -260,9 +255,7 @@ export function CreateCashout({ const request_uid = encodeCrock(getRandomBytes(32)); await handleError(async () => { // new cashout api doesn't require channel - const validChannel = - !OLD_CASHOUT_API || - config.supported_tan_channels.length === 0 || + const validChannel = config.supported_tan_channels.length === 0 || form.channel; if (!creds || !form.subject || !validChannel) return; @@ -613,9 +606,9 @@ export function CreateCashout({ cashoutDisabled ? undefined : (value) => { - form.amount = value; - updateForm(structuredClone(form)); - } + form.amount = value; + updateForm(structuredClone(form)); + } } /> {Amounts.isZero(sellFee) || - Amounts.isZero(calc.beforeFee) ? undefined : ( + Amounts.isZero(calc.beforeFee) ? undefined : (
@@ -687,130 +680,6 @@ export function CreateCashout({
)} - {/* channel, not shown if new cashout api */} - {!OLD_CASHOUT_API ? undefined : config.supported_tan_channels - .length === 0 ? ( -
- - - Before doing a cashout the server need to provide an - second channel to confirm the operation - - -
- ) : ( -
- -
-
- {config.supported_tan_channels.indexOf( - TanChannel.EMAIL, - ) === -1 ? undefined : ( - - )} - - {config.supported_tan_channels.indexOf(TanChannel.SMS) === - -1 ? undefined : ( - - )} -
-
-
- )} -- cgit v1.2.3