aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/refresh.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/operations/refresh.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/refresh.ts44
1 files changed, 36 insertions, 8 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts
index 8437d2d0b..c2cf13857 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -50,6 +50,7 @@ import {
TalerErrorDetail,
TalerPreciseTimestamp,
TalerProtocolTimestamp,
+ TransactionAction,
TransactionMajorState,
TransactionState,
TransactionType,
@@ -96,7 +97,10 @@ import {
PendingTaskType,
WalletConfig,
} from "../index.js";
-import { constructTransactionIdentifier, notifyTransition } from "./transactions.js";
+import {
+ constructTransactionIdentifier,
+ notifyTransition,
+} from "./transactions.js";
const logger = new Logger("refresh.ts");
@@ -1076,8 +1080,12 @@ export async function createRefreshGroup(
* Timestamp after which the wallet would do the next check for an auto-refresh.
*/
function getAutoRefreshCheckThreshold(d: DenominationRecord): AbsoluteTime {
- const expireWithdraw = AbsoluteTime.fromProtocolTimestamp(d.stampExpireWithdraw);
- const expireDeposit = AbsoluteTime.fromProtocolTimestamp(d.stampExpireDeposit);
+ const expireWithdraw = AbsoluteTime.fromProtocolTimestamp(
+ d.stampExpireWithdraw,
+ );
+ const expireDeposit = AbsoluteTime.fromProtocolTimestamp(
+ d.stampExpireDeposit,
+ );
const delta = AbsoluteTime.difference(expireWithdraw, expireDeposit);
const deltaDiv = durationMul(delta, 0.75);
return AbsoluteTime.addDuration(expireWithdraw, deltaDiv);
@@ -1087,8 +1095,12 @@ function getAutoRefreshCheckThreshold(d: DenominationRecord): AbsoluteTime {
* Timestamp after which the wallet would do an auto-refresh.
*/
function getAutoRefreshExecuteThreshold(d: DenominationRecord): AbsoluteTime {
- const expireWithdraw = AbsoluteTime.fromProtocolTimestamp(d.stampExpireWithdraw);
- const expireDeposit = AbsoluteTime.fromProtocolTimestamp(d.stampExpireDeposit);
+ const expireWithdraw = AbsoluteTime.fromProtocolTimestamp(
+ d.stampExpireWithdraw,
+ );
+ const expireDeposit = AbsoluteTime.fromProtocolTimestamp(
+ d.stampExpireDeposit,
+ );
const delta = AbsoluteTime.difference(expireWithdraw, expireDeposit);
const deltaDiv = durationMul(delta, 0.5);
return AbsoluteTime.addDuration(expireWithdraw, deltaDiv);
@@ -1175,7 +1187,8 @@ export async function autoRefresh(
logger.info(
`next refresh check at ${AbsoluteTime.toIsoString(minCheckThreshold)}`,
);
- exchange.nextRefreshCheck = AbsoluteTime.toPreciseTimestamp(minCheckThreshold);
+ exchange.nextRefreshCheck =
+ AbsoluteTime.toPreciseTimestamp(minCheckThreshold);
await tx.exchanges.put(exchange);
});
return OperationAttemptResult.finishedEmpty();
@@ -1204,6 +1217,21 @@ export function computeRefreshTransactionState(
}
}
+export function computeRefreshTransactionActions(
+ rg: RefreshGroupRecord,
+): TransactionAction[] {
+ switch (rg.operationStatus) {
+ case RefreshOperationStatus.Finished:
+ return [TransactionAction.Delete];
+ case RefreshOperationStatus.Failed:
+ return [TransactionAction.Delete];
+ case RefreshOperationStatus.Pending:
+ return [TransactionAction.Suspend, TransactionAction.Fail];
+ case RefreshOperationStatus.Suspended:
+ return [TransactionAction.Resume, TransactionAction.Fail];
+ }
+}
+
export async function suspendRefreshGroup(
ws: InternalWalletState,
refreshGroupId: string,
@@ -1292,7 +1320,7 @@ export async function resumeRefreshGroup(
notifyTransition(ws, transactionId, transitionInfo);
}
-export async function cancelAbortingRefreshGroup(
+export async function failRefreshGroup(
ws: InternalWalletState,
refreshGroupId: string,
): Promise<void> {
@@ -1321,7 +1349,7 @@ export async function abortRefreshGroup(
let newStatus: RefreshOperationStatus | undefined;
switch (dg.operationStatus) {
case RefreshOperationStatus.Finished:
- break;;
+ break;
case RefreshOperationStatus.Pending:
case RefreshOperationStatus.Suspended:
newStatus = RefreshOperationStatus.Failed;