diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts index 9c4a3162e..66c018ddf 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts @@ -25,10 +25,11 @@ import { } from "@gnu-taler/taler-util"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, 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"; +import { withSafe } from "../../mui/handlers.js"; import { Props, State } from "./index.js"; export function useComponentState({ @@ -39,6 +40,7 @@ export function useComponentState({ }: Props): State { const api = useBackendContext(); const { i18n } = useTranslationContext(); + const { pushAlertOnError } = useAlertContext(); const hook = useAsyncAsHook(async () => { const p2p = await api.wallet.call(WalletApiOperation.CheckPeerPullPayment, { talerUri: talerPayPullUri, @@ -54,10 +56,6 @@ export function useComponentState({ ), ); - const [operationError, setOperationError] = useState< - TalerErrorDetail | undefined - >(undefined); - if (!hook) { return { status: "loading", @@ -109,18 +107,17 @@ export function useComponentState({ contractTerms: {} as any, amountRaw: hook.response.p2p.amount, noncePriv: "", - }; + } as any; //FIXME: check this interface with new values const baseResult = { uri: talerPayPullUri, cancel: { - onClick: onClose, + onClick: pushAlertOnError(onClose), }, amount, goToWalletManualWithdraw, summary, expiration: expiration ? AbsoluteTime.fromTimestamp(expiration) : undefined, - operationError, }; if (!foundBalance) { @@ -148,21 +145,13 @@ export function useComponentState({ } async function accept(): Promise<void> { - try { - const resp = await api.wallet.call( - WalletApiOperation.AcceptPeerPullPayment, - { - peerPullPaymentIncomingId, - }, - ); - 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.AcceptPeerPullPayment, + { + peerPullPaymentIncomingId, + }, + ); + onSuccess(resp.transactionId); } return { @@ -172,7 +161,7 @@ export function useComponentState({ payStatus: paymentPossible, balance: foundAmount, accept: { - onClick: accept, + onClick: pushAlertOnError(accept), }, }; } |