aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-10-13 14:26:18 -0300
committerSebastian <sebasjm@gmail.com>2021-10-13 14:26:18 -0300
commitfbf501e727ffe37c30a0ebe038dfb8ae900be749 (patch)
treec3269b60751e1f3b729b2990736c587a6cbcd1b1 /packages/taler-wallet-webextension
parent021d508337490d25f6d7293bf0deadbb5f298f8c (diff)
fixing tos request
Diffstat (limited to 'packages/taler-wallet-webextension')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx243
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.tsx52
-rw-r--r--packages/taler-wallet-webextension/src/wxApi.ts14
3 files changed, 170 insertions, 139 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
index 59bbfc3bc..5e29a3e39 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.stories.tsx
@@ -785,21 +785,23 @@ export const NewTerms = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -821,21 +823,23 @@ export const TermsReviewingPLAIN = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -858,21 +862,23 @@ export const TermsReviewingHTML = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -910,21 +916,23 @@ export const TermsReviewingPDF = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -948,21 +956,23 @@ export const TermsReviewingXML = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -985,21 +995,23 @@ export const NewTermsAccepted = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -1021,21 +1033,23 @@ export const TermsShowAgainXML = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -1050,6 +1064,7 @@ export const TermsShowAgainXML = createExample(TestedComponent, {
},
status: 'new'
},
+ reviewed: true,
reviewing: true,
})
@@ -1058,21 +1073,23 @@ export const TermsChanged = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -1094,21 +1111,23 @@ export const TermsNotFound = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -1126,21 +1145,23 @@ export const TermsAlreadyAccepted = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: amountFractionalBase * 0.5,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: amountFractionalBase * 0.5,
+ value: 0
+ },
amount: {
currency: 'USD',
value: 2,
@@ -1159,21 +1180,23 @@ export const WithoutFee = createExample(TestedComponent, {
currency: 'USD',
exchangeBaseUrl: 'exchange.demo.taler.net',
paytoUris: ['asd'],
- },{
+ }, {
currency: 'USD',
exchangeBaseUrl: 'exchange.test.taler.net',
paytoUris: ['asd'],
}],
+ exchangeBaseUrl: 'exchange.demo.taler.net',
details: {
- exchangeInfo: {
- baseUrl: 'exchange.demo.taler.net'
- } as ExchangeRecord,
- withdrawFee: {
- currency: 'USD',
- fraction: 0,
- value: 0
- },
- } as ExchangeWithdrawDetails,
+ content: '',
+ contentType: '',
+ currentEtag: '',
+ acceptedEtag: undefined,
+ },
+ withdrawalFee: {
+ currency: 'USD',
+ fraction: 0,
+ value: 0,
+ },
amount: {
currency: 'USD',
value: 2,
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index 5ae1e86ec..ecc0420be 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -21,7 +21,7 @@
* @author Florian Dold
*/
-import { AmountJson, Amounts, ExchangeListItem, i18n, WithdrawUriInfoResponse } from '@gnu-taler/taler-util';
+import { AmountJson, Amounts, ExchangeListItem, GetExchangeTosResult, i18n, WithdrawUriInfoResponse } from '@gnu-taler/taler-util';
import { ExchangeWithdrawDetails } from '@gnu-taler/taler-wallet-core/src/operations/withdraw';
import { useState } from "preact/hooks";
import { Fragment } from 'preact/jsx-runtime';
@@ -33,7 +33,7 @@ import { SelectList } from '../components/SelectList';
import { ButtonSuccess, ButtonWarning, LinkSuccess, LinkWarning, TermsOfService, WalletAction } from '../components/styled';
import { useAsyncAsHook } from '../hooks/useAsyncAsHook';
import {
- acceptWithdrawal, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, setExchangeTosAccepted, listExchanges
+ acceptWithdrawal, getExchangeWithdrawalInfo, getWithdrawalDetailsForUri, setExchangeTosAccepted, listExchanges, getExchangeTos
} from "../wxApi";
import { wxMain } from '../wxBackend.js';
@@ -42,7 +42,9 @@ interface Props {
}
export interface ViewProps {
- details: ExchangeWithdrawDetails;
+ details: GetExchangeTosResult;
+ withdrawalFee: AmountJson;
+ exchangeBaseUrl: string;
amount: AmountJson;
onSwitchExchange: (ex: string) => void;
onWithdraw: () => Promise<void>;
@@ -54,8 +56,8 @@ export interface ViewProps {
terms: {
value?: TermsDocument;
status: TermsStatus;
- },
- knownExchanges: ExchangeListItem[]
+ };
+ knownExchanges: ExchangeListItem[];
};
@@ -94,7 +96,7 @@ function amountToString(text: AmountJson) {
return `${amount} ${aj.currency}`
}
-export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExchange, terms, reviewing, onReview, onAccept, reviewed, confirmed }: ViewProps) {
+export function View({ details, withdrawalFee, exchangeBaseUrl, knownExchanges, amount, onWithdraw, onSwitchExchange, terms, reviewing, onReview, onAccept, reviewed, confirmed }: ViewProps) {
const needsReview = terms.status === 'changed' || terms.status === 'new'
const [switchingExchange, setSwitchingExchange] = useState<string | undefined>(undefined)
@@ -107,12 +109,12 @@ export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExch
{i18n.str`Digital cash withdrawal`}
</h2>
<section>
- <Part title="Total to withdraw" text={amountToString(Amounts.sub(amount, details.withdrawFee).amount)} kind='positive' />
+ <Part title="Total to withdraw" text={amountToString(Amounts.sub(amount, withdrawalFee).amount)} kind='positive' />
<Part title="Chosen amount" text={amountToString(amount)} kind='neutral' />
- {Amounts.isNonZero(details.withdrawFee) &&
- <Part title="Exchange fee" text={amountToString(details.withdrawFee)} kind='negative' />
+ {Amounts.isNonZero(withdrawalFee) &&
+ <Part title="Exchange fee" text={amountToString(withdrawalFee)} kind='negative' />
}
- <Part title="Exchange" text={details.exchangeInfo.baseUrl} kind='neutral' big />
+ <Part title="Exchange" text={exchangeBaseUrl} kind='neutral' big />
</section>
{!reviewing &&
<section>
@@ -190,7 +192,7 @@ export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExch
{terms.status === 'new' && !reviewed && !reviewing &&
<ButtonSuccess
upperCased
- disabled={!details.exchangeInfo.baseUrl}
+ disabled={!exchangeBaseUrl}
onClick={() => onReview(true)}
>
{i18n.str`Review exchange terms of service`}
@@ -199,7 +201,7 @@ export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExch
{terms.status === 'changed' && !reviewed && !reviewing &&
<ButtonWarning
upperCased
- disabled={!details.exchangeInfo.baseUrl}
+ disabled={!exchangeBaseUrl}
onClick={() => onReview(true)}
>
{i18n.str`Review new version of terms of service`}
@@ -208,7 +210,7 @@ export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExch
{(terms.status === 'accepted' || (needsReview && reviewed)) &&
<ButtonSuccess
upperCased
- disabled={!details.exchangeInfo.baseUrl || confirmed}
+ disabled={!exchangeBaseUrl || confirmed}
onClick={onWithdraw}
>
{i18n.str`Confirm withdrawal`}
@@ -220,7 +222,7 @@ export function View({ details, knownExchanges, amount, onWithdraw, onSwitchExch
</LinkWarning>
<ButtonWarning
upperCased
- disabled={!details.exchangeInfo.baseUrl}
+ disabled={!exchangeBaseUrl}
onClick={onWithdraw}
>
{i18n.str`Withdraw anyway`}
@@ -249,11 +251,13 @@ export function WithdrawPageWithParsedURI({ uri, uriInfo }: { uri: string, uriIn
const exchange = customExchange || uriInfo.defaultExchangeBaseUrl || thisCurrencyExchanges[0]?.exchangeBaseUrl
const detailsHook = useAsyncAsHook(async () => {
if (!exchange) throw Error('no default exchange')
- return getExchangeWithdrawalInfo({
+ const tos = await getExchangeTos(exchange, ['text/xml'])
+ const info = await getExchangeWithdrawalInfo({
exchangeBaseUrl: exchange,
amount: withdrawAmount,
tosAcceptedFormat: ['text/xml']
})
+ return {tos, info}
})
if (!detailsHook) {
@@ -267,7 +271,7 @@ export function WithdrawPageWithParsedURI({ uri, uriInfo }: { uri: string, uriIn
const onAccept = async (): Promise<void> => {
try {
- await setExchangeTosAccepted(details.exchangeInfo.baseUrl, details.tosRequested?.tosEtag)
+ await setExchangeTosAccepted(exchange, details.tos.currentEtag)
setReviewed(true)
} catch (e) {
if (e instanceof Error) {
@@ -278,9 +282,9 @@ export function WithdrawPageWithParsedURI({ uri, uriInfo }: { uri: string, uriIn
const onWithdraw = async (): Promise<void> => {
setConfirmed(true)
- console.log("accepting exchange", details.exchangeDetails.exchangeBaseUrl);
+ console.log("accepting exchange", exchange);
try {
- const res = await acceptWithdrawal(uri, details.exchangeInfo.baseUrl);
+ const res = await acceptWithdrawal(uri, exchange);
console.log("accept withdrawal response", res);
if (res.confirmTransferUrl) {
document.location.href = res.confirmTransferUrl;
@@ -290,17 +294,18 @@ export function WithdrawPageWithParsedURI({ uri, uriInfo }: { uri: string, uriIn
}
};
- const termsContent: TermsDocument | undefined = !details.tosRequested ? undefined : parseTermsOfServiceContent(details.tosRequested.tosContentType, details.tosRequested.tosText);
+ const termsContent: TermsDocument | undefined = parseTermsOfServiceContent(details.tos.contentType, details.tos.content);
const status: TermsStatus = !termsContent ? 'notfound' : (
- !details.exchangeDetails.termsOfServiceAcceptedEtag ? 'new' : (
- details.tosRequested?.tosEtag !== details.exchangeDetails.termsOfServiceAcceptedEtag ? 'changed' : 'accepted'
+ !details.tos.acceptedEtag ? 'new' : (
+ details.tos.acceptedEtag !== details.tos.currentEtag ? 'changed' : 'accepted'
))
return <View onWithdraw={onWithdraw}
- // setCancelled={setCancelled} setSelecting={setSelecting}
- details={details} amount={withdrawAmount}
+ details={details.tos} amount={withdrawAmount}
+ exchangeBaseUrl={exchange}
+ withdrawalFee={details.info.withdrawFee} //FIXME
terms={{
status, value: termsContent
}}
@@ -309,7 +314,6 @@ export function WithdrawPageWithParsedURI({ uri, uriInfo }: { uri: string, uriIn
confirmed={confirmed}
reviewed={reviewed} onAccept={onAccept}
reviewing={reviewing} onReview={setReviewing}
- // terms={[]}
/>
}
export function WithdrawPage({ talerWithdrawUri }: Props): JSX.Element {
diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts
index b40b06ad9..92597cbd2 100644
--- a/packages/taler-wallet-webextension/src/wxApi.ts
+++ b/packages/taler-wallet-webextension/src/wxApi.ts
@@ -45,6 +45,7 @@ import {
AmountJson,
ExchangesListRespose,
AddExchangeRequest,
+ GetExchangeTosResult,
} from "@gnu-taler/taler-util";
import { AddBackupProviderRequest, BackupProviderState, OperationFailedError, RemoveBackupProviderRequest } from "@gnu-taler/taler-wallet-core";
import { BackupInfo } from "@gnu-taler/taler-wallet-core";
@@ -327,11 +328,14 @@ export function getExchangeWithdrawalInfo(
): Promise<ExchangeWithdrawDetails> {
return callBackend("getExchangeWithdrawalInfo", req);
}
-// export const codecForAddExchangeRequest = (): Codec<AddExchangeRequest> =>
-// buildCodecForObject<AddExchangeRequest>()
-// .property("exchangeBaseUrl", codecForString())
-// .property("forceUpdate", codecOptional(codecForBoolean()))
-// .build("AddExchangeRequest");
+export function getExchangeTos(
+ exchangeBaseUrl: string,
+ acceptedFormat: string[],
+): Promise<GetExchangeTosResult> {
+ return callBackend("getExchangeTos", {
+ exchangeBaseUrl, acceptedFormat
+ });
+}
export function addExchange(
req: AddExchangeRequest,