summaryrefslogtreecommitdiff
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.ts64
1 files changed, 51 insertions, 13 deletions
diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts
index c46344313..8437d2d0b 100644
--- a/packages/taler-wallet-core/src/operations/refresh.ts
+++ b/packages/taler-wallet-core/src/operations/refresh.ts
@@ -96,7 +96,7 @@ import {
PendingTaskType,
WalletConfig,
} from "../index.js";
-import { constructTransactionIdentifier } from "./transactions.js";
+import { constructTransactionIdentifier, notifyTransition } from "./transactions.js";
const logger = new Logger("refresh.ts");
@@ -158,7 +158,7 @@ function updateGroupStatus(rg: RefreshGroupRecord): void {
if (allDone) {
if (anyFrozen) {
rg.timestampFinished = TalerPreciseTimestamp.now();
- rg.operationStatus = RefreshOperationStatus.FinishedWithError;
+ rg.operationStatus = RefreshOperationStatus.Failed;
} else {
rg.timestampFinished = TalerPreciseTimestamp.now();
rg.operationStatus = RefreshOperationStatus.Finished;
@@ -1189,7 +1189,7 @@ export function computeRefreshTransactionState(
return {
major: TransactionMajorState.Done,
};
- case RefreshOperationStatus.FinishedWithError:
+ case RefreshOperationStatus.Failed:
return {
major: TransactionMajorState.Failed,
};
@@ -1261,7 +1261,7 @@ export async function resumeRefreshGroup(
tag: TransactionType.Refresh,
refreshGroupId,
});
- let res = await ws.db
+ const transitionInfo = await ws.db
.mktx((x) => [x.refreshGroups])
.runReadWrite(async (tx) => {
const dg = await tx.refreshGroups.get(refreshGroupId);
@@ -1289,19 +1289,57 @@ export async function resumeRefreshGroup(
return undefined;
});
ws.workAvailable.trigger();
- if (res) {
- ws.notify({
- type: NotificationType.TransactionStateTransition,
- transactionId,
- oldTxState: res.oldTxState,
- newTxState: res.newTxState,
- });
- }
+ notifyTransition(ws, transactionId, transitionInfo);
+}
+
+export async function cancelAbortingRefreshGroup(
+ ws: InternalWalletState,
+ refreshGroupId: string,
+): Promise<void> {
+ throw Error("action cancel-aborting not allowed on refreshes");
}
export async function abortRefreshGroup(
ws: InternalWalletState,
refreshGroupId: string,
): Promise<void> {
- throw Error("can't abort refresh groups.");
+ const transactionId = constructTransactionIdentifier({
+ tag: TransactionType.Refresh,
+ refreshGroupId,
+ });
+ const transitionInfo = await ws.db
+ .mktx((x) => [x.refreshGroups])
+ .runReadWrite(async (tx) => {
+ const dg = await tx.refreshGroups.get(refreshGroupId);
+ if (!dg) {
+ logger.warn(
+ `can't resume refresh group, refreshGroupId=${refreshGroupId} not found`,
+ );
+ return;
+ }
+ const oldState = computeRefreshTransactionState(dg);
+ let newStatus: RefreshOperationStatus | undefined;
+ switch (dg.operationStatus) {
+ case RefreshOperationStatus.Finished:
+ break;;
+ case RefreshOperationStatus.Pending:
+ case RefreshOperationStatus.Suspended:
+ newStatus = RefreshOperationStatus.Failed;
+ break;
+ case RefreshOperationStatus.Failed:
+ break;
+ default:
+ assertUnreachable(dg.operationStatus);
+ }
+ if (newStatus) {
+ dg.operationStatus = newStatus;
+ await tx.refreshGroups.put(dg);
+ }
+ return {
+ oldTxState: oldState,
+ newTxState: computeRefreshTransactionState(dg),
+ };
+ });
+ ws.workAvailable.trigger();
+ notifyTransition(ws, transactionId, transitionInfo);
}