aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/business
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-10-19 15:10:18 -0300
committerSebastian <sebasjm@gmail.com>2023-10-19 15:10:18 -0300
commit7582855e2723e11de25f10b6d5ba8a0757616765 (patch)
tree320f30c7202c88ba63542b93de1cbda533a73356 /packages/demobank-ui/src/pages/business
parent9e925a2f56677600973c4659f82776a6a56339bb (diff)
downloadwallet-core-7582855e2723e11de25f10b6d5ba8a0757616765.tar.xz
some ui fixes
Diffstat (limited to 'packages/demobank-ui/src/pages/business')
-rw-r--r--packages/demobank-ui/src/pages/business/Home.tsx93
1 files changed, 17 insertions, 76 deletions
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`}