summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/pay-peer-common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer-common.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/pay-peer-common.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/packages/taler-wallet-core/src/operations/pay-peer-common.ts b/packages/taler-wallet-core/src/operations/pay-peer-common.ts
index 6d425289d..aa9e0c858 100644
--- a/packages/taler-wallet-core/src/operations/pay-peer-common.ts
+++ b/packages/taler-wallet-core/src/operations/pay-peer-common.ts
@@ -88,6 +88,7 @@ export async function getTotalPeerPaymentCost(
ws: InternalWalletState,
pcs: SelectedPeerCoin[],
): Promise<AmountJson> {
+ const currency = Amounts.currencyOf(pcs[0].contribution);
return ws.db
.mktx((x) => [x.coins, x.denominations])
.runReadOnly(async (tx) => {
@@ -97,22 +98,29 @@ export async function getTotalPeerPaymentCost(
if (!coin) {
throw Error("can't calculate payment cost, coin not found");
}
- const denom = await tx.denominations.get([
+ const denomInfo = await ws.getDenomInfo(
+ ws,
+ tx,
coin.exchangeBaseUrl,
coin.denomPubHash,
- ]);
- if (!denom) {
+ );
+ if (!denomInfo) {
throw Error(
"can't calculate payment cost, denomination for coin not found",
);
}
- const allDenoms = await tx.denominations.indexes.byExchangeBaseUrl
- .iter(coin.exchangeBaseUrl)
- .filter((x) => Amounts.isSameCurrency(x.value, pcs[i].contribution));
- const amountLeft = Amounts.sub(denom.value, pcs[i].contribution).amount;
+ const allDenoms = (
+ await tx.denominations.indexes.byExchangeBaseUrl.getAll(
+ coin.exchangeBaseUrl,
+ )
+ ).filter((x) => x.currency === currency);
+ const amountLeft = Amounts.sub(
+ denomInfo.value,
+ pcs[i].contribution,
+ ).amount;
const refreshCost = getTotalRefreshCost(
allDenoms,
- DenominationRecord.toDenomInfo(denom),
+ denomInfo,
amountLeft,
ws.config.testing.denomselAllowLate,
);