aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Reward
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-02-06 17:06:56 -0300
committerSebastian <sebasjm@gmail.com>2024-02-06 17:06:56 -0300
commit27e4ff3011527d9c0b7630dc7a4080f8fb817300 (patch)
treea56f906cc36065eaf1733ea97a4eccc690145094 /packages/taler-wallet-webextension/src/cta/Reward
parentf91319e404ecfebfbc343175dd0bb73ab10eb4c0 (diff)
downloadwallet-core-27e4ff3011527d9c0b7630dc7a4080f8fb817300.tar.xz
fixes #8336 remove rewards
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Reward')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Reward/index.ts84
-rw-r--r--packages/taler-wallet-webextension/src/cta/Reward/state.ts100
-rw-r--r--packages/taler-wallet-webextension/src/cta/Reward/stories.tsx46
-rw-r--r--packages/taler-wallet-webextension/src/cta/Reward/test.ts228
-rw-r--r--packages/taler-wallet-webextension/src/cta/Reward/views.tsx90
5 files changed, 0 insertions, 548 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Reward/index.ts b/packages/taler-wallet-webextension/src/cta/Reward/index.ts
deleted file mode 100644
index 5e56db7bc..000000000
--- a/packages/taler-wallet-webextension/src/cta/Reward/index.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import { AmountJson } from "@gnu-taler/taler-util";
-import { ErrorAlertView } from "../../components/CurrentAlerts.js";
-import { Loading } from "../../components/Loading.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 { AcceptedView, IgnoredView, ReadyView } from "./views.js";
-
-export interface Props {
- talerTipUri?: string;
- onCancel: () => Promise<void>;
- onSuccess: (tx: string) => Promise<void>;
-}
-
-export type State =
- | State.Loading
- | State.LoadingUriError
- | State.Ignored
- | State.Accepted
- | State.Ready
- | State.Ignored;
-
-export namespace State {
- export interface Loading {
- status: "loading";
- error: undefined;
- }
-
- export interface LoadingUriError {
- status: "error";
- error: ErrorAlert;
- }
-
- export interface BaseInfo {
- merchantBaseUrl: string;
- amount: AmountJson;
- exchangeBaseUrl: string;
- error: undefined;
- cancel: ButtonHandler;
- }
-
- export interface Ignored extends BaseInfo {
- status: "ignored";
- }
-
- export interface Accepted extends BaseInfo {
- status: "accepted";
- }
- export interface Ready extends BaseInfo {
- status: "ready";
- accept: ButtonHandler;
- }
-}
-
-const viewMapping: StateViewMap<State> = {
- loading: Loading,
- error: ErrorAlertView,
- accepted: AcceptedView,
- ignored: IgnoredView,
- ready: ReadyView,
-};
-
-export const TipPage = compose(
- "Tip",
- (p: Props) => useComponentState(p),
- viewMapping,
-);
diff --git a/packages/taler-wallet-webextension/src/cta/Reward/state.ts b/packages/taler-wallet-webextension/src/cta/Reward/state.ts
deleted file mode 100644
index a4244a444..000000000
--- a/packages/taler-wallet-webextension/src/cta/Reward/state.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import { Amounts, TransactionIdStr } from "@gnu-taler/taler-util";
-import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { alertFromError, useAlertContext } from "../../context/alert.js";
-import { useBackendContext } from "../../context/backend.js";
-import { useTranslationContext } from "@gnu-taler/web-util/browser";
-import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
-import { Props, State } from "./index.js";
-
-export function useComponentState({
- talerTipUri: talerRewardUri,
- onCancel,
- onSuccess,
-}: Props): State {
- const api = useBackendContext();
- const { i18n } = useTranslationContext();
- const { pushAlertOnError } = useAlertContext();
- const tipInfo = useAsyncAsHook(async () => {
- if (!talerRewardUri) throw Error("ERROR_NO-URI-FOR-TIP");
- const tip = await api.wallet.call(WalletApiOperation.PrepareReward, {
- talerRewardUri,
- });
- return { tip };
- });
-
- if (!tipInfo) {
- return {
- status: "loading",
- error: undefined,
- };
- }
- if (tipInfo.hasError) {
- return {
- status: "error",
- error: alertFromError(
- i18n.str`Could not load the status of the term of service`,
- tipInfo,
- ),
- };
- }
- // if (tipInfo.hasError) {
- // return {
- // status: "loading-uri",
- // error: tipInfo,
- // };
- // }
-
- const { tip } = tipInfo.response;
-
- const doAccept = async (): Promise<void> => {
-
- const res = await api.wallet.call(WalletApiOperation.AcceptReward, {
- transactionId: tip.transactionId,
- });
-
- //FIX: this may not be seen since we are moving to the success also
- tipInfo.retry();
- onSuccess(res.transactionId);
- };
-
- const baseInfo = {
- merchantBaseUrl: tip.merchantBaseUrl,
- exchangeBaseUrl: tip.exchangeBaseUrl,
- amount: Amounts.parseOrThrow(tip.rewardAmountEffective),
- error: undefined,
- cancel: {
- onClick: pushAlertOnError(onCancel),
- },
- };
-
- if (tip.accepted) {
- return {
- status: "accepted",
- ...baseInfo,
- };
- }
-
- return {
- status: "ready",
- ...baseInfo,
- accept: {
- onClick: pushAlertOnError(doAccept),
- },
- };
-}
diff --git a/packages/taler-wallet-webextension/src/cta/Reward/stories.tsx b/packages/taler-wallet-webextension/src/cta/Reward/stories.tsx
deleted file mode 100644
index bd5fdefd9..000000000
--- a/packages/taler-wallet-webextension/src/cta/Reward/stories.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-/**
- *
- * @author Sebastian Javier Marchano (sebasjm)
- */
-
-import { Amounts } from "@gnu-taler/taler-util";
-import * as tests from "@gnu-taler/web-util/testing";
-import { AcceptedView, ReadyView } from "./views.js";
-
-export default {
- title: "tip",
-};
-
-export const Accepted = tests.createExample(AcceptedView, {
- status: "accepted",
- error: undefined,
- amount: Amounts.parseOrThrow("EUR:1"),
- exchangeBaseUrl: "",
- merchantBaseUrl: "",
-});
-
-export const Ready = tests.createExample(ReadyView, {
- status: "ready",
- error: undefined,
- amount: Amounts.parseOrThrow("EUR:1"),
- merchantBaseUrl: "http://merchant.url/",
- exchangeBaseUrl: "http://exchange.url/",
- accept: {},
- cancel: {},
-});
diff --git a/packages/taler-wallet-webextension/src/cta/Reward/test.ts b/packages/taler-wallet-webextension/src/cta/Reward/test.ts
deleted file mode 100644
index aa19af261..000000000
--- a/packages/taler-wallet-webextension/src/cta/Reward/test.ts
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-/**
- *
- * @author Sebastian Javier Marchano (sebasjm)
- */
-
-import { AmountString, Amounts, TransactionIdStr } from "@gnu-taler/taler-util";
-import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { expect } from "chai";
-import * as tests from "@gnu-taler/web-util/testing";
-import { nullFunction } from "../../mui/handlers.js";
-import { createWalletApiMock } from "../../test-utils.js";
-import { Props } from "./index.js";
-import { useComponentState } from "./state.js";
-
-describe("Tip CTA states", () => {
- it("should tell the user that the URI is missing", async () => {
- const { handler, TestingContext } = createWalletApiMock();
-
- const props: Props = {
- talerTipUri: undefined,
- onCancel: nullFunction,
- onSuccess: nullFunction,
- };
-
- const hookBehavior = await tests.hookBehaveLikeThis(
- useComponentState,
- props,
- [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- ({ status, error }) => {
- expect(status).equals("error");
- if (!error) expect.fail();
- expect(error.description).eq("ERROR_NO-URI-FOR-TIP");
- },
- ],
- TestingContext,
- );
-
- expect(hookBehavior).deep.equal({ result: "ok" });
- expect(handler.getCallingQueueState()).eq("empty");
- });
-
- it("should be ready for accepting the tip", async () => {
- const { handler, TestingContext } = createWalletApiMock();
-
- handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
- accepted: false,
- exchangeBaseUrl: "exchange url",
- merchantBaseUrl: "merchant url",
- rewardAmountEffective: "EUR:1" as AmountString,
- walletRewardId: "tip_id",
- transactionId: "txn:tip:ABC1234" as TransactionIdStr,
- expirationTimestamp: {
- t_s: 1,
- },
- rewardAmountRaw: "EUR:0" as AmountString,
- });
-
- const props: Props = {
- talerTipUri: "taler://tip/asd",
- onCancel: nullFunction,
- onSuccess: nullFunction,
- };
-
- const hookBehavior = await tests.hookBehaveLikeThis(
- useComponentState,
- props,
- [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "ready") {
- expect(state).eq({ status: "ready" });
- return;
- }
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- if (state.accept.onClick === undefined) expect.fail();
-
- handler.addWalletCallResponse(WalletApiOperation.AcceptReward);
- state.accept.onClick();
-
- handler.addWalletCallResponse(
- WalletApiOperation.PrepareReward,
- undefined,
- {
- accepted: true,
- exchangeBaseUrl: "exchange url",
- merchantBaseUrl: "merchant url",
- rewardAmountEffective: "EUR:1" as AmountString,
- walletRewardId: "tip_id",
- transactionId: "txn:tip:ABC1234" as TransactionIdStr,
- expirationTimestamp: {
- t_s: 1,
- },
- rewardAmountRaw: "EUR:0" as AmountString,
- },
- );
- },
- (state) => {
- if (state.status !== "accepted") expect.fail();
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- },
- ],
- TestingContext,
- );
-
- expect(hookBehavior).deep.equal({ result: "ok" });
- expect(handler.getCallingQueueState()).eq("empty");
- });
-
- it.skip("should be ignored after clicking the ignore button", async () => {
- const { handler, TestingContext } = createWalletApiMock();
- handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
- exchangeBaseUrl: "exchange url",
- merchantBaseUrl: "merchant url",
- rewardAmountEffective: "EUR:1" as AmountString,
- walletRewardId: "tip_id",
- transactionId: "txn:tip:ABC1234" as TransactionIdStr,
- accepted: false,
- expirationTimestamp: {
- t_s: 1,
- },
- rewardAmountRaw: "EUR:0" as AmountString,
- });
-
- const props: Props = {
- talerTipUri: "taler://tip/asd",
- onCancel: nullFunction,
- onSuccess: nullFunction,
- };
-
- const hookBehavior = await tests.hookBehaveLikeThis(
- useComponentState,
- props,
- [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "ready") expect.fail();
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
-
- //FIXME: add ignore button
- },
- ],
- TestingContext,
- );
-
- expect(hookBehavior).deep.equal({ result: "ok" });
- expect(handler.getCallingQueueState()).eq("empty");
- });
-
- it("should render accepted if the tip has been used previously", async () => {
- const { handler, TestingContext } = createWalletApiMock();
-
- handler.addWalletCallResponse(WalletApiOperation.PrepareReward, undefined, {
- accepted: true,
- exchangeBaseUrl: "exchange url",
- merchantBaseUrl: "merchant url",
- rewardAmountEffective: "EUR:1" as AmountString,
- walletRewardId: "tip_id",
- transactionId: "txn:tip:ABC1234" as TransactionIdStr,
- expirationTimestamp: {
- t_s: 1,
- },
- rewardAmountRaw: "EUR:0" as AmountString,
- });
-
- const props: Props = {
- talerTipUri: "taler://tip/asd",
- onCancel: nullFunction,
- onSuccess: nullFunction,
- };
-
- const hookBehavior = await tests.hookBehaveLikeThis(
- useComponentState,
- props,
- [
- ({ status, error }) => {
- expect(status).equals("loading");
- expect(error).undefined;
- },
- (state) => {
- if (state.status !== "accepted") expect.fail();
- if (state.error) expect.fail();
- expect(state.amount).deep.eq(Amounts.parseOrThrow("EUR:1"));
- expect(state.merchantBaseUrl).eq("merchant url");
- expect(state.exchangeBaseUrl).eq("exchange url");
- },
- ],
- TestingContext,
- );
-
- expect(hookBehavior).deep.equal({ result: "ok" });
- expect(handler.getCallingQueueState()).eq("empty");
- });
-});
diff --git a/packages/taler-wallet-webextension/src/cta/Reward/views.tsx b/packages/taler-wallet-webextension/src/cta/Reward/views.tsx
deleted file mode 100644
index 9b4a6c3ef..000000000
--- a/packages/taler-wallet-webextension/src/cta/Reward/views.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2022 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-
-import { TranslatedString } from "@gnu-taler/taler-util";
-import { useTranslationContext } from "@gnu-taler/web-util/browser";
-import { Fragment, h, VNode } from "preact";
-import { Amount } from "../../components/Amount.js";
-import { Part } from "../../components/Part.js";
-import { TermsOfService } from "../../components/TermsOfService/index.js";
-import { Button } from "../../mui/Button.js";
-import { State } from "./index.js";
-
-export function IgnoredView(state: State.Ignored): VNode {
- const { i18n } = useTranslationContext();
- return (
- <Fragment>
- <span>
- <i18n.Translate>You&apos;ve ignored the tip.</i18n.Translate>
- </span>
- </Fragment>
- );
-}
-
-export function ReadyView(state: State.Ready): VNode {
- const { i18n } = useTranslationContext();
- return (
- <Fragment>
- <section>
- <p>
- <i18n.Translate>The merchant is offering you a reward</i18n.Translate>
- </p>
- <Part
- title={i18n.str`Amount`}
- text={<Amount value={state.amount} />}
- kind="positive"
- />
- <Part
- title={i18n.str`Merchant URL`}
- text={state.merchantBaseUrl as TranslatedString}
- kind="neutral"
- />
- <Part
- title={i18n.str`Exchange`}
- text={state.exchangeBaseUrl as TranslatedString}
- kind="neutral"
- />
- </section>
- <section>
- <TermsOfService key="terms" exchangeUrl={state.exchangeBaseUrl} >
- <Button
- variant="contained"
- color="success"
- onClick={state.accept.onClick}
- >
- <i18n.Translate>
- Receive &nbsp; {<Amount value={state.amount} />}
- </i18n.Translate>
- </Button>
- </TermsOfService>
- </section>
- </Fragment>
- );
-}
-
-export function AcceptedView(state: State.Accepted): VNode {
- const { i18n } = useTranslationContext();
- return (
- <Fragment>
- <section>
- <i18n.Translate>
- Tip from <code>{state.merchantBaseUrl}</code> accepted. Check your
- transactions list for more details.
- </i18n.Translate>
- </section>
- </Fragment>
- );
-}