commit 1c747ae004fcaa947a62cd23b77857161f7ff03e
parent 5d1b0df8a44c79cac46d40ff157f0150a668d6f4
Author: Florian Dold <florian.dold@gmail.com>
Date: Fri, 27 Mar 2020 15:20:02 +0530
don't rip off the merchant via our coin selection
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git 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;