aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Refund
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/cta/Refund
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/cta/Refund')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Refund/state.ts7
-rw-r--r--packages/taler-wallet-webextension/src/cta/Refund/stories.tsx10
-rw-r--r--packages/taler-wallet-webextension/src/cta/Refund/test.ts9
3 files changed, 12 insertions, 14 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts
index 5a5073ba3..4c411ec04 100644
--- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts
@@ -17,7 +17,7 @@
import { Amounts, NotificationType } from "@gnu-taler/taler-util";
import { 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";
@@ -31,6 +31,7 @@ export function useComponentState({
const api = useBackendContext();
const { i18n } = useTranslationContext();
const [ignored, setIgnored] = useState(false);
+ const { pushAlertOnError } = useAlertContext();
const info = useAsyncAsHook(async () => {
if (!talerRefundUri) throw Error("ERROR_NO-URI-FOR-REFUND");
@@ -108,10 +109,10 @@ export function useComponentState({
...baseInfo,
orderId: info.response.refund.info.orderId,
accept: {
- onClick: doAccept,
+ onClick: pushAlertOnError(doAccept),
},
ignore: {
- onClick: doIgnore,
+ onClick: pushAlertOnError(doIgnore),
},
cancel,
};
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx b/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx
index 921cf77e6..faaee1104 100644
--- a/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Refund/stories.tsx
@@ -21,13 +21,13 @@
import { Amounts } from "@gnu-taler/taler-util";
import beer from "../../../static-dev/beer.png";
-import { createExample } from "../../test-utils.js";
+import { tests } from "@gnu-taler/web-util/lib/index.browser";
import { IgnoredView, InProgressView, ReadyView } from "./views.js";
export default {
title: "refund",
};
-export const InProgress = createExample(InProgressView, {
+export const InProgress = tests.createExample(InProgressView, {
status: "in-progress",
error: undefined,
amount: Amounts.parseOrThrow("USD:1"),
@@ -37,7 +37,7 @@ export const InProgress = createExample(InProgressView, {
products: undefined,
});
-export const Ready = createExample(ReadyView, {
+export const Ready = tests.createExample(ReadyView, {
status: "ready",
error: undefined,
accept: {},
@@ -51,7 +51,7 @@ export const Ready = createExample(ReadyView, {
orderId: "abcdef",
});
-export const WithAProductList = createExample(ReadyView, {
+export const WithAProductList = tests.createExample(ReadyView, {
status: "ready",
error: undefined,
accept: {},
@@ -75,7 +75,7 @@ export const WithAProductList = createExample(ReadyView, {
orderId: "abcdef",
});
-export const Ignored = createExample(IgnoredView, {
+export const Ignored = tests.createExample(IgnoredView, {
status: "ignored",
error: undefined,
merchantName: "the merchant",
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/test.ts b/packages/taler-wallet-webextension/src/cta/Refund/test.ts
index 8c4daa4d2..a07158e1a 100644
--- a/packages/taler-wallet-webextension/src/cta/Refund/test.ts
+++ b/packages/taler-wallet-webextension/src/cta/Refund/test.ts
@@ -27,11 +27,8 @@ import {
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { expect } from "chai";
import { tests } from "../../../../web-util/src/index.browser.js";
-import {
- createWalletApiMock,
- mountHook,
- nullFunction,
-} from "../../test-utils.js";
+import { nullFunction } from "../../mui/handlers.js";
+import { createWalletApiMock } from "../../test-utils.js";
import { useComponentState } from "./state.js";
describe("Refund CTA states", () => {
@@ -57,7 +54,7 @@ describe("Refund CTA states", () => {
if (!error) expect.fail();
// if (!error.hasError) expect.fail();
// if (error.operational) expect.fail();
- expect(error.cause?.message).eq("ERROR_NO-URI-FOR-REFUND");
+ expect(error.description).eq("ERROR_NO-URI-FOR-REFUND");
},
],
TestingContext,