From bd7ca80ff6528377afdfcb94f612393853d3f69c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 29 May 2023 23:47:21 -0300 Subject: show buttons --- .../src/wallet/Transaction.tsx | 193 ++++++++++++++------- 1 file changed, 126 insertions(+), 67 deletions(-) (limited to 'packages/taler-wallet-webextension') diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 39175186f..eb2325e7a 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -115,17 +115,26 @@ export function TransactionPage({ tid, goToWalletHistory }: Props): VNode { return ( { - null; - }} onCancel={async () => { - await api.wallet.call(WalletApiOperation.AbortTransaction, { + await api.wallet.call(WalletApiOperation.CancelAbortingTransaction, { transactionId, }); goToWalletHistory(currency); }} - onDelete={async () => { - await api.wallet.call(WalletApiOperation.DeleteTransaction, { + onSuspend={async () => { + await api.wallet.call(WalletApiOperation.SuspendTransaction, { + transactionId, + }); + goToWalletHistory(currency); + }} + onResume={async () => { + await api.wallet.call(WalletApiOperation.SuspendTransaction, { + transactionId, + }); + goToWalletHistory(currency); + }} + onAbort={async () => { + await api.wallet.call(WalletApiOperation.AbortTransaction, { transactionId, }); goToWalletHistory(currency); @@ -136,6 +145,12 @@ export function TransactionPage({ tid, goToWalletHistory }: Props): VNode { }); goToWalletHistory(currency); }} + onDelete={async () => { + await api.wallet.call(WalletApiOperation.DeleteTransaction, { + transactionId, + }); + goToWalletHistory(currency); + }} onRefund={async (transactionId) => { await api.wallet.call(WalletApiOperation.StartRefundQuery, { transactionId, @@ -148,8 +163,10 @@ export function TransactionPage({ tid, goToWalletHistory }: Props): VNode { export interface WalletTransactionProps { transaction: Transaction; - onSend: () => Promise; onCancel: () => Promise; + onSuspend: () => Promise; + onResume: () => Promise; + onAbort: () => Promise; onDelete: () => Promise; onRetry: () => Promise; onRefund: (id: TransactionIdStr) => Promise; @@ -175,7 +192,9 @@ function TransactionTemplate({ transaction, onDelete, onRetry, - onSend, + onAbort, + onResume, + onSuspend, onCancel, children, }: TransactionTemplateProps): VNode { @@ -199,26 +218,39 @@ function TransactionTemplate({ setConfirmBeforeCancel(true); } - const SHOWING_RETRY_THRESHOLD_SECS = 30; - - const showSend = false; const hasCancelTransactionImplemented = transaction.type === TransactionType.Payment; + const hasAbortTransactionImplemented = + transaction.type === TransactionType.Withdrawal || + transaction.type === TransactionType.Deposit || + transaction.type === TransactionType.Payment; - const transactionStillActive = - transaction.txState.major !== TransactionMajorState.Aborted && - transaction.txState.major !== TransactionMajorState.Done && - transaction.txState.major !== TransactionMajorState.Failed; + const isFinalState = + transaction.txState.major === TransactionMajorState.Aborted || + transaction.txState.major === TransactionMajorState.Done || + transaction.txState.major === TransactionMajorState.Failed; + + const showAbort = + hasAbortTransactionImplemented && + transaction.txState.major === TransactionMajorState.Pending; + + const showCancel = + hasCancelTransactionImplemented && + transaction.txState.major === TransactionMajorState.Aborting; - // show retry if there is an error in an active state, or after some time - // if it is not aborting const showRetry = - transactionStillActive && - (transaction.error !== undefined || - (transaction.txState.major === TransactionMajorState.Aborting && - (transaction.timestamp.t_s === "never" || - differenceInSeconds(new Date(), transaction.timestamp.t_s * 1000) > - SHOWING_RETRY_THRESHOLD_SECS))); + transaction.txState.major !== TransactionMajorState.Pending && + transaction.txState.major !== TransactionMajorState.Aborting; + + const showDelete = isFinalState; + + const showResume = + transaction.txState.major === TransactionMajorState.Suspended || + transaction.txState.major === TransactionMajorState.SuspendedAborting; + + const showSuspend = + transaction.txState.major === TransactionMajorState.Pending || + transaction.txState.major === TransactionMajorState.Aborting; return ( @@ -331,46 +363,50 @@ function TransactionTemplate({
{children}