aboutsummaryrefslogtreecommitdiff
path: root/src/operations/refresh.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-05-11 18:03:25 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-05-11 18:03:25 +0530
commit5d6192b0cd356f7e56fa8d6193a2e74233a52f4b (patch)
tree0360ba1d39e6ff081e25045652f457faca8cb879 /src/operations/refresh.ts
parent7e947ca2cdd8e66ea49822acbad81e7d35289c0a (diff)
downloadwallet-core-5d6192b0cd356f7e56fa8d6193a2e74233a52f4b.tar.xz
make planchet management during withdrawal O(n) instead of O(n^2)
Diffstat (limited to 'src/operations/refresh.ts')
-rw-r--r--src/operations/refresh.ts6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/operations/refresh.ts b/src/operations/refresh.ts
index 924769334..56d18f28b 100644
--- a/src/operations/refresh.ts
+++ b/src/operations/refresh.ts
@@ -67,7 +67,9 @@ export function getTotalRefreshCost(
const withdrawDenoms = getWithdrawDenomList(withdrawAmount, denoms);
const resultingAmount = Amounts.add(
Amounts.getZero(withdrawAmount.currency),
- ...withdrawDenoms.map((d) => d.value),
+ ...withdrawDenoms.selectedDenoms.map(
+ (d) => Amounts.mult(d.denom.value, d.count).amount,
+ ),
).amount;
const totalCost = Amounts.sub(amountLeft, resultingAmount).amount;
logger.trace(
@@ -130,7 +132,7 @@ async function refreshCreateSession(
const newCoinDenoms = getWithdrawDenomList(availableAmount, availableDenoms);
- if (newCoinDenoms.length === 0) {
+ if (newCoinDenoms.selectedDenoms.length === 0) {
logger.trace(
`not refreshing, available amount ${amountToPretty(
availableAmount,