From a1c5f00aedb75e5e2deb6b12c3cfb06eefb355e4 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 6 Dec 2022 19:41:32 +0100 Subject: wallet: fix p2p coin selection The p2p coin selection didn't work properly when all available denoms are needed. Thanks to Florian Jung for finding the issue and suggesting a fix. --- packages/taler-wallet-core/src/operations/pay-peer.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'packages/taler-wallet-core') diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts index f31a7f37c..cc859f243 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer.ts @@ -191,12 +191,7 @@ export async function selectPeerCoins( }[] = []; for (const coin of coinInfos) { if (Amounts.cmp(amountAcc, instructedAmount) >= 0) { - const res: PeerCoinSelection = { - exchangeBaseUrl: exch.baseUrl, - coins: resCoins, - depositFees: depositFeesAcc, - }; - return res; + break; } const gap = Amounts.add( coin.feeDeposit, @@ -217,6 +212,14 @@ export async function selectPeerCoins( ageCommitmentProof: coin.ageCommitmentProof, }); } + if (Amounts.cmp(amountAcc, instructedAmount) >= 0) { + const res: PeerCoinSelection = { + exchangeBaseUrl: exch.baseUrl, + coins: resCoins, + depositFees: depositFeesAcc, + }; + return res; + } continue; } return undefined; -- cgit v1.2.3