1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 22:24:27 +01:00
metamask-extension/ui/app/components/transaction-list-item-details/transaction-list-item-details.component.js

147 lines
4.8 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import copyToClipboard from 'copy-to-clipboard'
import SenderToRecipient from '../sender-to-recipient'
2018-12-09 21:48:06 +01:00
import { FLAT_VARIANT } from '../sender-to-recipient/sender-to-recipient.constants'
import TransactionActivityLog from '../transaction-activity-log'
import TransactionBreakdown from '../transaction-breakdown'
import Button from '../button'
import Tooltip from '../tooltip'
import prefixForNetwork from '../../../lib/etherscan-prefix-for-network'
export default class TransactionListItemDetails extends PureComponent {
static contextTypes = {
t: PropTypes.func,
}
static propTypes = {
onCancel: PropTypes.func,
2018-09-15 05:19:13 +02:00
onRetry: PropTypes.func,
showCancel: PropTypes.bool,
showRetry: PropTypes.bool,
2018-12-09 21:48:06 +01:00
transactionGroup: PropTypes.object,
}
state = {
justCopied: false,
}
handleEtherscanClick = () => {
2018-12-09 21:48:06 +01:00
const { transactionGroup: { primaryTransaction } } = this.props
const { hash, metamaskNetworkId } = primaryTransaction
const prefix = prefixForNetwork(metamaskNetworkId)
const etherscanUrl = `https://${prefix}etherscan.io/tx/${hash}`
global.platform.openWindow({ url: etherscanUrl })
}
handleCancel = event => {
2018-12-09 21:48:06 +01:00
const { transactionGroup: { initialTransaction: { id } = {} } = {}, onCancel } = this.props
event.stopPropagation()
2018-12-09 21:48:06 +01:00
onCancel(id)
}
2018-09-15 05:19:13 +02:00
handleRetry = event => {
2018-12-09 21:48:06 +01:00
const { transactionGroup: { initialTransaction: { id } = {} } = {}, onRetry } = this.props
2018-09-15 05:19:13 +02:00
event.stopPropagation()
2018-12-09 21:48:06 +01:00
onRetry(id)
2018-09-15 05:19:13 +02:00
}
handleCopyTxId = () => {
const { transactionGroup} = this.props
const { primaryTransaction: transaction } = transactionGroup
const { hash } = transaction
this.setState({ justCopied: true }, () => {
copyToClipboard(hash)
setTimeout(() => this.setState({ justCopied: false }), 1000)
})
}
render () {
const { t } = this.context
const { justCopied } = this.state
2018-12-09 21:48:06 +01:00
const { transactionGroup, showCancel, showRetry, onCancel, onRetry } = this.props
const { primaryTransaction: transaction } = transactionGroup
const { txParams: { to, from } = {} } = transaction
return (
<div className="transaction-list-item-details">
<div className="transaction-list-item-details__header">
2018-12-09 21:48:06 +01:00
<div>{ t('details') }</div>
<div className="transaction-list-item-details__header-buttons">
{
showRetry && (
<Button
type="raised"
2018-09-15 05:19:13 +02:00
onClick={this.handleRetry}
className="transaction-list-item-details__header-button"
>
{ t('speedUp') }
</Button>
)
}
{
showCancel && (
<Button
type="raised"
onClick={this.handleCancel}
className="transaction-list-item-details__header-button"
>
{ t('cancel') }
</Button>
)
}
<Tooltip title={justCopied ? t('copiedTransactionId') : t('copyTransactionId')}>
<Button
type="raised"
onClick={this.handleCopyTxId}
className="transaction-list-item-details__header-button"
>
<img
className="transaction-list-item-details__header-button__copy-icon"
src="/images/copy-to-clipboard.svg"
/>
</Button>
</Tooltip>
<Tooltip title={t('viewOnEtherscan')}>
<Button
type="raised"
onClick={this.handleEtherscanClick}
className="transaction-list-item-details__header-button"
>
<img src="/images/arrow-popout.svg" />
</Button>
</Tooltip>
</div>
</div>
2018-12-09 21:48:06 +01:00
<div className="transaction-list-item-details__body">
<div className="transaction-list-item-details__sender-to-recipient-container">
<SenderToRecipient
variant={FLAT_VARIANT}
addressOnly
recipientAddress={to}
senderAddress={from}
/>
</div>
<div className="transaction-list-item-details__cards-container">
<TransactionBreakdown
transaction={transaction}
className="transaction-list-item-details__transaction-breakdown"
/>
<TransactionActivityLog
transactionGroup={transactionGroup}
className="transaction-list-item-details__transaction-activity-log"
onCancel={onCancel}
onRetry={onRetry}
/>
</div>
</div>
</div>
)
}
}