aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/coinSelection.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-03-27 19:03:26 +0100
committerFlorian Dold <florian@dold.me>2024-03-27 19:03:26 +0100
commit30e5b7f6bf6fe7810f3fe0778e203b0e54d34b40 (patch)
tree8d640b1b4713d103e1a86ce49194ddd1ee280e4d /packages/taler-wallet-core/src/coinSelection.ts
parentdac6a052b508cfd208cbf4aa7cb5efc44d85c82a (diff)
downloadwallet-core-30e5b7f6bf6fe7810f3fe0778e203b0e54d34b40.tar.xz
wallet-core: report more info about (missing) fees
Diffstat (limited to 'packages/taler-wallet-core/src/coinSelection.ts')
-rw-r--r--packages/taler-wallet-core/src/coinSelection.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/coinSelection.ts b/packages/taler-wallet-core/src/coinSelection.ts
index 7c22f63db..cf323e586 100644
--- a/packages/taler-wallet-core/src/coinSelection.ts
+++ b/packages/taler-wallet-core/src/coinSelection.ts
@@ -36,6 +36,7 @@ import {
checkLogicInvariant,
CoinStatus,
DenominationInfo,
+ ExchangeGlobalFees,
ForcedCoinSel,
InternationalizedString,
j2s,
@@ -400,6 +401,16 @@ export async function reportInsufficientBalanceDetails(
if (!exch.detailsPointer) {
continue;
}
+ let missingGlobalFees = false;
+ const exchWire = await getExchangeWireDetailsInTx(tx, exch.baseUrl);
+ if (!exchWire) {
+ missingGlobalFees = true;
+ } else {
+ const globalFees = getGlobalFees(exchWire);
+ if (!globalFees) {
+ missingGlobalFees = true;
+ }
+ }
const exchDet = await getPaymentBalanceDetailsInTx(wex, tx, {
restrictExchanges: {
exchanges: [
@@ -431,6 +442,7 @@ export async function reportInsufficientBalanceDetails(
maxEffectiveSpendAmount: Amounts.stringify(
exchDet.maxEffectiveSpendAmount,
),
+ missingGlobalFees,
};
}
@@ -900,6 +912,24 @@ export function emptyTallyForPeerPayment(
};
}
+function getGlobalFees(
+ wireDetails: ExchangeWireDetails,
+): ExchangeGlobalFees | undefined {
+ const now = AbsoluteTime.now();
+ for (let gf of wireDetails.globalFees) {
+ const isActive = AbsoluteTime.isBetween(
+ now,
+ AbsoluteTime.fromProtocolTimestamp(gf.startDate),
+ AbsoluteTime.fromProtocolTimestamp(gf.endDate),
+ );
+ if (!isActive) {
+ continue;
+ }
+ return gf;
+ }
+ return undefined;
+}
+
export async function selectPeerCoins(
wex: WalletExecutionContext,
req: PeerCoinSelectionRequest,
@@ -928,6 +958,14 @@ export async function selectPeerCoins(
if (exch.detailsPointer?.currency !== currency) {
continue;
}
+ const exchWire = await getExchangeWireDetailsInTx(tx, exch.baseUrl);
+ if (!exchWire) {
+ continue;
+ }
+ const globalFees = getGlobalFees(exchWire);
+ if (!globalFees) {
+ continue;
+ }
const candidatesRes = await selectPayCandidates(wex, tx, {
instructedAmount,
restrictExchanges: {