mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
6dd141ebfd
* Fix: Insufficient number of substitutions for key "stxSuccessDescription" * Only calculate "approvalGas" if the "approvalNeeded" param is truthy in a quote * "Swap from" has to be set to enable "Review Swap", set a default token for "Swap from" * Fix: Unable to find value of key "undefined" for locale * Use array destructuring
86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import classnames from 'classnames';
|
|
import Tooltip from '../../ui/tooltip';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import {
|
|
TRANSACTION_GROUP_STATUSES,
|
|
TRANSACTION_STATUSES,
|
|
} from '../../../../shared/constants/transaction';
|
|
|
|
const QUEUED_PSEUDO_STATUS = 'queued';
|
|
|
|
/**
|
|
* 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 = {
|
|
[TRANSACTION_STATUSES.SUBMITTED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
|
[TRANSACTION_STATUSES.APPROVED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
|
[TRANSACTION_STATUSES.SIGNED]: TRANSACTION_GROUP_STATUSES.PENDING,
|
|
};
|
|
|
|
const statusToClassNameHash = {
|
|
[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',
|
|
[QUEUED_PSEUDO_STATUS]: 'transaction-status--queued',
|
|
[TRANSACTION_GROUP_STATUSES.PENDING]: 'transaction-status--pending',
|
|
};
|
|
|
|
export default function TransactionStatus({
|
|
status,
|
|
date,
|
|
error,
|
|
isEarliestNonce,
|
|
className,
|
|
statusOnly,
|
|
}) {
|
|
const t = useI18nContext();
|
|
const tooltipText = error?.rpc?.message || error?.message;
|
|
let statusKey = status;
|
|
if (pendingStatusHash[status]) {
|
|
statusKey = isEarliestNonce
|
|
? TRANSACTION_GROUP_STATUSES.PENDING
|
|
: QUEUED_PSEUDO_STATUS;
|
|
}
|
|
|
|
const statusText =
|
|
statusKey === TRANSACTION_STATUSES.CONFIRMED && !statusOnly
|
|
? date
|
|
: statusKey && t(statusKey);
|
|
|
|
return (
|
|
<Tooltip
|
|
position="top"
|
|
title={tooltipText}
|
|
wrapperClassName={classnames(
|
|
'transaction-status',
|
|
`transaction-status--${statusKey}`,
|
|
className,
|
|
statusToClassNameHash[statusKey],
|
|
)}
|
|
>
|
|
{statusText}
|
|
</Tooltip>
|
|
);
|
|
}
|
|
|
|
TransactionStatus.propTypes = {
|
|
status: PropTypes.string,
|
|
className: PropTypes.string,
|
|
date: PropTypes.string,
|
|
error: PropTypes.object,
|
|
isEarliestNonce: PropTypes.bool,
|
|
statusOnly: PropTypes.bool,
|
|
};
|