aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util/coinSelection.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/util/coinSelection.ts')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts62
1 files changed, 23 insertions, 39 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index daba2ead5..ef2f85789 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -588,22 +588,22 @@ async function selectPayMerchantCandidates(
for (const acc of exchangeDetails.wireInfo.accounts) {
const pp = parsePaytoUri(acc.payto_uri);
checkLogicInvariant(!!pp);
- if (pp.targetType === req.wireMethod) {
- // also check that wire method is supported now
- const wireFeeStr = exchangeDetails.wireInfo.feesForType[
- req.wireMethod
- ]?.find((x) => {
- return AbsoluteTime.isBetween(
- AbsoluteTime.now(),
- AbsoluteTime.fromProtocolTimestamp(x.startStamp),
- AbsoluteTime.fromProtocolTimestamp(x.endStamp),
- );
- })?.wireFee;
- if (wireFeeStr) {
- wireMethodFee = wireFeeStr;
- }
- break;
+ if (pp.targetType !== req.wireMethod) {
+ continue;
+ }
+ const wireFeeStr = exchangeDetails.wireInfo.feesForType[
+ req.wireMethod
+ ]?.find((x) => {
+ return AbsoluteTime.isBetween(
+ AbsoluteTime.now(),
+ AbsoluteTime.fromProtocolTimestamp(x.startStamp),
+ AbsoluteTime.fromProtocolTimestamp(x.endStamp),
+ );
+ })?.wireFee;
+ if (wireFeeStr) {
+ wireMethodFee = wireFeeStr;
}
+ break;
}
if (!wireMethodFee) {
break;
@@ -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,
@@ -1002,7 +986,7 @@ export async function selectPeerCoins(
x.coinAvailability,
x.denominations,
x.refreshGroups,
- x.peerPushPaymentInitiations,
+ x.peerPushDebit,
])
.runReadWrite(async (tx) => {
const exchanges = await tx.exchanges.iter().toArray();