import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import copyToClipboard from 'copy-to-clipboard'; import { getBlockExplorerLink } from '@metamask/etherscan-link'; import SenderToRecipient from '../../ui/sender-to-recipient'; import { DEFAULT_VARIANT } from '../../ui/sender-to-recipient/sender-to-recipient.constants'; import Disclosure from '../../ui/disclosure'; import TransactionActivityLog from '../transaction-activity-log'; import TransactionBreakdown from '../transaction-breakdown'; import Button from '../../ui/button'; import Tooltip from '../../ui/tooltip'; import CancelButton from '../cancel-button'; import Popover from '../../ui/popover'; import { SECOND } from '../../../../shared/constants/time'; import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction'; import { getURLHostName } from '../../../helpers/utils/util'; import TransactionDecoding from '../transaction-decoding'; export default class TransactionListItemDetails extends PureComponent { static contextTypes = { t: PropTypes.func, metricsEvent: PropTypes.func, trackEvent: PropTypes.func, }; static defaultProps = { recipientEns: null, }; static propTypes = { onCancel: PropTypes.func, onRetry: PropTypes.func, showCancel: PropTypes.bool, showSpeedUp: PropTypes.bool, showRetry: PropTypes.bool, isEarliestNonce: PropTypes.bool, primaryCurrency: PropTypes.string, transactionGroup: PropTypes.object, title: PropTypes.string.isRequired, onClose: PropTypes.func.isRequired, recipientEns: PropTypes.string, recipientAddress: PropTypes.string, rpcPrefs: PropTypes.object, senderAddress: PropTypes.string.isRequired, tryReverseResolveAddress: PropTypes.func.isRequired, senderNickname: PropTypes.string.isRequired, recipientNickname: PropTypes.string, transactionStatus: PropTypes.func, }; state = { justCopied: false, }; handleBlockExplorerClick = () => { const { transactionGroup: { primaryTransaction }, rpcPrefs, } = this.props; const blockExplorerLink = getBlockExplorerLink( primaryTransaction, rpcPrefs, ); this.context.trackEvent({ category: 'Transactions', event: 'Clicked Block Explorer Link', properties: { link_type: 'Transaction Block Explorer', action: 'Transaction Details', block_explorer_domain: getURLHostName(blockExplorerLink), }, }); global.platform.openTab({ url: blockExplorerLink, }); }; handleCancel = (event) => { const { onCancel, onClose } = this.props; onCancel(event); onClose(); }; handleRetry = (event) => { const { onClose, onRetry } = this.props; onRetry(event); onClose(); }; handleCopyTxId = () => { const { transactionGroup } = this.props; const { primaryTransaction: transaction } = transactionGroup; const { hash } = transaction; this.context.metricsEvent({ eventOpts: { category: 'Navigation', action: 'Activity Log', name: 'Copied Transaction ID', }, }); this.setState({ justCopied: true }, () => { copyToClipboard(hash); setTimeout(() => this.setState({ justCopied: false }), SECOND); }); }; componentDidMount() { const { recipientAddress, tryReverseResolveAddress } = this.props; if (recipientAddress) { tryReverseResolveAddress(recipientAddress); } } render() { const { t } = this.context; const { justCopied } = this.state; const { transactionGroup, primaryCurrency, showSpeedUp, showRetry, recipientEns, recipientAddress, senderAddress, isEarliestNonce, senderNickname, title, onClose, recipientNickname, showCancel, transactionStatus: TransactionStatus, } = this.props; const { primaryTransaction: transaction, initialTransaction: { type }, } = transactionGroup; const { hash } = transaction; return (
{showSpeedUp && ( )} {showCancel && ( )} {showRetry && ( )}
Status
{t('from')}
{t('to')}
{ this.context.metricsEvent({ eventOpts: { category: 'Navigation', action: 'Activity Log', name: 'Copied "To" Address', }, }); }} onSenderClick={() => { this.context.metricsEvent({ eventOpts: { category: 'Navigation', action: 'Activity Log', name: 'Copied "From" Address', }, }); }} />
{transactionGroup.initialTransaction?.txParams?.data ? ( ) : null}
); } }