2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const QUEUED_PSEUDO_STATUS = 'queued';
|
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',
|
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,
|
2020-11-03 00:41:28 +01:00
|
|
|
}) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const t = useI18nContext();
|
|
|
|
const tooltipText = error?.rpc?.message || error?.message;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 23:57:51 +01:00
|
|
|
const statusText =
|
2023-01-18 15:47:29 +01:00
|
|
|
statusKey === TransactionStatus.confirmed && !statusOnly
|
2021-12-01 18:22:08 +01:00
|
|
|
? date
|
2022-02-23 22:10:28 +01:00
|
|
|
: statusKey && t(statusKey);
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|