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 {
|
|
|
|
TRANSACTION_GROUP_STATUSES,
|
|
|
|
TRANSACTION_STATUSES,
|
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 = {
|
2020-11-07 08:38:12 +01:00
|
|
|
[TRANSACTION_STATUSES.SUBMITTED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
|
|
|
[TRANSACTION_STATUSES.APPROVED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
|
|
|
[TRANSACTION_STATUSES.SIGNED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-30 20:53:54 +02:00
|
|
|
|
|
|
|
const statusToClassNameHash = {
|
2020-11-03 23:57:51 +01:00
|
|
|
[TRANSACTION_STATUSES.UNAPPROVED]: 'transaction-status--unapproved',
|
|
|
|
[TRANSACTION_STATUSES.REJECTED]: 'transaction-status--rejected',
|
|
|
|
[TRANSACTION_STATUSES.FAILED]: 'transaction-status--failed',
|
|
|
|
[TRANSACTION_STATUSES.DROPPED]: 'transaction-status--dropped',
|
|
|
|
[TRANSACTION_GROUP_STATUSES.CANCELLED]: 'transaction-status--cancelled',
|
2020-06-10 22:38:34 +02:00
|
|
|
[QUEUED_PSEUDO_STATUS]: 'transaction-status--queued',
|
2020-11-07 08:38:12 +01:00
|
|
|
[TRANSACTION_GROUP_STATUSES.PENDING]: 'transaction-status--pending',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-30 20:53:54 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function TransactionStatus({
|
|
|
|
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
|
|
|
|
? TRANSACTION_GROUP_STATUSES.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 =
|
2021-12-01 18:22:08 +01:00
|
|
|
statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly
|
|
|
|
? date
|
|
|
|
: 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(
|
|
|
|
'transaction-status',
|
2021-12-01 18:22:08 +01:00
|
|
|
`transaction-status--${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
|
|
|
|
2020-06-10 22:38:34 +02:00
|
|
|
TransactionStatus.propTypes = {
|
|
|
|
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
|
|
|
};
|