show the button that wallet-core tells
This commit is contained in:
parent
cb3b48d316
commit
d79155b634
@ -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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user