diff options
author | Sebastian <sebasjm@gmail.com> | 2023-02-13 15:32:23 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-02-13 15:32:23 -0300 |
commit | 6106caeba9e017242dfd334c34c8473aefb6ffb0 (patch) | |
tree | abbfa3a86b1b865938e1a5f43404269f7167491b /packages/taler-wallet-webextension/src/cta | |
parent | bb6644367bc014fcc09e44a7b32c2f58861ac835 (diff) | |
download | wallet-core-6106caeba9e017242dfd334c34c8473aefb6ffb0.tar.gz wallet-core-6106caeba9e017242dfd334c34c8473aefb6ffb0.tar.bz2 wallet-core-6106caeba9e017242dfd334c34c8473aefb6ffb0.zip |
fix broken build since wallet-core new api and placeholder for payment-temlate
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
6 files changed, 273 insertions, 0 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index f53be00c9..e92eb78c0 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -27,6 +27,7 @@ import { PreparePayResultInsufficientBalance, PreparePayResultPaymentPossible, PreparePayResultType, + ScopeType, } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; @@ -143,6 +144,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -198,6 +204,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -256,6 +267,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -312,6 +328,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -376,6 +397,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -459,6 +485,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, @@ -485,6 +516,11 @@ describe("Payment CTA states", () => { pendingIncoming: "USD:0", pendingOutgoing: "USD:0", requiresUserInput: false, + scopeInfo: { + currency: "USD", + type: ScopeType.Auditor, + url: "", + }, }, ], }, diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/index.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/index.ts new file mode 100644 index 000000000..2cdc8d2e1 --- /dev/null +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/index.ts @@ -0,0 +1,56 @@ +/* + 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 { ErrorAlertView } from "../../components/CurrentAlerts.js"; +import { Loading } from "../../components/Loading.js"; +import { ErrorAlert } from "../../context/alert.js"; +import { compose, StateViewMap } from "../../utils/index.js"; +import { useComponentState } from "./state.js"; +import { ReadyView } from "./views.js"; + +export interface Props { + talerTemplateUri?: string; +} + +export type State = State.Loading | State.LoadingUriError | State.Ready; + +export namespace State { + export interface Loading { + status: "loading"; + error: undefined; + } + export interface LoadingUriError { + status: "error"; + error: ErrorAlert; + } + + export interface Ready { + status: "ready"; + error: undefined; + } +} + +const viewMapping: StateViewMap<State> = { + loading: Loading, + error: ErrorAlertView, + ready: ReadyView, +}; + +export const PaymentTemplatePage = compose( + "PaymentTemplate", + (p: Props) => useComponentState(p), + viewMapping, +); diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts new file mode 100644 index 000000000..f5e6dee61 --- /dev/null +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts @@ -0,0 +1,63 @@ +/* + 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 { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +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"; + +export function useComponentState({ talerTemplateUri }: Props): State { + // const { pushAlertOnError } = useAlertContext(); + const api = useBackendContext(); + const { i18n } = useTranslationContext(); + + const hook = useAsyncAsHook(async () => { + if (!talerTemplateUri) throw Error("ERROR_NO-URI-FOR-PAYMENT-TEMPLATE"); + const payStatus = await api.wallet.call( + WalletApiOperation.PreparePayForTemplate, + { + talerPayTemplateUri: talerTemplateUri, + templateParams: {}, + }, + ); + const balance = await api.wallet.call(WalletApiOperation.GetBalances, {}); + return { payStatus, balance, uri: talerTemplateUri }; + }, []); + + if (!hook) { + return { + status: "loading", + error: undefined, + }; + } + + if (hook.hasError) { + return { + status: "error", + error: alertFromError( + i18n.str`Could not load the status of the order template`, + hook, + ), + }; + } + + return { + status: "ready", + error: undefined, + }; +} diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/stories.tsx b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/stories.tsx new file mode 100644 index 000000000..32a080959 --- /dev/null +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/stories.tsx @@ -0,0 +1,34 @@ +/* + 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 { tests } from "@gnu-taler/web-util/lib/index.browser"; +import { ReadyView } from "./views.js"; + +export default { + title: "payment template", + component: ReadyView, + argTypes: {}, +}; + +export const PaymentPossible = tests.createExample(ReadyView, { + status: "ready", + error: undefined, +}); diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts new file mode 100644 index 000000000..d4c65e008 --- /dev/null +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts @@ -0,0 +1,55 @@ +/* + 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 { expect } from "chai"; +import { tests } from "../../../../web-util/src/index.browser.js"; +import { createWalletApiMock } from "../../test-utils.js"; +import { useComponentState } from "./state.js"; + +describe("Order template CTA states", () => { + it("should tell the user that the URI is missing", async () => { + const { handler, TestingContext } = createWalletApiMock(); + const props = { + talerTemplateUri: undefined, + }; + + const hookBehavior = await tests.hookBehaveLikeThis( + useComponentState, + props, + [ + ({ status, error }) => { + expect(status).equals("loading"); + expect(error).undefined; + }, + ({ status, error }) => { + expect(status).equals("error"); + if (error === undefined) expect.fail(); + // expect(error.hasError).true; + // expect(error.operational).false; + }, + ], + TestingContext, + ); + + expect(hookBehavior).deep.equal({ result: "ok" }); + expect(handler.getCallingQueueState()).eq("empty"); + }); +}); diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx new file mode 100644 index 000000000..d3f893c7e --- /dev/null +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx @@ -0,0 +1,29 @@ +/* + 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 { Fragment, h, VNode } from "preact"; +import { useTranslationContext } from "../../context/translation.js"; +import { State } from "./index.js"; + +export function ReadyView({ status }: State.Ready): VNode { + const { i18n } = useTranslationContext(); + + return ( + <div> + <i18n.Translate>Not yet implemented</i18n.Translate> + </div> + ); +} |