wallet-core/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx

368 lines
7.3 KiB
TypeScript
Raw Normal View History

2021-05-31 16:34:48 +02:00
/*
This file is part of GNU Taler
(C) 2021 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/>
*/
/**
2021-11-15 15:18:58 +01:00
*
* @author Sebastian Javier Marchano (sebasjm)
*/
2021-05-31 16:34:48 +02:00
import { amountFractionalBase, ExchangeListItem } from "@gnu-taler/taler-util";
2022-03-29 04:41:07 +02:00
import { createExample } from "../test-utils.js";
import { termsHtml, termsPdf, termsPlain, termsXml } from "./termsExample.js";
import { View as TestedComponent } from "./Withdraw.js";
2021-05-31 16:34:48 +02:00
2022-01-04 21:06:17 +01:00
function parseFromString(s: string): Document {
if (typeof window === "undefined") {
return {} as Document;
}
return new window.DOMParser().parseFromString(s, "text/xml");
}
2021-05-31 16:34:48 +02:00
export default {
2021-11-15 15:18:58 +01:00
title: "cta/withdraw",
component: TestedComponent,
2021-05-31 16:34:48 +02:00
};
const exchangeList: ExchangeListItem[] = [
{
currency: "USD",
exchangeBaseUrl: "exchange.demo.taler.net",
tos: {
currentVersion: "1",
acceptedVersion: "1",
content: "terms of service content",
contentType: "text/plain",
2021-11-15 15:18:58 +01:00
},
paytoUris: ["asd"],
},
{
currency: "USD",
exchangeBaseUrl: "exchange.test.taler.net",
tos: {
currentVersion: "1",
acceptedVersion: "1",
content: "terms of service content",
contentType: "text/plain",
2021-11-15 15:18:58 +01:00
},
paytoUris: ["asd"],
},
];
export const NewTerms = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
value: 1,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
status: "new",
2021-11-22 21:34:27 +01:00
version: "",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const TermsReviewingPLAIN = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-12 20:18:29 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-12 20:18:29 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-12 20:18:29 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-10-12 20:18:29 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "plain",
content: termsPlain,
2021-10-12 20:18:29 +02:00
},
2021-11-15 15:18:58 +01:00
status: "new",
2021-11-22 21:34:27 +01:00
version: "",
2021-10-12 20:18:29 +02:00
},
2021-11-15 15:18:58 +01:00
reviewing: true,
});
2021-10-12 20:18:29 +02:00
export const TermsReviewingHTML = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-12 20:18:29 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-12 20:18:29 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-12 20:18:29 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-10-12 20:18:29 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "html",
2022-04-06 17:20:00 +02:00
href: new URL(`data:text/html;base64,${toBase64(termsHtml)}`),
2021-10-12 20:18:29 +02:00
},
2021-11-22 21:34:27 +01:00
version: "",
2021-11-15 15:18:58 +01:00
status: "new",
2021-10-12 20:18:29 +02:00
},
2021-11-15 15:18:58 +01:00
reviewing: true,
});
2021-10-12 20:18:29 +02:00
2022-04-06 17:20:00 +02:00
function toBase64(str: string): string {
return btoa(
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode(parseInt(p1, 16));
}),
);
}
2021-10-12 20:18:29 +02:00
export const TermsReviewingPDF = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-12 20:18:29 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-12 20:18:29 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-12 20:18:29 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-10-12 20:18:29 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "pdf",
2022-04-06 17:20:00 +02:00
location: new URL(`data:text/html;base64,${toBase64(termsPdf)}`),
2021-10-12 20:18:29 +02:00
},
2021-11-15 15:18:58 +01:00
status: "new",
2021-11-22 21:34:27 +01:00
version: "",
2021-10-12 20:18:29 +02:00
},
2021-11-15 15:18:58 +01:00
reviewing: true,
});
2021-10-12 20:18:29 +02:00
export const TermsReviewingXML = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
status: "new",
2021-11-22 21:34:27 +01:00
version: "",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
reviewing: true,
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const NewTermsAccepted = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
status: "new",
2021-11-22 21:34:27 +01:00
version: "",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
reviewed: true,
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const TermsShowAgainXML = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-22 21:34:27 +01:00
version: "",
2021-11-15 15:18:58 +01:00
status: "new",
2021-09-13 18:32:58 +02:00
},
2021-10-13 19:26:18 +02:00
reviewed: true,
2021-09-13 18:32:58 +02:00
reviewing: true,
2021-11-15 15:18:58 +01:00
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const TermsChanged = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-22 21:34:27 +01:00
version: "",
2021-11-15 15:18:58 +01:00
status: "changed",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const TermsNotFound = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: undefined,
2021-11-15 15:18:58 +01:00
status: "notfound",
2021-11-22 21:34:27 +01:00
version: "",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const TermsAlreadyAccepted = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: amountFractionalBase * 0.5,
2021-11-15 15:18:58 +01:00
value: 0,
2021-10-13 19:26:18 +02:00
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-15 15:18:58 +01:00
status: "accepted",
2021-11-22 21:34:27 +01:00
content: undefined,
version: "",
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
});
2021-09-13 18:32:58 +02:00
2021-10-12 20:18:29 +02:00
export const WithoutFee = createExample(TestedComponent, {
knownExchanges: exchangeList,
2021-11-15 15:18:58 +01:00
exchangeBaseUrl: "exchange.demo.taler.net",
2021-10-13 19:26:18 +02:00
withdrawalFee: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-13 19:26:18 +02:00
fraction: 0,
value: 0,
},
2021-10-11 20:59:55 +02:00
amount: {
2021-11-15 15:18:58 +01:00
currency: "USD",
2021-10-11 20:59:55 +02:00
value: 2,
2021-11-15 15:18:58 +01:00
fraction: 10000000,
2021-10-11 20:59:55 +02:00
},
2021-11-16 17:59:53 +01:00
onSwitchExchange: async () => {
null;
},
2021-09-13 18:32:58 +02:00
terms: {
2021-11-22 21:34:27 +01:00
content: {
2021-11-15 15:18:58 +01:00
type: "xml",
2022-01-04 21:06:17 +01:00
document: parseFromString(termsXml),
2021-09-13 18:32:58 +02:00
},
2021-11-15 15:18:58 +01:00
status: "accepted",
2021-11-22 21:34:27 +01:00
version: "",
2021-11-15 15:18:58 +01:00
},
});