aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-10-15 12:59:26 +0200
committerFlorian Dold <florian@dold.me>2022-10-15 12:59:26 +0200
commitbd88dcebbcf90414c790a86ee13740eaf20e3334 (patch)
tree3faa7508089bfa4316aebb310a7a5cf55076db34 /packages/taler-wallet-core/src
parente075134ffc94fda3582b179122bda594d91a962b (diff)
downloadwallet-core-bd88dcebbcf90414c790a86ee13740eaf20e3334.tar.xz
wallet-core: simplify exchanges list response
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r--packages/taler-wallet-core/src/operations/common.ts15
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts23
-rw-r--r--packages/taler-wallet-core/src/wallet.ts7
3 files changed, 28 insertions, 17 deletions
diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts
index 5e02f3d7b..ee7a1b46e 100644
--- a/packages/taler-wallet-core/src/operations/common.ts
+++ b/packages/taler-wallet-core/src/operations/common.ts
@@ -22,6 +22,7 @@ import {
Amounts,
CoinRefreshRequest,
CoinStatus,
+ ExchangeTosStatus,
j2s,
Logger,
RefreshReason,
@@ -31,7 +32,7 @@ import {
TransactionIdStr,
TransactionType,
} from "@gnu-taler/taler-util";
-import { WalletStoresV1, CoinRecord } from "../db.js";
+import { WalletStoresV1, CoinRecord, ExchangeDetailsRecord } from "../db.js";
import { makeErrorDetail, TalerError } from "../errors.js";
import { InternalWalletState } from "../internal-wallet-state.js";
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
@@ -307,3 +308,15 @@ export function makeTombstoneId(
): TombstoneIdStr {
return `tmb:${type}:${args.map((x) => encodeURIComponent(x)).join(":")}`;
}
+
+export function getExchangeTosStatus(
+ exchangeDetails: ExchangeDetailsRecord,
+): ExchangeTosStatus {
+ if (!exchangeDetails.tosAccepted) {
+ return ExchangeTosStatus.New;
+ }
+ if (exchangeDetails.tosAccepted?.etag == exchangeDetails.tosCurrentEtag) {
+ return ExchangeTosStatus.Accepted;
+ }
+ return ExchangeTosStatus.Changed;
+}
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index d7627e6cf..1520dfc0a 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -83,6 +83,7 @@ import {
} from "../errors.js";
import { InternalWalletState } from "../internal-wallet-state.js";
import {
+ getExchangeTosStatus,
makeCoinAvailable,
runOperationWithErrorReporting,
} from "../operations/common.js";
@@ -1359,26 +1360,20 @@ export async function getWithdrawalDetailsForUri(
.runReadOnly(async (tx) => {
const exchangeRecords = await tx.exchanges.iter().toArray();
for (const r of exchangeRecords) {
- const details = await ws.exchangeOps.getExchangeDetails(tx, r.baseUrl);
+ const exchangeDetails = await ws.exchangeOps.getExchangeDetails(tx, r.baseUrl);
const denominations = await tx.denominations.indexes.byExchangeBaseUrl
.iter(r.baseUrl)
.toArray();
- if (details && denominations) {
+ if (exchangeDetails && denominations) {
const tosRecord = await tx.exchangeTos.get([
- details.exchangeBaseUrl,
- details.tosCurrentEtag,
+ exchangeDetails.exchangeBaseUrl,
+ exchangeDetails.tosCurrentEtag,
]);
exchanges.push({
- exchangeBaseUrl: details.exchangeBaseUrl,
- currency: details.currency,
- // FIXME: We probably don't want to include the full ToS here!
- tos: {
- acceptedVersion: details.tosAccepted?.etag,
- currentVersion: details.tosCurrentEtag,
- contentType: tosRecord?.termsOfServiceContentType ?? "",
- content: tosRecord?.termsOfServiceText ?? "",
- },
- paytoUris: details.wireInfo.accounts.map((x) => x.payto_uri),
+ exchangeBaseUrl: exchangeDetails.exchangeBaseUrl,
+ currency: exchangeDetails.currency,
+ paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
+ tosStatus: getExchangeTosStatus(exchangeDetails),
});
}
}
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index ef41c5101..3c7194059 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -146,7 +146,7 @@ import {
} from "./operations/backup/index.js";
import { setWalletDeviceId } from "./operations/backup/state.js";
import { getBalances } from "./operations/balance.js";
-import { runOperationWithErrorReporting } from "./operations/common.js";
+import { getExchangeTosStatus, runOperationWithErrorReporting } from "./operations/common.js";
import {
createDepositGroup,
getFeeForDeposit,
@@ -503,6 +503,7 @@ async function getExchangeTos(
currentEtag,
content,
contentType,
+ tosStatus: getExchangeTosStatus(exchangeDetails),
};
}
@@ -519,6 +520,7 @@ async function getExchangeTos(
currentEtag,
content,
contentType,
+ tosStatus: getExchangeTosStatus(exchangeDetails),
};
}
@@ -529,6 +531,7 @@ async function getExchangeTos(
currentEtag: tosDownload.tosEtag,
content: tosDownload.tosText,
contentType: tosDownload.tosContentType,
+ tosStatus: getExchangeTosStatus(exchangeDetails),
};
}
@@ -665,7 +668,7 @@ async function getExchanges(
exchanges.push({
exchangeBaseUrl: r.baseUrl,
currency,
- tos,
+ tosStatus: getExchangeTosStatus(exchangeDetails),
paytoUris: exchangeDetails.wireInfo.accounts.map((x) => x.payto_uri),
});
}