diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/Transaction.tsx | 84 |
1 files changed, 44 insertions, 40 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 8f2d279da..80f0479c8 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -29,6 +29,7 @@ import { TalerPreciseTimestamp, TalerProtocolTimestamp, Transaction, + TransactionAction, TransactionDeposit, TransactionIdStr, TransactionMajorState, @@ -223,40 +224,7 @@ function TransactionTemplate({ setConfirmBeforeCancel(true); } - const hasCancelTransactionImplemented = - transaction.type === TransactionType.Payment; - const hasAbortTransactionImplemented = - transaction.type === TransactionType.Withdrawal || - transaction.type === TransactionType.Deposit || - transaction.type === TransactionType.Payment; - - 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; - - const showRetry = - !isFinalState && - 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; + const showButton = getShowButtonStates(transaction); return ( <Fragment> @@ -390,7 +358,7 @@ function TransactionTemplate({ <footer> <div /> <div> - {showRetry && ( + {showButton.retry && ( <Button variant="contained" onClick={safely("retry transaction", onRetry)} @@ -398,7 +366,7 @@ function TransactionTemplate({ <i18n.Translate>Retry</i18n.Translate> </Button> )} - {showAbort && ( + {showButton.abort && ( <Button variant="contained" onClick={safely("abort transaction", onAbort)} @@ -406,7 +374,7 @@ function TransactionTemplate({ <i18n.Translate>Abort</i18n.Translate> </Button> )} - {showResume && settings.suspendIndividualTransaction && ( + {showButton.resume && settings.suspendIndividualTransaction && ( <Button variant="contained" onClick={safely("resume transaction", onResume)} @@ -414,7 +382,7 @@ function TransactionTemplate({ <i18n.Translate>Resume</i18n.Translate> </Button> )} - {showSuspend && settings.suspendIndividualTransaction && ( + {showButton.suspend && settings.suspendIndividualTransaction && ( <Button variant="contained" onClick={safely("suspend transaction", onSuspend)} @@ -422,7 +390,7 @@ function TransactionTemplate({ <i18n.Translate>Suspend</i18n.Translate> </Button> )} - {showCancel && ( + {showButton.fail && ( <Button variant="contained" color="error" @@ -431,7 +399,7 @@ function TransactionTemplate({ <i18n.Translate>Cancel</i18n.Translate> </Button> )} - {showDelete && ( + {showButton.remove && ( <Button variant="contained" color="error" @@ -1948,3 +1916,39 @@ function ShowQrWithCopy({ text }: { text: string }): VNode { </div> ); } + +function getShowButtonStates(transaction: Transaction) { + let abort = false; + let fail = false; + let resume = false; + let retry = false; + let remove = false; + let suspend = false; + + transaction.txActions.forEach((a) => { + switch (a) { + case TransactionAction.Delete: + remove = true; + break; + case TransactionAction.Suspend: + suspend = true; + break; + case TransactionAction.Resume: + resume = true; + break; + case TransactionAction.Abort: + abort = true; + break; + case TransactionAction.Fail: + fail = true; + break; + case TransactionAction.Retry: + retry = true; + break; + default: + assertUnreachable(a); + break; + } + }); + return { abort, fail, resume, retry, remove, suspend }; +} |