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/cta/TransferPickup | |
parent | 8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff) | |
download | wallet-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/cta/TransferPickup')
4 files changed, 13 insertions, 33 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts index 7bb8785d7..5cfbe7170 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/index.ts @@ -57,7 +57,6 @@ export namespace State { expiration: AbsoluteTime | undefined; error: undefined; accept: ButtonHandler; - operationError?: TalerErrorDetail; } } diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts index 04fc0e0a7..12643b893 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts @@ -22,7 +22,7 @@ import { } from "@gnu-taler/taler-util"; import { TalerError, 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"; @@ -34,15 +34,13 @@ export function useComponentState({ onSuccess, }: Props): State { const api = useBackendContext(); + const { pushAlertOnError } = useAlertContext(); const { i18n } = useTranslationContext(); const hook = useAsyncAsHook(async () => { return await api.wallet.call(WalletApiOperation.CheckPeerPushPayment, { talerUri: talerPayPushUri, }); }, []); - const [operationError, setOperationError] = useState< - TalerErrorDetail | undefined - >(undefined); if (!hook) { return { @@ -74,34 +72,25 @@ export function useComponentState({ contractTerms?.purse_expiration; async function accept(): Promise<void> { - try { - const resp = await api.wallet.call( - WalletApiOperation.AcceptPeerPushPayment, - { - peerPushPaymentIncomingId, - }, - ); - onSuccess(resp.transactionId); - } catch (e) { - if (e instanceof TalerError) { - setOperationError(e.errorDetail); - } - console.error(e); - throw Error("error trying to accept"); - } + const resp = await api.wallet.call( + WalletApiOperation.AcceptPeerPushPayment, + { + peerPushPaymentIncomingId, + }, + ); + onSuccess(resp.transactionId); } return { status: "ready", amount: Amounts.parseOrThrow(amount), error: undefined, accept: { - onClick: accept, + onClick: pushAlertOnError(accept), }, summary, expiration: expiration ? AbsoluteTime.fromTimestamp(expiration) : undefined, cancel: { - onClick: onClose, + onClick: pushAlertOnError(onClose), }, - operationError, }; } diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/stories.tsx b/packages/taler-wallet-webextension/src/cta/TransferPickup/stories.tsx index 250e99ae1..48f006127 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/stories.tsx @@ -19,14 +19,14 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { createExample } from "../../test-utils.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { ReadyView } from "./views.js"; export default { title: "transfer pickup", }; -export const Ready = createExample(ReadyView, { +export const Ready = tests.createExample(ReadyView, { amount: { currency: "ARS", value: 1, diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx b/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx index d2402db3a..25f5cdf52 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx @@ -30,8 +30,6 @@ export function ReadyView({ summary, expiration, amount, - cancel, - operationError, }: State.Ready): VNode { const { i18n } = useTranslationContext(); return ( @@ -40,12 +38,6 @@ export function ReadyView({ <SubTitle> <i18n.Translate>Digital cash transfer</i18n.Translate> </SubTitle> - {operationError && ( - <ErrorTalerOperation - title={i18n.str`Could not finish the pickup operation`} - error={operationError} - /> - )} <section style={{ textAlign: "left" }}> <Part title={i18n.str`Subject`} text={<div>{summary}</div>} /> <Part title={i18n.str`Amount`} text={<Amount value={amount} />} /> |