diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Tip')
3 files changed, 89 insertions, 57 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Tip/index.ts b/packages/taler-wallet-webextension/src/cta/Tip/index.ts index 53c890b2c..4bdad0808 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/index.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/index.ts @@ -20,13 +20,14 @@ import { HookError } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js"; import { compose, StateViewMap } from "../../utils/index.js"; import * as wxApi from "../../wxApi.js"; -import { - Props as TermsOfServiceSectionProps -} from "../TermsOfServiceSection.js"; +import { Props as TermsOfServiceSectionProps } from "../TermsOfServiceSection.js"; import { useComponentState } from "./state.js"; -import { AcceptedView, IgnoredView, LoadingUriView, ReadyView } from "./views.js"; - - +import { + AcceptedView, + IgnoredView, + LoadingUriView, + ReadyView, +} from "./views.js"; export interface Props { talerTipUri?: string; @@ -42,7 +43,6 @@ export type State = | State.Ignored; export namespace State { - export interface Loading { status: "loading"; error: undefined; @@ -77,9 +77,13 @@ export namespace State { const viewMapping: StateViewMap<State> = { loading: Loading, "loading-uri": LoadingUriView, - "accepted": AcceptedView, - "ignored": IgnoredView, - "ready": ReadyView, + accepted: AcceptedView, + ignored: IgnoredView, + ready: ReadyView, }; -export const TipPage = compose("Tip", (p: Props) => useComponentState(p, wxApi), viewMapping) +export const TipPage = compose( + "Tip", + (p: Props) => useComponentState(p, wxApi), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/cta/Tip/state.ts b/packages/taler-wallet-webextension/src/cta/Tip/state.ts index aa62bd5e3..333337e78 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/state.ts @@ -14,7 +14,6 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - import { Amounts } from "@gnu-taler/taler-util"; import { useState } from "preact/hooks"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; @@ -37,7 +36,7 @@ export function useComponentState( return { status: "loading", error: undefined, - } + }; } if (tipInfo.hasError) { return { @@ -59,9 +58,9 @@ export function useComponentState( amount: Amounts.parseOrThrow(tip.tipAmountEffective), error: undefined, cancel: { - onClick: onCancel - } - } + onClick: onCancel, + }, + }; if (tipIgnored) { return { @@ -85,4 +84,3 @@ export function useComponentState( }, }; } - diff --git a/packages/taler-wallet-webextension/src/cta/Tip/test.ts b/packages/taler-wallet-webextension/src/cta/Tip/test.ts index ccb36572e..4895fcc7f 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/test.ts @@ -19,9 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { - Amounts, PrepareTipResult -} from "@gnu-taler/taler-util"; +import { Amounts, PrepareTipResult } from "@gnu-taler/taler-util"; import { expect } from "chai"; import { mountHook } from "../../test-utils.js"; import { useComponentState } from "./state.js"; @@ -30,10 +28,18 @@ describe("Tip CTA states", () => { it("should tell the user that the URI is missing", async () => { const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState({ talerTipUri: undefined, onCancel: async () => { null } }, { - prepareTip: async () => ({}), - acceptTip: async () => ({}), - } as any), + useComponentState( + { + talerTipUri: undefined, + onCancel: async () => { + null; + }, + }, + { + prepareTip: async () => ({}), + acceptTip: async () => ({}), + } as any, + ), ); { @@ -62,19 +68,27 @@ describe("Tip CTA states", () => { const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState({ talerTipUri: "taler://tip/asd", onCancel: async () => { null } }, { - prepareTip: async () => - ({ - accepted: tipAccepted, - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => { - tipAccepted = true; + useComponentState( + { + talerTipUri: "taler://tip/asd", + onCancel: async () => { + null; + }, }, - } as any), + { + prepareTip: async () => + ({ + accepted: tipAccepted, + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => { + tipAccepted = true; + }, + } as any, + ), ); { @@ -114,16 +128,24 @@ describe("Tip CTA states", () => { it("should be ignored after clicking the ignore button", async () => { const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState({ talerTipUri: "taler://tip/asd", onCancel: async () => { null } }, { - prepareTip: async () => - ({ - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => ({}), - } as any), + useComponentState( + { + talerTipUri: "taler://tip/asd", + onCancel: async () => { + null; + }, + }, + { + prepareTip: async () => + ({ + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => ({}), + } as any, + ), ); { @@ -160,17 +182,25 @@ describe("Tip CTA states", () => { it("should render accepted if the tip has been used previously", async () => { const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = mountHook(() => - useComponentState({ talerTipUri: "taler://tip/asd", onCancel: async () => { null } }, { - prepareTip: async () => - ({ - accepted: true, - exchangeBaseUrl: "exchange url", - merchantBaseUrl: "merchant url", - tipAmountEffective: "EUR:1", - walletTipId: "tip_id", - } as PrepareTipResult as any), - acceptTip: async () => ({}), - } as any), + useComponentState( + { + talerTipUri: "taler://tip/asd", + onCancel: async () => { + null; + }, + }, + { + prepareTip: async () => + ({ + accepted: true, + exchangeBaseUrl: "exchange url", + merchantBaseUrl: "merchant url", + tipAmountEffective: "EUR:1", + walletTipId: "tip_id", + } as PrepareTipResult as any), + acceptTip: async () => ({}), + } as any, + ), ); { |