From 829a59e1a24d6a99ce7554d28acfd05f21baeaf8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 22 Nov 2021 17:34:27 -0300 Subject: add exchange feature --- .../src/wallet/ExchangeAddConfirm.tsx | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx (limited to 'packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx') diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx new file mode 100644 index 000000000..5c7f94ecd --- /dev/null +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx @@ -0,0 +1,152 @@ +import { i18n } from "@gnu-taler/taler-util"; +import { Fragment, h, VNode } from "preact"; +import { useState } from "preact/hooks"; +import { + Button, + ButtonSuccess, + ButtonWarning, + WarningBox, +} from "../components/styled/index"; +import { TermsOfServiceSection } from "../cta/TermsOfServiceSection"; +import { useAsyncAsHook } from "../hooks/useAsyncAsHook"; +import { buildTermsOfServiceState, TermsState } from "../utils"; +import * as wxApi from "../wxApi"; + +export interface Props { + url: string; + onCancel: () => void; + onConfirm: () => void; +} + +export function ExchangeAddConfirmPage({ + url, + onCancel, + onConfirm, +}: Props): VNode { + const detailsHook = useAsyncAsHook(async () => { + const tos = await wxApi.getExchangeTos(url, ["text/xml"]); + + const tosState = buildTermsOfServiceState(tos); + + return { tos: tosState }; + }); + + const termsNotFound: TermsState = { + status: "notfound", + version: "", + content: undefined, + }; + const terms = !detailsHook + ? undefined + : detailsHook.hasError + ? termsNotFound + : detailsHook.response.tos; + + // const [errorAccepting, setErrorAccepting] = useState( + // undefined, + // ); + + const onAccept = async (): Promise => { + if (!terms) return; + try { + await wxApi.setExchangeTosAccepted(url, terms.version); + } catch (e) { + if (e instanceof Error) { + // setErrorAccepting(e.message); + } + } + }; + return ( + + ); +} + +export interface ViewProps { + url: string; + terms: TermsState | undefined; + onAccept: (b: boolean) => Promise; + onCancel: () => void; + onConfirm: () => void; +} + +export function View({ + url, + terms, + onAccept: doAccept, + onConfirm, + onCancel, +}: ViewProps): VNode { + const needsReview = + !terms || terms.status === "changed" || terms.status === "new"; + const [reviewed, setReviewed] = useState(false); + + return ( + +
+

Review terms of service

+
+ Exchange URL: + + {url} + +
+
+ {terms && terms.status === "notfound" && ( +
+ + {i18n.str`Exchange doesn't have terms of service`} + +
+ )} + + {terms && ( + + doAccept(value).then(() => { + setReviewed(value); + }) + } + /> + )} + + +
+ ); +} -- cgit v1.2.3