summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/withdraw.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-09-13 15:32:06 -0300
committerSebastian <sebasjm@gmail.com>2021-09-13 15:32:15 -0300
commit9f009873809d5b7e8d1d95d77f009862724c577b (patch)
treecd424abc49b290c684f9947daa759a9a6fb28150 /packages/taler-wallet-core/src/operations/withdraw.ts
parent57b6cd42692584063819ccac3c2218f1283332a4 (diff)
downloadwallet-core-9f009873809d5b7e8d1d95d77f009862724c577b.tar.gz
wallet-core-9f009873809d5b7e8d1d95d77f009862724c577b.tar.bz2
wallet-core-9f009873809d5b7e8d1d95d77f009862724c577b.zip
added integration with the wallet-core to get info about the last tos approved
Diffstat (limited to 'packages/taler-wallet-core/src/operations/withdraw.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index 620ad88be..f63723535 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -66,6 +66,8 @@ import {
WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
WALLET_EXCHANGE_PROTOCOL_VERSION,
} from "../versions.js";
+import { stringify } from "querystring";
+import { downloadExchangeWithTermsOfService, ExchangeTosDownloadResult } from "./exchanges";
/**
* Logger for this file.
@@ -132,6 +134,11 @@ export interface ExchangeWithdrawDetails {
termsOfServiceAccepted: boolean;
/**
+ * Tos
+ */
+ tosRequested: ExchangeTosDownloadResult | undefined
+
+ /**
* The exchange is trusted directly.
*/
isTrusted: boolean;
@@ -930,6 +937,7 @@ export async function getExchangeWithdrawalInfo(
ws: InternalWalletState,
baseUrl: string,
amount: AmountJson,
+ tosAcceptedFormat?: string[],
): Promise<ExchangeWithdrawDetails> {
const {
exchange,
@@ -996,6 +1004,34 @@ export async function getExchangeWithdrawalInfo(
}
}
+ const noTosDownloaded =
+ exchangeDetails.termsOfServiceContentType === undefined ||
+ exchangeDetails.termsOfServiceAcceptedEtag === undefined ||
+ exchangeDetails.termsOfServiceText === undefined;
+
+ let tosFound: ExchangeTosDownloadResult | undefined = noTosDownloaded ? undefined : {
+ tosContentType: exchangeDetails.termsOfServiceContentType!,
+ tosEtag: exchangeDetails.termsOfServiceAcceptedEtag!,
+ tosText: exchangeDetails.termsOfServiceText!,
+ };
+
+ try {
+ if (tosAcceptedFormat) for (const format of tosAcceptedFormat) {
+ const resp = await downloadExchangeWithTermsOfService(
+ exchangeDetails.exchangeBaseUrl,
+ ws.http,
+ { d_ms: 1000 },
+ format
+ );
+ if (resp.tosContentType === format) {
+ tosFound = resp
+ break
+ }
+ }
+ } catch (e) {
+ tosFound = undefined
+ }
+
const withdrawFee = Amounts.sub(
selectedDenoms.totalWithdrawCost,
selectedDenoms.totalCoinValue,
@@ -1018,6 +1054,7 @@ export async function getExchangeWithdrawalInfo(
walletVersion: WALLET_EXCHANGE_PROTOCOL_VERSION,
withdrawFee,
termsOfServiceAccepted: tosAccepted,
+ tosRequested: tosFound
};
return ret;
}