diff options
author | Sebastian <sebasjm@gmail.com> | 2021-09-13 15:32:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-09-13 15:32:15 -0300 |
commit | 9f009873809d5b7e8d1d95d77f009862724c577b (patch) | |
tree | cd424abc49b290c684f9947daa759a9a6fb28150 /packages/taler-wallet-webextension/src/cta | |
parent | 57b6cd42692584063819ccac3c2218f1283332a4 (diff) | |
download | wallet-core-9f009873809d5b7e8d1d95d77f009862724c577b.tar.xz |
added integration with the wallet-core to get info about the last tos approved
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx | 4 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw.tsx | 46 |
2 files changed, 42 insertions, 8 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx index 022b92454..94fdea8fb 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx @@ -35,6 +35,8 @@ export default { }; const termsXml = `<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd"> +<!-- Generated by Docutils 0.14 --> <document source="/home/grothoff/research/taler/exchange/contrib/tos/tos.rst"> <section ids="terms-of-service" names="terms\ of\ service"> <title>Terms Of Service</title> @@ -234,7 +236,6 @@ const termsXml = `<?xml version="1.0" encoding="utf-8"?> <enumerated_list enumtype="loweralpha" prefix="(" suffix=")"> <list_item> <paragraph>any lost profits, data loss, cost of procurement of substitute goods or -* TLSv1.3 (IN), TLS Unknown, Unknown (23): services, or direct, indirect, incidental, special, punitive, compensatory, or consequential damages of any kind whatsoever resulting from:</paragraph> </list_item> @@ -377,7 +378,6 @@ const termsXml = `<?xml version="1.0" encoding="utf-8"?> </section> </section> </document> - `; export const WithdrawNewTermsXML = createExample(TestedComponent, { 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, <div> <ButtonSuccess upperCased - disabled={!details.exchangeInfo.baseUrl} + disabled={!details.exchangeInfo.baseUrl || confirmed} onClick={onWithdraw} > {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<boolean>(false) const [accepted, setAccepted] = useState<boolean>(false) + const [confirmed, setConfirmed] = useState<boolean>(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 <span><i18n.Translate>missing withdraw uri</i18n.Translate></span>; } + const onAccept = async (): Promise<void> => { + if (!details) { + throw Error("can't accept, no exchange selected"); + } + await setExchangeTosAccepted(details.exchangeDetails.exchangeBaseUrl, details.tosRequested?.tosEtag) + setAccepted(true) + } + const onWithdraw = async (): Promise<void> => { 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 <span><i18n.Translate>Getting withdrawal details.</i18n.Translate></span>; } + 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 <View onWithdraw={onWithdraw} // setCancelled={setCancelled} setSelecting={setSelecting} details={details} amount={uriInfo.amount} - terms={{} as any} - accepted={accepted} onAccept={setAccepted} + terms={{ + status, value: termsContent + }} + confirmed={confirmed} + accepted={accepted} onAccept={onAccept} reviewing={reviewing} onReview={setReviewing} // terms={[]} /> |