diff options
| author | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:20:09 -0300 |
|---|---|---|
| committer | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:20:09 -0300 |
| commit | 4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 (patch) | |
| tree | 5c16976f99eb973ff62d78ed64107ca01df57b99 /packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts | |
| parent | 8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff) | |
fix #7153: more error handling
if handler do not trap error then fail at compile time,
all safe handlers push alert on error
errors are typed so they render good information
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts')
| -rw-r--r-- | packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts index b597c77be..935adf012 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts @@ -25,7 +25,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; -import { alertFromError } from "../../context/alert.js"; +import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; import { useTranslationContext } from "../../context/translation.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; @@ -39,6 +39,7 @@ export function useComponentState({ }: Props): State { const api = useBackendContext(); const { i18n } = useTranslationContext(); + const { pushAlertOnError } = useAlertContext(); const parsed = amountStr === undefined ? undefined : Amounts.parse(amountStr); const currency = parsed !== undefined ? parsed.currency : currencyStr; @@ -130,9 +131,9 @@ export function useComponentState({ error: undefined, currency, onAddAccount: { - onClick: async () => { + onClick: pushAlertOnError(async () => { setAddingAccount(true); - }, + }), }, }; } @@ -221,27 +222,27 @@ export function useComponentState({ currency, amount: { value: amount, - onInput: updateAmount, + onInput: pushAlertOnError(updateAmount), error: amountError, }, onAddAccount: { - onClick: async () => { + onClick: pushAlertOnError(async () => { setAddingAccount(true); - }, + }), }, account: { list: accountMap, value: stringifyPaytoUri(currentAccount), - onChange: updateAccountFromList, + onChange: pushAlertOnError(updateAccountFromList), }, currentAccount, cancelHandler: { - onClick: async () => { + onClick: pushAlertOnError(async () => { onCancel(currency); - }, + }), }, depositHandler: { - onClick: unableToDeposit ? undefined : doSend, + onClick: unableToDeposit ? undefined : pushAlertOnError(doSend), }, totalFee, totalToDeposit, @@ -263,7 +264,7 @@ async function getFeeForAmount( }); } -export function labelForAccountType(id: string) { +export function labelForAccountType(id: string): string { switch (id) { case "": return "Choose one"; |
