From 6b28885f0bfaf4ae4d6073db360f67088bda7a17 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 20 Feb 2023 14:40:26 +0100 Subject: wallet-core: stubs for suspend/resume tx --- packages/taler-util/src/wallet-types.ts | 20 +++++++++++++++++++ .../src/operations/transactions.ts | 19 ++++++++++++++++++ packages/taler-wallet-core/src/wallet-api-types.ts | 23 ++++++++++++++++++++++ packages/taler-wallet-core/src/wallet.ts | 14 +++++++++++++ 4 files changed, 76 insertions(+) diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index aff83da14..338124d08 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1649,6 +1649,26 @@ export const codecForAcceptTipRequest = (): Codec => .property("walletTipId", codecForString()) .build("AcceptTipRequest"); +export interface SuspendTransactionRequest { + transactionId: string; +} + +export const codecForSuspendTransaction = + (): Codec => + buildCodecForObject() + .property("transactionId", codecForString()) + .build("SuspendTransactionRequest"); + +export interface ResumeTransactionRequest { + transactionId: string; +} + +export const codecForResumeTransaction = + (): Codec => + buildCodecForObject() + .property("transactionId", codecForString()) + .build("ResumeTransactionRequest"); + export interface AbortTransactionRequest { transactionId: string; diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 9ee1c1e74..c03d2aa3d 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -1404,6 +1404,25 @@ export async function retryTransaction( } } +/** + * Suspends a pending transaction, stopping any associated network activities, + * but with a chance of trying again at a later time. This could be useful if + * a user needs to save battery power or bandwidth and an operation is expected + * to take longer (such as a backup, recovery or very large withdrawal operation). + */ +export async function suspendTransaction( + ws: InternalWalletState, + transactionId: string, +): Promise {} + +/** + * Resume a suspended transaction. + */ +export async function resumeTransaction( + ws: InternalWalletState, + transactionId: string, +): Promise {} + /** * Permanently delete a transaction based on the transaction ID. */ diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 904462c36..dc62f0c0f 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -157,6 +157,8 @@ export enum WalletApiOperation { GetExchangeDetailedInfo = "getExchangeDetailedInfo", RetryPendingNow = "retryPendingNow", AbortTransaction = "abortTransaction", + SuspendTransaction = "suspendTransaction", + ResumeTransaction = "resumeTransaction", ConfirmPay = "confirmPay", DumpCoins = "dumpCoins", SetCoinSuspended = "setCoinSuspended", @@ -359,6 +361,25 @@ export type AbortTransactionOp = { response: EmptyObject; }; +/** + * Suspend a transaction + */ +export type SuspendTransactionOp = { + op: WalletApiOperation.SuspendTransaction; + request: AbortTransactionRequest; + response: EmptyObject; +}; + + +/** + * Resume a transaction + */ +export type ResumeTransactionOp = { + op: WalletApiOperation.ResumeTransaction; + request: AbortTransactionRequest; + response: EmptyObject; +}; + /** * Check for a refund based on a taler://refund URI. */ @@ -852,6 +873,8 @@ export type WalletOperations = { [WalletApiOperation.WithdrawTestkudos]: WithdrawTestkudosOp; [WalletApiOperation.ConfirmPay]: ConfirmPayOp; [WalletApiOperation.AbortTransaction]: AbortTransactionOp; + [WalletApiOperation.SuspendTransaction]: SuspendTransactionOp; + [WalletApiOperation.ResumeTransaction]: ResumeTransactionOp; [WalletApiOperation.GetBalances]: GetBalancesOp; [WalletApiOperation.GetBalanceDetail]: GetBalancesDetailOp; [WalletApiOperation.GetTransactions]: GetTransactionsOp; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 6f775142b..a036be86c 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -107,6 +107,8 @@ import { URL, WalletCoreVersion, WalletNotification, + codecForSuspendTransaction, + codecForResumeTransaction, } from "@gnu-taler/taler-util"; import { TalerCryptoInterface } from "./crypto/cryptoImplementation.js"; import { @@ -230,7 +232,9 @@ import { deleteTransaction, getTransactionById, getTransactions, + resumeTransaction, retryTransaction, + suspendTransaction, } from "./operations/transactions.js"; import { acceptWithdrawalFromUri, @@ -1224,6 +1228,16 @@ async function dispatchRequestInternal( await abortTransaction(ws, req.transactionId, req.forceImmediateAbort); return {}; } + case WalletApiOperation.SuspendTransaction: { + const req = codecForSuspendTransaction().decode(payload); + await suspendTransaction(ws, req.transactionId); + return {}; + } + case WalletApiOperation.ResumeTransaction: { + const req = codecForResumeTransaction().decode(payload); + await resumeTransaction(ws, req.transactionId); + return {}; + } case WalletApiOperation.DumpCoins: { return await dumpCoins(ws); } -- cgit v1.2.3