From 829a59e1a24d6a99ce7554d28acfd05f21baeaf8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 22 Nov 2021 17:34:27 -0300 Subject: add exchange feature --- .../taler-wallet-webextension/src/cta/Withdraw.tsx | 255 ++++----------------- 1 file changed, 41 insertions(+), 214 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.tsx') diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx index 8258717bd..4ebbe11c6 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx @@ -25,14 +25,11 @@ import { AmountJson, Amounts, ExchangeListItem, - GetExchangeTosResult, i18n, WithdrawUriInfoResponse, } from "@gnu-taler/taler-util"; -import { VNode, h, Fragment } from "preact"; +import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { CheckboxOutlined } from "../components/CheckboxOutlined"; -import { ExchangeXmlTos } from "../components/ExchangeToS"; import { LogoHeader } from "../components/LogoHeader"; import { Part } from "../components/Part"; import { SelectList } from "../components/SelectList"; @@ -40,19 +37,13 @@ import { ButtonSuccess, ButtonWarning, LinkSuccess, - TermsOfService, WalletAction, WarningText, } from "../components/styled"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook"; -import { - acceptWithdrawal, - getExchangeTos, - getExchangeWithdrawalInfo, - getWithdrawalDetailsForUri, - listExchanges, - setExchangeTosAccepted, -} from "../wxApi"; +import { amountToString, buildTermsOfServiceState, TermsState } from "../utils"; +import * as wxApi from "../wxApi"; +import { TermsOfServiceSection } from "./TermsOfServiceSection"; interface Props { talerWithdrawUri?: string; @@ -60,7 +51,7 @@ interface Props { export interface ViewProps { withdrawalFee: AmountJson; - exchangeBaseUrl: string; + exchangeBaseUrl?: string; amount: AmountJson; onSwitchExchange: (ex: string) => void; onWithdraw: () => Promise; @@ -69,53 +60,10 @@ export interface ViewProps { reviewing: boolean; reviewed: boolean; confirmed: boolean; - terms: { - value?: TermsDocument; - status: TermsStatus; - }; + terms: TermsState; knownExchanges: ExchangeListItem[]; } -type TermsStatus = "new" | "accepted" | "changed" | "notfound"; - -type TermsDocument = - | TermsDocumentXml - | TermsDocumentHtml - | TermsDocumentPlain - | TermsDocumentJson - | TermsDocumentPdf; - -interface TermsDocumentXml { - type: "xml"; - document: Document; -} - -interface TermsDocumentHtml { - type: "html"; - href: URL; -} - -interface TermsDocumentPlain { - type: "plain"; - content: string; -} - -interface TermsDocumentJson { - type: "json"; - data: any; -} - -interface TermsDocumentPdf { - type: "pdf"; - location: URL; -} - -function amountToString(text: AmountJson): string { - const aj = Amounts.jsonifyAmount(text); - const amount = Amounts.stringifyValue(aj); - return `${amount} ${aj.currency}`; -} - export function View({ withdrawalFee, exchangeBaseUrl, @@ -162,7 +110,9 @@ export function View({ kind="negative" /> )} - + {exchangeBaseUrl && ( + + )} {!reviewing && (
@@ -190,13 +140,6 @@ export function View({ )}
)} - {!reviewing && reviewed && ( -
- onReview(true)}> - {i18n.str`Show terms of service`} - -
- )} {terms.status === "notfound" && (
@@ -204,79 +147,14 @@ export function View({
)} - {reviewing && ( -
- {terms.status !== "accepted" && - terms.value && - terms.value.type === "xml" && ( - - - - )} - {terms.status !== "accepted" && - terms.value && - terms.value.type === "plain" && ( -
-
{terms.value.content}
-
- )} - {terms.status !== "accepted" && - terms.value && - terms.value.type === "html" && ( -