show the button that wallet-core tells
This commit is contained in:
parent
cb3b48d316
commit
d79155b634
@ -29,6 +29,7 @@ import {
|
|||||||
TalerPreciseTimestamp,
|
TalerPreciseTimestamp,
|
||||||
TalerProtocolTimestamp,
|
TalerProtocolTimestamp,
|
||||||
Transaction,
|
Transaction,
|
||||||
|
TransactionAction,
|
||||||
TransactionDeposit,
|
TransactionDeposit,
|
||||||
TransactionIdStr,
|
TransactionIdStr,
|
||||||
TransactionMajorState,
|
TransactionMajorState,
|
||||||
@ -223,40 +224,7 @@ function TransactionTemplate({
|
|||||||
setConfirmBeforeCancel(true);
|
setConfirmBeforeCancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasCancelTransactionImplemented =
|
const showButton = getShowButtonStates(transaction);
|
||||||
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;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
@ -390,7 +358,7 @@ function TransactionTemplate({
|
|||||||
<footer>
|
<footer>
|
||||||
<div />
|
<div />
|
||||||
<div>
|
<div>
|
||||||
{showRetry && (
|
{showButton.retry && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={safely("retry transaction", onRetry)}
|
onClick={safely("retry transaction", onRetry)}
|
||||||
@ -398,7 +366,7 @@ function TransactionTemplate({
|
|||||||
<i18n.Translate>Retry</i18n.Translate>
|
<i18n.Translate>Retry</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showAbort && (
|
{showButton.abort && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={safely("abort transaction", onAbort)}
|
onClick={safely("abort transaction", onAbort)}
|
||||||
@ -406,7 +374,7 @@ function TransactionTemplate({
|
|||||||
<i18n.Translate>Abort</i18n.Translate>
|
<i18n.Translate>Abort</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showResume && settings.suspendIndividualTransaction && (
|
{showButton.resume && settings.suspendIndividualTransaction && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={safely("resume transaction", onResume)}
|
onClick={safely("resume transaction", onResume)}
|
||||||
@ -414,7 +382,7 @@ function TransactionTemplate({
|
|||||||
<i18n.Translate>Resume</i18n.Translate>
|
<i18n.Translate>Resume</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showSuspend && settings.suspendIndividualTransaction && (
|
{showButton.suspend && settings.suspendIndividualTransaction && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={safely("suspend transaction", onSuspend)}
|
onClick={safely("suspend transaction", onSuspend)}
|
||||||
@ -422,7 +390,7 @@ function TransactionTemplate({
|
|||||||
<i18n.Translate>Suspend</i18n.Translate>
|
<i18n.Translate>Suspend</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showCancel && (
|
{showButton.fail && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
@ -431,7 +399,7 @@ function TransactionTemplate({
|
|||||||
<i18n.Translate>Cancel</i18n.Translate>
|
<i18n.Translate>Cancel</i18n.Translate>
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{showDelete && (
|
{showButton.remove && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
@ -1948,3 +1916,39 @@ function ShowQrWithCopy({ text }: { text: string }): VNode {
|
|||||||
</div>
|
</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