commit 76e3a3fc04bacd8a491098b827e026bd4009497b
parent 9cb267ecea87eddd7c420cd5115e74e45bfdf056
Author: Florian Dold <dold@taler.net>
Date: Wed, 22 Jul 2026 10:45:12 +0200
wallet: reject an empty coin selection when computing the payment cost
The zero seed that was meant to give the sum a currency for an empty selection
read the first coin of that very selection.
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/packages/taler-wallet-core/src/pay-peer-common.ts b/packages/taler-wallet-core/src/pay-peer-common.ts
@@ -73,6 +73,10 @@ export async function getTotalPeerPaymentCostInTx(
tx: WalletDbTransaction,
pcs: SelectedProspectiveCoin[],
): Promise<AmountJson> {
+ if (pcs.length === 0) {
+ // Without a coin there is no currency to express the cost in.
+ throw Error("can't calculate payment cost, no coin selected");
+ }
const costs: AmountJson[] = [];
for (let i = 0; i < pcs.length; i++) {
const denomInfo = await getDenomInfo(
@@ -96,8 +100,7 @@ export async function getTotalPeerPaymentCostInTx(
costs.push(Amounts.parseOrThrow(pcs[i].contribution));
costs.push(refreshCost);
}
- const zero = Amounts.zeroOfAmount(pcs[0].contribution);
- return Amounts.sum([zero, ...costs]).amount;
+ return Amounts.sum(costs).amount;
}
export async function getTotalPeerPaymentCost(