From 9f009873809d5b7e8d1d95d77f009862724c577b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 13 Sep 2021 15:32:06 -0300 Subject: added integration with the wallet-core to get info about the last tos approved --- .../taler-wallet-webextension/src/cta/Withdraw.tsx | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 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 c0347000d..ac25bcd15 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx @@ -30,7 +30,7 @@ import { LogoHeader } from '../components/LogoHeader'; import { Part } from '../components/Part'; import { ButtonDestructive, ButtonSuccess, ButtonWarning, LinkSuccess, TermsOfService, WalletAction } from '../components/styled'; import { - acceptWithdrawal, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, onUpdateNotification + acceptWithdrawal, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, onUpdateNotification, setExchangeTosAccepted } from "../wxApi"; import { h } from 'preact'; @@ -48,6 +48,7 @@ export interface ViewProps { onAccept: (b: boolean) => void; reviewing: boolean; accepted: boolean; + confirmed: boolean; terms: { value?: TermsDocument; status: TermsStatus; @@ -75,7 +76,7 @@ function amountToString(text: AmountLike) { return `${amount} ${aj.currency}` } -export function View({ details, amount, onWithdraw, terms, reviewing, onReview, onAccept, accepted }: ViewProps) { +export function View({ details, amount, onWithdraw, terms, reviewing, onReview, onAccept, accepted, confirmed }: ViewProps) { const needsReview = terms.status === 'changed' || terms.status === 'new' return ( @@ -172,7 +173,7 @@ export function View({ details, amount, onWithdraw, terms, reviewing, onReview,
{i18n.str`Confirm withdrawal`} @@ -203,6 +204,7 @@ export function WithdrawPage({ talerWithdrawUri, ...rest }: Props): JSX.Element const [updateCounter, setUpdateCounter] = useState(1); const [reviewing, setReviewing] = useState(false) const [accepted, setAccepted] = useState(false) + const [confirmed, setConfirmed] = useState(false) useEffect(() => { return onUpdateNotification(() => { @@ -231,7 +233,8 @@ export function WithdrawPage({ talerWithdrawUri, ...rest }: Props): JSX.Element if (!uriInfo || !uriInfo.defaultExchangeBaseUrl) return const res = await getExchangeWithdrawalInfo({ exchangeBaseUrl: uriInfo.defaultExchangeBaseUrl, - amount: Amounts.parseOrThrow(uriInfo.amount) + amount: Amounts.parseOrThrow(uriInfo.amount), + tosAcceptedFormat: ['text/json', 'text/xml', 'text/pdf'] }) setDetails(res) } @@ -242,10 +245,19 @@ export function WithdrawPage({ talerWithdrawUri, ...rest }: Props): JSX.Element return missing withdraw uri; } + const onAccept = async (): Promise => { + if (!details) { + throw Error("can't accept, no exchange selected"); + } + await setExchangeTosAccepted(details.exchangeDetails.exchangeBaseUrl, details.tosRequested?.tosEtag) + setAccepted(true) + } + const onWithdraw = async (): Promise => { if (!details) { throw Error("can't accept, no exchange selected"); } + setConfirmed(true) console.log("accepting exchange", details.exchangeInfo.baseUrl); const res = await acceptWithdrawal(talerWithdrawUri, details.exchangeInfo.baseUrl); console.log("accept withdrawal response", res); @@ -267,11 +279,33 @@ export function WithdrawPage({ talerWithdrawUri, ...rest }: Props): JSX.Element return Getting withdrawal details.; } + let termsContent: TermsDocument | undefined = undefined; + if (details.tosRequested) { + if (details.tosRequested.tosContentType === 'text/xml') { + try { + const document = new DOMParser().parseFromString(details.tosRequested.tosText, "text/xml") + termsContent = { type: 'xml', document } + } catch (e) { + console.log(e) + debugger; + } + } + } + + const status: TermsStatus = !termsContent ? 'notfound' : ( + !details.exchangeDetails.termsOfServiceAcceptedEtag ? 'new' : ( + details.tosRequested?.tosEtag !== details.exchangeDetails.termsOfServiceAcceptedEtag ? 'changed' : 'accepted' + )) + + return -- cgit v1.2.3