From 58c0b115175ffc963e394258ec888b2be7ad3d74 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 23 Oct 2023 16:02:58 -0300 Subject: fix more error cases --- .../src/pages/business/CreateCashout.tsx | 43 ++++++++++------------ .../src/pages/business/ShowCashoutDetails.tsx | 20 +++++++++- 2 files changed, 37 insertions(+), 26 deletions(-) (limited to 'packages/demobank-ui/src/pages/business') diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index a3a48eed4..a71915622 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -14,7 +14,6 @@ GNU Taler; see the file COPYING. If not, see */ import { - AmountJson, Amounts, TalerError, TranslatedString @@ -23,10 +22,10 @@ import { notify, useTranslationContext } from "@gnu-taler/web-util/browser"; -import { format } from "date-fns"; import { Fragment, VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; import { mutate } from "swr"; +import { Attention } from "../../components/Attention.js"; import { ErrorLoading } from "../../components/ErrorLoading.js"; import { Loading } from "../../components/Loading.js"; import { ShowInputErrorLabel } from "../../components/ShowInputErrorLabel.js"; @@ -34,9 +33,7 @@ import { useBankCoreApiContext } from "../../context/config.js"; import { useAccountDetails } from "../../hooks/access.js"; import { useBackendState } from "../../hooks/backend.js"; import { - useCashoutDetails, - useEstimator, - useRatiosAndFeeConfig, + useEstimator } from "../../hooks/circuit.js"; import { TanChannel, @@ -46,7 +43,6 @@ import { import { LoginForm } from "../LoginForm.js"; import { InputAmount } from "../PaytoWireTransferForm.js"; import { assertUnreachable } from "../WithdrawalOperationPage.js"; -import { Attention } from "../../components/Attention.js"; interface Props { account: string; @@ -71,7 +67,6 @@ export function CreateCashout({ onCancel, }: Props): VNode { const { i18n } = useTranslationContext(); - const resultRatios = useRatiosAndFeeConfig(); const resultAccount = useAccountDetails(accountName); const { estimateByCredit: calculateFromCredit, @@ -93,19 +88,17 @@ export function CreateCashout({ } - if (!resultAccount || !resultRatios) { + if (!resultAccount) { return } if (resultAccount instanceof TalerError) { return } - if (resultRatios instanceof TalerError) { - return - } if (resultAccount.type === "fail") { switch (resultAccount.case) { case "unauthorized": return case "not-found": return + case "no-rights": return default: assertUnreachable(resultAccount) } } @@ -133,14 +126,16 @@ export function CreateCashout({ const zeroCalc = { debit: zero, credit: zero, beforeFee: zero }; const [calc, setCalc] = useState(zeroCalc); - const sellRate = ratio.sell_at_ratio; - const sellFee = !ratio.sell_out_fee + const sellRate = config.conversion_info?.sell_at_ratio; + const sellFee = !config.conversion_info?.sell_out_fee ? zero : Amounts.parseOrThrow( - `${account.balance.currency}:${ratio.sell_out_fee}`, + `${account.balance.currency}:${config.conversion_info.sell_out_fee}`, ); - if (!sellRate || sellRate < 0) return
error rate
; + if (sellRate === undefined || sellRate < 0) return
error rate
; + + const safeSellRate = sellRate const amount = Amounts.parseOrThrow( `${!form.isDebit ? config.fiat_currency.name : account.balance.currency}:${!form.amount ? "0" : form.amount @@ -151,8 +146,8 @@ export function CreateCashout({ async function doAsync() { await withRuntimeErrorHandling(i18n, async () => { const resp = await (form.isDebit ? - calculateFromDebit(amount, sellFee, sellRate) : - calculateFromCredit(amount, sellFee, sellRate)); + calculateFromDebit(amount, sellFee, safeSellRate) : + calculateFromCredit(amount, sellFee, safeSellRate)); setCalc(resp) }) } @@ -383,12 +378,6 @@ export function CreateCashout({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "no-allowed": return notify({ - type: "error", - title: i18n.str`This user is not allowed to make a cashout`, - description: resp.detail.hint as TranslatedString, - debug: resp.detail, - }); case "no-contact-info": return notify({ type: "error", title: i18n.str`Need a contact data where to send the TAN`, @@ -401,12 +390,18 @@ export function CreateCashout({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "tan-not-supported": return notify({ + case "cashout-or-tan-not-supported": return notify({ type: "error", title: i18n.str`The bank does not support the TAN channel for this operation`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); + // case "": return notify({ + // type: "error", + // title: i18n.str`This user is not allowed to make a cashout`, + // description: resp.detail.hint as TranslatedString, + // debug: resp.detail, + // }); default: assertUnreachable(resp) } } diff --git a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx index 5c09e2001..b8e566348 100644 --- a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx +++ b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx @@ -38,6 +38,7 @@ import { withRuntimeErrorHandling } from "../../utils.js"; import { assertUnreachable } from "../WithdrawalOperationPage.js"; +import { Attention } from "../../components/Attention.js"; interface Props { id: string; @@ -62,8 +63,11 @@ export function ShowCashoutDetails({ } if (result.type === "fail") { switch (result.case) { - case "already-aborted": return
this cashout is already aborted
- default: assertUnreachable(result.case) + case "already-aborted": return + + case "cashout-not-supported": return + + default: assertUnreachable(result) } } const errors = undefinedIfEmpty({ @@ -175,6 +179,12 @@ export function ShowCashoutDetails({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case "cashout-not-supported": return notify({ + type: "error", + title: i18n.str`Cashout operation is not supported.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: { assertUnreachable(resp) } @@ -219,6 +229,12 @@ export function ShowCashoutDetails({ description: resp.detail.hint as TranslatedString, debug: resp.detail, }) + case "cashout-not-supported": return notify({ + type: "error", + title: i18n.str`Cashout operation is not supported.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }) default: assertUnreachable(resp) } } -- cgit v1.2.3