diff options
Diffstat (limited to 'packages/bank-ui/src/pages/regional/CreateCashout.tsx')
-rw-r--r-- | packages/bank-ui/src/pages/regional/CreateCashout.tsx | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/packages/bank-ui/src/pages/regional/CreateCashout.tsx b/packages/bank-ui/src/pages/regional/CreateCashout.tsx index 8e54bbd4e..c51b96b8b 100644 --- a/packages/bank-ui/src/pages/regional/CreateCashout.tsx +++ b/packages/bank-ui/src/pages/regional/CreateCashout.tsx @@ -59,6 +59,7 @@ interface Props { account: string; focus?: boolean; onAuthorizationRequired: () => void; + onCashout: () => void; routeClose: RouteDefinition; routeHere: RouteDefinition; } @@ -76,6 +77,7 @@ type ErrorFrom<T> = { export function CreateCashout({ account: accountName, onAuthorizationRequired, + onCashout, focus, routeHere, routeClose, @@ -93,7 +95,6 @@ export function CreateCashout({ const { lib: { bank: api }, config, - hints, } = useBankCoreApiContext(); const [form, setForm] = useState<Partial<FormType>>({ isDebit: true }); const [notification, notify, handleError] = useLocalNotification(); @@ -167,13 +168,6 @@ export function CreateCashout({ ); } - const account = { - balance: Amounts.parseOrThrow(resultAccount.body.balance.amount), - balanceIsDebit: - resultAccount.body.balance.credit_debit_indicator == "debit", - debitThreshold: Amounts.parseOrThrow(resultAccount.body.debit_threshold), - }; - const { fiat_currency, regional_currency, @@ -182,6 +176,15 @@ export function CreateCashout({ } = info.body; const regionalZero = Amounts.zeroOfCurrency(regional_currency); const fiatZero = Amounts.zeroOfCurrency(fiat_currency); + + const account = { + balance: Amounts.parseOrThrow(resultAccount.body.balance.amount), + balanceIsDebit: + resultAccount.body.balance.credit_debit_indicator == "debit", + debitThreshold: Amounts.parseOrThrow(resultAccount.body.debit_threshold), + minCashout: resultAccount.body.min_cashout === undefined ? regionalZero : Amounts.parseOrThrow(resultAccount.body.min_cashout) + }; + const limit = account.balanceIsDebit ? Amounts.sub(account.debitThreshold, account.balance).amount : Amounts.add(account.balance, account.debitThreshold).amount; @@ -241,16 +244,23 @@ export function CreateCashout({ ? i18n.str`Invalid` : 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 ${ + : calculationResult === "amount-is-too-small" + ? i18n.str`Amount needs to be higher` + : Amounts.cmp(calc.debit, conversionInfo.cashout_min_amount) < 0 + ? i18n.str`No account can't cashout less 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.cmp(calc.debit, account.minCashout) < 0 + ? i18n.str`Your account can't cashout less than ${ + Amounts.stringifyValueWithSpec( + Amounts.parseOrThrow(account.minCashout), + regional_currency_specification, + ).normal + }` + : Amounts.isZero(calc.credit) ? i18n.str`The total transfer at destination will be zero` : undefined, @@ -260,21 +270,17 @@ export function CreateCashout({ async function createCashout() { const request_uid = encodeCrock(getRandomBytes(32)); await handleError(async () => { - // new cashout api doesn't require channel - const validChannel = - config.supported_tan_channels.length === 0 || form.channel; - - if (!creds || !form.subject || !validChannel) return; + if (!creds || !form.subject) return; 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`); + onCashout(); } else { switch (resp.case) { case HttpStatusCode.Accepted: { @@ -335,6 +341,15 @@ export function CreateCashout({ debug: resp.detail, when: AbsoluteTime.now(), }); + case TalerErrorCode.BANK_CONVERSION_AMOUNT_TO_SMALL: + return notify({ + type: "error", + title: i18n.str`The amount is less than the minimum allowed.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + when: AbsoluteTime.now(), + }); + case TalerErrorCode.BANK_TAN_CHANNEL_SCRIPT_FAILED: return notify({ type: "error", |