From 7582855e2723e11de25f10b6d5ba8a0757616765 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 19 Oct 2023 15:10:18 -0300 Subject: some ui fixes --- packages/demobank-ui/src/pages/business/Home.tsx | 93 +++++------------------- 1 file changed, 17 insertions(+), 76 deletions(-) (limited to 'packages/demobank-ui/src/pages/business') diff --git a/packages/demobank-ui/src/pages/business/Home.tsx b/packages/demobank-ui/src/pages/business/Home.tsx index 03d7895e3..d7beda01d 100644 --- a/packages/demobank-ui/src/pages/business/Home.tsx +++ b/packages/demobank-ui/src/pages/business/Home.tsx @@ -45,6 +45,7 @@ import { TanChannel, buildRequestErrorMessage, undefinedIfEmpty, + withRuntimeErrorHandling, } from "../../utils.js"; import { LoginForm } from "../LoginForm.js"; import { InputAmount } from "../PaytoWireTransferForm.js"; @@ -241,41 +242,15 @@ function CreateCashout({ ); useEffect(() => { - if (form.isDebit) { - calculateFromDebit(amount, sellFee, sellRate) - .then((r) => { - setCalc(r); - }) - .catch((error) => { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) - } - }); - } else { - calculateFromCredit(amount, sellFee, sellRate) - .then((r) => { - setCalc(r); - }) - .catch((error) => { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) - } - }); + async function doAsync() { + await withRuntimeErrorHandling(i18n, async () => { + const resp = await (form.isDebit ? + calculateFromDebit(amount, sellFee, sellRate) : + calculateFromCredit(amount, sellFee, sellRate)); + setCalc(resp) + }) } + doAsync() }, [form.amount, form.isDebit]); const balanceAfter = Amounts.sub(account.balance, calc.debit).amount; @@ -484,7 +459,7 @@ function CreateCashout({ e.preventDefault(); if (errors || !creds) return; - try { + await withRuntimeErrorHandling(i18n, async () => { const resp = await api.createCashout(creds, { amount_credit: Amounts.stringify(calc.credit), amount_debit: Amounts.stringify(calc.debit), @@ -529,18 +504,7 @@ function CreateCashout({ default: assertUnreachable(resp) } } - } catch (error) { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) - } - } + }) }} > {i18n.str`Create`} @@ -669,7 +633,7 @@ export function ShowCashoutDetails({ onClick={async (e) => { e.preventDefault(); if (!creds) return; - try { + await withRuntimeErrorHandling(i18n, async () => { const resp = await api.abortCashoutById(creds, id); if (resp.type === "ok") { onCancel(); @@ -692,18 +656,7 @@ export function ShowCashoutDetails({ } } } - } catch (error) { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) - } - } + }) }} > {i18n.str`Abort`} @@ -715,9 +668,8 @@ export function ShowCashoutDetails({ class="pure-button pure-button-primary " onClick={async (e) => { e.preventDefault(); - if (!creds) return; - try { - if (!code) return; + if (!creds || !code) return; + await withRuntimeErrorHandling(i18n, async () => { const resp = await api.confirmCashoutById(creds, id, { tan: code, }); @@ -745,19 +697,8 @@ export function ShowCashoutDetails({ }) default: assertUnreachable(resp) } - } - } catch (error) { - if (error instanceof TalerError) { - notify(buildRequestErrorMessage(i18n, error)) - } else { - notifyError( - i18n.str`Operation failed, please report`, - (error instanceof Error - ? error.message - : JSON.stringify(error)) as TranslatedString - ) - } - } + } + }) }} > {i18n.str`Confirm`} -- cgit v1.2.3