aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-01-09 20:20:09 -0300
committerSebastian <sebasjm@gmail.com>2023-01-09 20:20:09 -0300
commit4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 (patch)
tree5c16976f99eb973ff62d78ed64107ca01df57b99 /packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
parent8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff)
downloadwallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.xz
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/DestinationSelection/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts31
1 files changed, 16 insertions, 15 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
index 1fe324c5a..d5015ae1d 100644
--- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
+++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts
@@ -17,7 +17,7 @@
import { Amounts } 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";
@@ -26,6 +26,7 @@ import { Contact, Props, State } from "./index.js";
export function useComponentState(props: Props): RecursiveState<State> {
const api = useBackendContext();
+ const { pushAlertOnError } = useAlertContext();
const parsedInitialAmount = !props.amount
? undefined
: Amounts.parse(props.amount);
@@ -108,26 +109,26 @@ export function useComponentState(props: Props): RecursiveState<State> {
error: undefined,
previous,
selectCurrency: {
- onClick: async () => {
+ onClick: pushAlertOnError(async () => {
setAmount(undefined);
- },
+ }),
},
goToBank: {
onClick: invalid
? undefined
- : async () => {
+ : pushAlertOnError(async () => {
props.goToWalletBankDeposit(currencyAndAmount);
- },
+ }),
},
goToWallet: {
onClick: invalid
? undefined
- : async () => {
+ : pushAlertOnError(async () => {
props.goToWalletWalletSend(currencyAndAmount);
- },
+ }),
},
amountHandler: {
- onInput: async (s) => setAmount(s),
+ onInput: pushAlertOnError(async (s) => setAmount(s)),
value: amount,
},
type: props.type,
@@ -138,26 +139,26 @@ export function useComponentState(props: Props): RecursiveState<State> {
error: undefined,
previous,
selectCurrency: {
- onClick: async () => {
+ onClick: pushAlertOnError(async () => {
setAmount(undefined);
- },
+ }),
},
goToBank: {
onClick: invalid
? undefined
- : async () => {
+ : pushAlertOnError(async () => {
props.goToWalletManualWithdraw(currencyAndAmount);
- },
+ }),
},
goToWallet: {
onClick: invalid
? undefined
- : async () => {
+ : pushAlertOnError(async () => {
props.goToWalletWalletInvoice(currencyAndAmount);
- },
+ }),
},
amountHandler: {
- onInput: async (s) => setAmount(s),
+ onInput: pushAlertOnError(async (s) => setAmount(s)),
value: amount,
},
type: props.type,