From d483a3f5574355ed9c43eb6ddea59e5734323cf0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 19 Apr 2023 12:42:47 -0300 Subject: fix #7704 --- .../taler-wallet-core/src/util/coinSelection.ts | 12 ++++++-- packages/taler-wallet-core/src/util/debugFlags.ts | 32 ---------------------- .../taler-wallet-core/src/util/denominations.ts | 9 ++++-- 3 files changed, 15 insertions(+), 38 deletions(-) delete mode 100644 packages/taler-wallet-core/src/util/debugFlags.ts (limited to 'packages/taler-wallet-core/src/util') diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index 176d636fc..3b986d72b 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -48,7 +48,11 @@ import { AllowedExchangeInfo, DenominationRecord, } from "../db.js"; -import { getExchangeDetails, isWithdrawableDenom } from "../index.js"; +import { + getExchangeDetails, + isWithdrawableDenom, + WalletConfig, +} from "../index.js"; import { InternalWalletState } from "../internal-wallet-state.js"; import { getMerchantPaymentBalanceDetails } from "../operations/balance.js"; import { checkDbInvariant, checkLogicInvariant } from "./invariants.js"; @@ -664,6 +668,7 @@ export async function selectCandidates( export function selectWithdrawalDenominations( amountAvailable: AmountJson, denoms: DenominationRecord[], + denomselAllowLate: boolean = false, ): DenomSelectionState { let remaining = Amounts.copy(amountAvailable); @@ -675,7 +680,7 @@ export function selectWithdrawalDenominations( let totalCoinValue = Amounts.zeroOfCurrency(amountAvailable.currency); let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency); - denoms = denoms.filter(isWithdrawableDenom); + denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate)); denoms.sort((d1, d2) => Amounts.cmp( DenominationRecord.getValue(d2), @@ -737,6 +742,7 @@ export function selectForcedWithdrawalDenominations( amountAvailable: AmountJson, denoms: DenominationRecord[], forcedDenomSel: ForcedDenomSel, + denomselAllowLate: boolean, ): DenomSelectionState { const selectedDenoms: { count: number; @@ -746,7 +752,7 @@ export function selectForcedWithdrawalDenominations( let totalCoinValue = Amounts.zeroOfCurrency(amountAvailable.currency); let totalWithdrawCost = Amounts.zeroOfCurrency(amountAvailable.currency); - denoms = denoms.filter(isWithdrawableDenom); + denoms = denoms.filter((d) => isWithdrawableDenom(d, denomselAllowLate)); denoms.sort((d1, d2) => Amounts.cmp( DenominationRecord.getValue(d2), diff --git a/packages/taler-wallet-core/src/util/debugFlags.ts b/packages/taler-wallet-core/src/util/debugFlags.ts deleted file mode 100644 index cea249d27..000000000 --- a/packages/taler-wallet-core/src/util/debugFlags.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is part of GNU Taler - (C) 2021 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see - */ - -/** - * Debug flags for wallet-core. - * - * @author Florian Dold - */ - -export interface WalletCoreDebugFlags { - /** - * Allow withdrawal of denominations even though they are about to expire. - */ - denomselAllowLate: boolean; -} - -export const walletCoreDebugFlags: WalletCoreDebugFlags = { - denomselAllowLate: false, -}; diff --git a/packages/taler-wallet-core/src/util/denominations.ts b/packages/taler-wallet-core/src/util/denominations.ts index fb766e96a..5cc57bdab 100644 --- a/packages/taler-wallet-core/src/util/denominations.ts +++ b/packages/taler-wallet-core/src/util/denominations.ts @@ -29,7 +29,7 @@ import { WireFee, } from "@gnu-taler/taler-util"; import { DenominationRecord } from "../db.js"; -import { walletCoreDebugFlags } from "./debugFlags.js"; +import { WalletConfig } from "../index.js"; /** * Given a list of denominations with the same value and same period of time: @@ -452,13 +452,16 @@ export function createTimeline( * Check if a denom is withdrawable based on the expiration time, * revocation and offered state. */ -export function isWithdrawableDenom(d: DenominationRecord): boolean { +export function isWithdrawableDenom( + d: DenominationRecord, + denomselAllowLate?: boolean, +): boolean { const now = AbsoluteTime.now(); const start = AbsoluteTime.fromTimestamp(d.stampStart); const withdrawExpire = AbsoluteTime.fromTimestamp(d.stampExpireWithdraw); const started = AbsoluteTime.cmp(now, start) >= 0; let lastPossibleWithdraw: AbsoluteTime; - if (walletCoreDebugFlags.denomselAllowLate) { + if (denomselAllowLate) { lastPossibleWithdraw = start; } else { lastPossibleWithdraw = AbsoluteTime.subtractDuraction( -- cgit v1.2.3