2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
import Tooltip from '../../ui/tooltip';
|
2019-07-08 19:58:35 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2020-11-03 23:57:51 +01:00
|
|
|
import {
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionGroupStatus,
|
|
|
|
TransactionStatus,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../../shared/constants/transaction';
|
2020-06-10 22:38:34 +02:00
|
|
|
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
import { getTransactionStatusMap } from '../../../selectors/institutional/selectors';
|
|
|
|
import { getCurrentKeyring } from '../../../selectors';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const QUEUED_PSEUDO_STATUS = 'queued';
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
const CUSTODIAN_PSEUDO_STATUS = 'inCustody';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2020-06-10 22:38:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A note about status logic for this component:
|
|
|
|
* Approved, Signed and Submitted statuses are all treated, effectively
|
|
|
|
* as pending. Transactions are only approved or signed for less than a
|
|
|
|
* second, usually, and ultimately should be rendered in the UI no
|
|
|
|
* differently than a pending transaction.
|
|
|
|
*
|
|
|
|
* Confirmed transactions are not especially highlighted except that their
|
|
|
|
* status label will be the date the transaction was finalized.
|
|
|
|
*/
|
|
|
|
const pendingStatusHash = {
|
2023-01-18 15:47:29 +01:00
|
|
|
[TransactionStatus.submitted]: TransactionGroupStatus.pending,
|
|
|
|
[TransactionStatus.approved]: TransactionGroupStatus.pending,
|
|
|
|
[TransactionStatus.signed]: TransactionGroupStatus.pending,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-30 20:53:54 +02:00
|
|
|
|
|
|
|
const statusToClassNameHash = {
|
2023-01-18 15:47:29 +01:00
|
|
|
[TransactionStatus.unapproved]: 'transaction-status-label--unapproved',
|
|
|
|
[TransactionStatus.rejected]: 'transaction-status-label--rejected',
|
|
|
|
[TransactionStatus.failed]: 'transaction-status-label--failed',
|
|
|
|
[TransactionStatus.dropped]: 'transaction-status-label--dropped',
|
|
|
|
[TransactionGroupStatus.cancelled]: 'transaction-status-label--cancelled',
|
|
|
|
[QUEUED_PSEUDO_STATUS]: 'transaction-status-label--queued',
|
|
|
|
[TransactionGroupStatus.pending]: 'transaction-status-label--pending',
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
[CUSTODIAN_PSEUDO_STATUS]: 'transaction-status--custodian',
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-30 20:53:54 +02:00
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
export default function TransactionStatusLabel({
|
2020-11-03 00:41:28 +01:00
|
|
|
status,
|
|
|
|
date,
|
|
|
|
error,
|
|
|
|
isEarliestNonce,
|
|
|
|
className,
|
2021-12-01 18:22:08 +01:00
|
|
|
statusOnly,
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
custodyStatus,
|
|
|
|
custodyStatusDisplayText,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2020-11-03 00:41:28 +01:00
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
2023-04-28 13:41:16 +02:00
|
|
|
let tooltipText = error?.rpc?.message || error?.message;
|
2021-02-04 19:15:23 +01:00
|
|
|
let statusKey = status;
|
2020-06-10 22:38:34 +02:00
|
|
|
if (pendingStatusHash[status]) {
|
2020-11-07 08:38:12 +01:00
|
|
|
statusKey = isEarliestNonce
|
2023-01-18 15:47:29 +01:00
|
|
|
? TransactionGroupStatus.pending
|
2021-02-04 19:15:23 +01:00
|
|
|
: QUEUED_PSEUDO_STATUS;
|
2018-09-09 01:18:26 +02:00
|
|
|
}
|
|
|
|
|
2023-04-28 13:41:16 +02:00
|
|
|
let statusText = statusKey && t(statusKey);
|
|
|
|
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
statusText = custodyStatusDisplayText || t(statusKey);
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
|
|
|
if (statusKey === TransactionStatus.confirmed && !statusOnly) {
|
|
|
|
statusText = date;
|
|
|
|
}
|
|
|
|
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
const transactionStatusMap = useSelector(getTransactionStatusMap);
|
|
|
|
const currentKeyring = useSelector(getCurrentKeyring);
|
|
|
|
const custodyType = currentKeyring?.type.split(' - ')[1]?.toLowerCase();
|
|
|
|
|
|
|
|
if (
|
|
|
|
custodyStatus &&
|
|
|
|
transactionStatusMap &&
|
|
|
|
transactionStatusMap[custodyType]
|
|
|
|
) {
|
|
|
|
const custodyStatusInfo = transactionStatusMap[custodyType][custodyStatus];
|
|
|
|
const shortText = custodyStatusInfo?.shortText || custodyStatus;
|
|
|
|
const longText = custodyStatusInfo?.longText;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
tooltipText = error.message;
|
|
|
|
statusText =
|
|
|
|
custodyStatus === 'aborted'
|
|
|
|
? custodyStatusDisplayText
|
|
|
|
: t('snapResultError');
|
|
|
|
} else {
|
|
|
|
tooltipText = custodyStatusDisplayText || longText || custodyStatus;
|
|
|
|
statusText = custodyStatusDisplayText || shortText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2018-08-24 01:44:38 +02:00
|
|
|
|
2020-06-10 22:38:34 +02:00
|
|
|
return (
|
2020-06-17 18:38:15 +02:00
|
|
|
<Tooltip
|
|
|
|
position="top"
|
|
|
|
title={tooltipText}
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapperClassName={classnames(
|
2023-01-18 15:47:29 +01:00
|
|
|
'transaction-status-label',
|
|
|
|
`transaction-status-label--${statusKey}`,
|
2020-11-03 00:41:28 +01:00
|
|
|
className,
|
|
|
|
statusToClassNameHash[statusKey],
|
|
|
|
)}
|
2020-06-17 18:38:15 +02:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{statusText}
|
2020-06-17 18:38:15 +02:00
|
|
|
</Tooltip>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-06-10 22:38:34 +02:00
|
|
|
}
|
2018-07-30 20:53:54 +02:00
|
|
|
|
2023-01-18 15:47:29 +01:00
|
|
|
TransactionStatusLabel.propTypes = {
|
2020-06-10 22:38:34 +02:00
|
|
|
status: PropTypes.string,
|
|
|
|
className: PropTypes.string,
|
|
|
|
date: PropTypes.string,
|
|
|
|
error: PropTypes.object,
|
|
|
|
isEarliestNonce: PropTypes.bool,
|
2021-12-01 18:22:08 +01:00
|
|
|
statusOnly: PropTypes.bool,
|
2023-04-28 13:41:16 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
custodyStatus: PropTypes.string,
|
|
|
|
custodyStatusDisplayText: PropTypes.string,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|