summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util/coinSelection.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-09-08 13:33:21 +0200
committerFlorian Dold <florian@dold.me>2023-09-08 13:33:21 +0200
commit4898f50db777a68cd2ddd0c1e323ef55033f4af7 (patch)
tree82b241ffc35413c6653d781e381f3d47f7ffd544 /packages/taler-wallet-core/src/util/coinSelection.ts
parent2ae952cdfa8f38a650be8e4438c21bace2f24c19 (diff)
downloadwallet-core-4898f50db777a68cd2ddd0c1e323ef55033f4af7.tar.gz
wallet-core-4898f50db777a68cd2ddd0c1e323ef55033f4af7.tar.bz2
wallet-core-4898f50db777a68cd2ddd0c1e323ef55033f4af7.zip
wallet-core: more DB cleanup
Diffstat (limited to 'packages/taler-wallet-core/src/util/coinSelection.ts')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts30
1 files changed, 7 insertions, 23 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index ce9fec186..ef2f85789 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -699,25 +699,17 @@ export function selectWithdrawalDenominations(
let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency);
denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate));
- denoms.sort((d1, d2) =>
- Amounts.cmp(
- DenominationRecord.getValue(d2),
- DenominationRecord.getValue(d1),
- ),
- );
+ denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value));
for (const d of denoms) {
- const cost = Amounts.add(
- DenominationRecord.getValue(d),
- d.fees.feeWithdraw,
- ).amount;
+ const cost = Amounts.add(d.value, d.fees.feeWithdraw).amount;
const res = Amounts.divmod(remaining, cost);
const count = res.quotient;
remaining = Amounts.sub(remaining, Amounts.mult(cost, count).amount).amount;
if (count > 0) {
totalCoinValue = Amounts.add(
totalCoinValue,
- Amounts.mult(DenominationRecord.getValue(d), count).amount,
+ Amounts.mult(d.value, count).amount,
).amount;
totalWithdrawCost = Amounts.add(
totalWithdrawCost,
@@ -766,30 +758,22 @@ export function selectForcedWithdrawalDenominations(
let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency);
denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate));
- denoms.sort((d1, d2) =>
- Amounts.cmp(
- DenominationRecord.getValue(d2),
- DenominationRecord.getValue(d1),
- ),
- );
+ denoms.sort((d1, d2) => Amounts.cmp(d2.value, d1.value));
for (const fds of forcedDenomSel.denoms) {
const count = fds.count;
const denom = denoms.find((x) => {
- return Amounts.cmp(DenominationRecord.getValue(x), fds.value) == 0;
+ return Amounts.cmp(x.value, fds.value) == 0;
});
if (!denom) {
throw Error(
`unable to find denom for forced selection (value ${fds.value})`,
);
}
- const cost = Amounts.add(
- DenominationRecord.getValue(denom),
- denom.fees.feeWithdraw,
- ).amount;
+ const cost = Amounts.add(denom.value, denom.fees.feeWithdraw).amount;
totalCoinValue = Amounts.add(
totalCoinValue,
- Amounts.mult(DenominationRecord.getValue(denom), count).amount,
+ Amounts.mult(denom.value, count).amount,
).amount;
totalWithdrawCost = Amounts.add(
totalWithdrawCost,