diff options
author | Sebastian <sebasjm@gmail.com> | 2023-03-31 12:27:05 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-03-31 12:27:17 -0300 |
commit | b0cc65e17f2348f46ae1c9b88b69abae11266899 (patch) | |
tree | 41a8b4a14c4fe99eea8e285d43b01f972ea7226b /packages/taler-wallet-core/src/util/denominations.ts | |
parent | 7ebcb30b9f9a573a04dc19a99df739aefb677c15 (diff) | |
download | wallet-core-b0cc65e17f2348f46ae1c9b88b69abae11266899.tar.xz |
move coin selection function to coinSelection.ts and added a test placeholder, and some fixes:
* selectCandidates was not save wire fee
* selectCandidates show check wire fee time range
Diffstat (limited to 'packages/taler-wallet-core/src/util/denominations.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/denominations.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/denominations.ts b/packages/taler-wallet-core/src/util/denominations.ts index ef35fe198..fb766e96a 100644 --- a/packages/taler-wallet-core/src/util/denominations.ts +++ b/packages/taler-wallet-core/src/util/denominations.ts @@ -20,12 +20,16 @@ import { Amounts, AmountString, DenominationInfo, + Duration, + durationFromSpec, FeeDescription, FeeDescriptionPair, TalerProtocolTimestamp, TimePoint, WireFee, } from "@gnu-taler/taler-util"; +import { DenominationRecord } from "../db.js"; +import { walletCoreDebugFlags } from "./debugFlags.js"; /** * Given a list of denominations with the same value and same period of time: @@ -443,3 +447,26 @@ export function createTimeline<Type extends object>( return result; }, [] as FeeDescription[]); } + +/** + * Check if a denom is withdrawable based on the expiration time, + * revocation and offered state. + */ +export function isWithdrawableDenom(d: DenominationRecord): 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) { + lastPossibleWithdraw = start; + } else { + lastPossibleWithdraw = AbsoluteTime.subtractDuraction( + withdrawExpire, + durationFromSpec({ minutes: 5 }), + ); + } + const remaining = Duration.getRemaining(lastPossibleWithdraw, now); + const stillOkay = remaining.d_ms !== 0; + return started && stillOkay && !d.isRevoked && d.isOffered; +} |