aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-09-05 21:09:28 +0200
committerFlorian Dold <florian@dold.me>2022-09-05 21:09:28 +0200
commit3f5a76751b3bf410ea3df023eef2f5bfd6f730cd (patch)
tree7ed7bc46035e557ad6eeb9647980d0a60eb7621c /packages/taler-wallet-core/src/wallet.ts
parent0f57f48f847a7bd0b35ddc05770aa169fec1c136 (diff)
downloadwallet-core-3f5a76751b3bf410ea3df023eef2f5bfd6f730cd.tar.gz
wallet-core-3f5a76751b3bf410ea3df023eef2f5bfd6f730cd.tar.bz2
wallet-core-3f5a76751b3bf410ea3df023eef2f5bfd6f730cd.zip
wallet-core: make listExchanges return less datav0.9.0-dev.16
Since the webextension UI depends on the full response, we have a temporary listExchangesDetailled request. See https://bugs.taler.net/n/7323 for details.
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts62
1 files changed, 59 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index 688985521..a7a39c5a9 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -72,7 +72,7 @@ import {
Duration,
durationFromSpec,
durationMin,
- ExchangeListItem,
+ ExchangeFullDetailsListItem,
ExchangesListRespose,
GetExchangeTosResult,
j2s,
@@ -87,6 +87,7 @@ import {
URL,
WalletNotification,
WalletCoreVersion,
+ ExchangeListItem,
} from "@gnu-taler/taler-util";
import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js";
import {
@@ -207,7 +208,11 @@ import {
} from "./util/promiseUtils.js";
import { DbAccess, GetReadWriteAccess } from "./util/query.js";
import { TimerAPI, TimerGroup } from "./util/timer.js";
-import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_MERCHANT_PROTOCOL_VERSION } from "./versions.js";
+import {
+ WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
+ WALLET_EXCHANGE_PROTOCOL_VERSION,
+ WALLET_MERCHANT_PROTOCOL_VERSION,
+} from "./versions.js";
import { WalletCoreApiClient } from "./wallet-api-types.js";
const builtinAuditors: AuditorTrustRecord[] = [
@@ -602,6 +607,53 @@ async function getExchanges(
content: exchangeDetails.termsOfServiceText,
},
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
+ });
+ }
+ });
+ return { exchanges };
+}
+
+async function getExchangesDetailled(
+ ws: InternalWalletState,
+): Promise<ExchangesListRespose> {
+ const exchanges: ExchangeFullDetailsListItem[] = [];
+ await ws.db
+ .mktx((x) => ({
+ exchanges: x.exchanges,
+ exchangeDetails: x.exchangeDetails,
+ denominations: x.denominations,
+ }))
+ .runReadOnly(async (tx) => {
+ const exchangeRecords = await tx.exchanges.iter().toArray();
+ for (const r of exchangeRecords) {
+ const dp = r.detailsPointer;
+ if (!dp) {
+ continue;
+ }
+ const { currency } = dp;
+ const exchangeDetails = await getExchangeDetails(tx, r.baseUrl);
+ if (!exchangeDetails) {
+ continue;
+ }
+
+ const denominations = await tx.denominations.indexes.byExchangeBaseUrl
+ .iter(r.baseUrl)
+ .toArray();
+
+ if (!denominations) {
+ continue;
+ }
+
+ exchanges.push({
+ exchangeBaseUrl: r.baseUrl,
+ currency,
+ tos: {
+ acceptedVersion: exchangeDetails.termsOfServiceAcceptedEtag,
+ currentVersion: exchangeDetails.termsOfServiceLastEtag,
+ contentType: exchangeDetails.termsOfServiceContentType,
+ content: exchangeDetails.termsOfServiceText,
+ },
+ paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
auditors: exchangeDetails.auditors,
wireInfo: exchangeDetails.wireInfo,
denominations: denominations,
@@ -782,6 +834,9 @@ async function dispatchRequestInternal(
case "listExchanges": {
return await getExchanges(ws);
}
+ case "listExchangesDetailled": {
+ return await getExchangesDetailled(ws);
+ }
case "listKnownBankAccounts": {
const req = codecForListKnownBankAccounts().decode(payload);
return await listKnownBankAccounts(ws, req.currency);
@@ -790,6 +845,7 @@ async function dispatchRequestInternal(
const req = codecForGetWithdrawalDetailsForUri().decode(payload);
return await getWithdrawalDetailsForUri(ws, req.talerWithdrawUri);
}
+
case "getExchangeWithdrawalInfo": {
const req = codecForGetExchangeWithdrawalInfo().decode(payload);
return await getExchangeWithdrawalInfo(
@@ -1078,7 +1134,7 @@ async function dispatchRequestInternal(
exchange: WALLET_EXCHANGE_PROTOCOL_VERSION,
merchant: WALLET_MERCHANT_PROTOCOL_VERSION,
bank: WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
- }
+ };
return version;
}
}