diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Refund')
4 files changed, 30 insertions, 39 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Refund/index.ts b/packages/taler-wallet-webextension/src/cta/Refund/index.ts index f79a77680..e90f770ff 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/index.ts @@ -15,17 +15,13 @@ */ import { AmountJson, Product } from "@gnu-taler/taler-util"; +import { ErrorAlertView } from "../../components/CurrentAlerts.js"; import { Loading } from "../../components/Loading.js"; -import { HookError } from "../../hooks/useAsyncAsHook.js"; +import { ErrorAlert } from "../../context/alert.js"; import { ButtonHandler } from "../../mui/handlers.js"; import { compose, StateViewMap } from "../../utils/index.js"; import { useComponentState } from "./state.js"; -import { - IgnoredView, - InProgressView, - LoadingUriView, - ReadyView, -} from "./views.js"; +import { IgnoredView, InProgressView, ReadyView } from "./views.js"; export interface Props { talerRefundUri?: string; @@ -47,8 +43,8 @@ export namespace State { } export interface LoadingUriError { - status: "loading-uri"; - error: HookError; + status: "error"; + error: ErrorAlert; } interface BaseInfo { @@ -81,7 +77,7 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, - "loading-uri": LoadingUriView, + error: ErrorAlertView, "in-progress": InProgressView, ignored: IgnoredView, ready: ReadyView, diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts index 9e3311b65..5a5073ba3 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts @@ -17,7 +17,9 @@ 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 { useBackendContext } from "../../context/backend.js"; +import { useTranslationContext } from "../../context/translation.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; @@ -27,6 +29,7 @@ export function useComponentState({ onSuccess, }: Props): State { const api = useBackendContext(); + const { i18n } = useTranslationContext(); const [ignored, setIgnored] = useState(false); const info = useAsyncAsHook(async () => { @@ -49,10 +52,19 @@ export function useComponentState({ } if (info.hasError) { return { - status: "loading-uri", - error: info, + status: "error", + error: alertFromError( + i18n.str`Could not load the status of the term of service`, + info, + ), }; } + // if (info.hasError) { + // return { + // status: "loading-uri", + // error: info, + // }; + // } const { refund, uri } = info.response; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/test.ts b/packages/taler-wallet-webextension/src/cta/Refund/test.ts index 24d483a9a..8c4daa4d2 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/test.ts @@ -53,11 +53,11 @@ describe("Refund CTA states", () => { expect(error).undefined; }, ({ status, error }) => { - expect(status).equals("loading-uri"); + expect(status).equals("error"); if (!error) expect.fail(); - if (!error.hasError) expect.fail(); - if (error.operational) expect.fail(); - expect(error.message).eq("ERROR_NO-URI-FOR-REFUND"); + // if (!error.hasError) expect.fail(); + // if (error.operational) expect.fail(); + expect(error.cause?.message).eq("ERROR_NO-URI-FOR-REFUND"); }, ], TestingContext, diff --git a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx index a55bc43dd..16e1c519c 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx @@ -17,26 +17,14 @@ import { Amounts } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { Amount } from "../../components/Amount.js"; -import { LoadingError } from "../../components/LoadingError.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; +import { ProductList } from "../../components/ProductList.js"; import { Link, SubTitle, WalletAction } from "../../components/styled/index.js"; import { useTranslationContext } from "../../context/translation.js"; import { Button } from "../../mui/Button.js"; -import { ProductList } from "../../components/ProductList.js"; import { State } from "./index.js"; -export function LoadingUriView({ error }: State.LoadingUriError): VNode { - const { i18n } = useTranslationContext(); - - return ( - <LoadingError - title={<i18n.Translate>Could not load refund status</i18n.Translate>} - error={error} - /> - ); -} - export function IgnoredView(state: State.Ignored): VNode { const { i18n } = useTranslationContext(); @@ -73,13 +61,13 @@ export function InProgressView(state: State.InProgress): VNode { <section> <Part big - title={<i18n.Translate>Total to refund</i18n.Translate>} + title={i18n.str`Total to refund`} text={<Amount value={state.awaitingAmount} />} kind="negative" /> <Part big - title={<i18n.Translate>Refunded</i18n.Translate>} + title={i18n.str`Refunded`} text={<Amount value={state.amount} />} kind="negative" /> @@ -112,21 +100,21 @@ export function ReadyView(state: State.Ready): VNode { <section> <Part big - title={<i18n.Translate>Order amount</i18n.Translate>} + title={i18n.str`Order amount`} text={<Amount value={state.amount} />} kind="neutral" /> {Amounts.isNonZero(state.granted) && ( <Part big - title={<i18n.Translate>Already refunded</i18n.Translate>} + title={i18n.str`Already refunded`} text={<Amount value={state.granted} />} kind="neutral" /> )} <Part big - title={<i18n.Translate>Refund offered</i18n.Translate>} + title={i18n.str`Refund offered`} text={<Amount value={state.awaitingAmount} />} kind="positive" /> @@ -147,11 +135,6 @@ export function ReadyView(state: State.Ready): VNode { </i18n.Translate> </Button> </section> - <section> - <Link upperCased onClick={state.cancel}> - <i18n.Translate>Cancel</i18n.Translate> - </Link> - </section> </WalletAction> ); } |