From 1c747ae004fcaa947a62cd23b77857161f7ff03e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 27 Mar 2020 15:20:02 +0530 Subject: don't rip off the merchant via our coin selection --- src/operations/pay.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/operations/pay.ts') diff --git a/src/operations/pay.ts b/src/operations/pay.ts index 9a8017e4e..f3468ae46 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -234,11 +234,17 @@ export function selectPayCoins( ).amount; if (Amounts.cmp(amountActualAvailable, amountPayRemaining) > 0) { - // Partial spending + // Partial spending, as the coin is worth more than the remaining + // amount to pay. coinSpend = Amounts.add(amountPayRemaining, depositFeeSpend).amount; + // Make sure we contribute at least the deposit fee, otherwise + // contributing this coin would cause a loss for the merchant. + if (Amounts.cmp(coinSpend, aci.feeDeposit) < 0) { + coinSpend = aci.feeDeposit; + } amountPayRemaining = Amounts.getZero(currency); } else { - // Spend the full remaining amount + // Spend the full remaining amount on the coin coinSpend = aci.availableAmount; amountPayRemaining = Amounts.add(amountPayRemaining, depositFeeSpend) .amount; -- cgit v1.2.3