aboutsummaryrefslogtreecommitdiff
path: root/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-27 15:20:02 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-27 15:20:02 +0530
commit1c747ae004fcaa947a62cd23b77857161f7ff03e (patch)
treef479d04c85eb5c711802df91be9b8f828e891476 /src/operations
parent5d1b0df8a44c79cac46d40ff157f0150a668d6f4 (diff)
don't rip off the merchant via our coin selection
Diffstat (limited to 'src/operations')
-rw-r--r--src/operations/pay.ts10
1 files changed, 8 insertions, 2 deletions
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;