2018-07-31 07:03:20 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2018-09-18 04:35:47 +02:00
|
|
|
import classnames from 'classnames'
|
2018-07-31 07:03:20 +02:00
|
|
|
import Identicon from '../identicon'
|
|
|
|
import TransactionStatus from '../transaction-status'
|
|
|
|
import TransactionAction from '../transaction-action'
|
2018-10-17 01:03:29 +02:00
|
|
|
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
|
2018-08-16 04:18:01 +02:00
|
|
|
import TokenCurrencyDisplay from '../token-currency-display'
|
2018-08-31 21:37:30 +02:00
|
|
|
import TransactionListItemDetails from '../transaction-list-item-details'
|
2018-07-31 07:03:20 +02:00
|
|
|
import { CONFIRM_TRANSACTION_ROUTE } from '../../routes'
|
2018-08-03 05:20:15 +02:00
|
|
|
import { UNAPPROVED_STATUS, TOKEN_METHOD_TRANSFER } from '../../constants/transactions'
|
2018-10-17 01:03:29 +02:00
|
|
|
import { PRIMARY, SECONDARY } from '../../constants/common'
|
2018-10-16 00:00:47 +02:00
|
|
|
import { getStatusKey } from '../../helpers/transactions.util'
|
2018-07-31 07:03:20 +02:00
|
|
|
|
|
|
|
export default class TransactionListItem extends PureComponent {
|
|
|
|
static propTypes = {
|
2018-09-17 19:34:29 +02:00
|
|
|
assetImages: PropTypes.object,
|
2018-07-31 07:03:20 +02:00
|
|
|
history: PropTypes.object,
|
2018-08-03 05:20:15 +02:00
|
|
|
methodData: PropTypes.object,
|
2018-09-17 19:34:29 +02:00
|
|
|
nonceAndDate: PropTypes.string,
|
2018-08-03 05:20:15 +02:00
|
|
|
retryTransaction: PropTypes.func,
|
|
|
|
setSelectedToken: PropTypes.func,
|
2018-09-17 19:34:29 +02:00
|
|
|
showCancelModal: PropTypes.func,
|
|
|
|
showCancel: PropTypes.bool,
|
|
|
|
showRetry: PropTypes.bool,
|
2018-08-16 04:18:01 +02:00
|
|
|
token: PropTypes.object,
|
2018-09-07 22:59:05 +02:00
|
|
|
tokenData: PropTypes.object,
|
2018-09-17 19:34:29 +02:00
|
|
|
transaction: PropTypes.object,
|
|
|
|
value: PropTypes.string,
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 21:37:30 +02:00
|
|
|
state = {
|
|
|
|
showTransactionDetails: false,
|
|
|
|
}
|
|
|
|
|
2018-07-31 07:03:20 +02:00
|
|
|
handleClick = () => {
|
2018-09-18 03:32:35 +02:00
|
|
|
const {
|
|
|
|
transaction,
|
|
|
|
history,
|
|
|
|
} = this.props
|
2018-08-31 21:37:30 +02:00
|
|
|
const { id, status } = transaction
|
|
|
|
const { showTransactionDetails } = this.state
|
2018-07-31 07:03:20 +02:00
|
|
|
|
|
|
|
if (status === UNAPPROVED_STATUS) {
|
|
|
|
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${id}`)
|
2018-08-31 21:37:30 +02:00
|
|
|
return
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
2018-08-31 21:37:30 +02:00
|
|
|
|
2018-10-23 13:59:04 +02:00
|
|
|
this.setState({ showTransactionDetails: !showTransactionDetails })
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 19:34:29 +02:00
|
|
|
handleCancel = () => {
|
|
|
|
const { transaction: { id, txParams: { gasPrice } } = {}, showCancelModal } = this.props
|
|
|
|
showCancelModal(id, gasPrice)
|
|
|
|
}
|
|
|
|
|
2018-09-15 05:19:13 +02:00
|
|
|
handleRetry = () => {
|
2018-08-03 05:20:15 +02:00
|
|
|
const {
|
|
|
|
transaction: { txParams: { to } = {} },
|
|
|
|
methodData: { name } = {},
|
|
|
|
setSelectedToken,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (name === TOKEN_METHOD_TRANSFER) {
|
|
|
|
setSelectedToken(to)
|
|
|
|
}
|
|
|
|
|
2018-09-26 23:58:27 +02:00
|
|
|
return this.resubmit()
|
2018-08-03 05:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resubmit () {
|
|
|
|
const { transaction: { id }, retryTransaction, history } = this.props
|
2018-09-26 23:58:27 +02:00
|
|
|
return retryTransaction(id)
|
2018-08-03 05:20:15 +02:00
|
|
|
.then(id => history.push(`${CONFIRM_TRANSACTION_ROUTE}/${id}`))
|
|
|
|
}
|
|
|
|
|
2018-08-16 04:18:01 +02:00
|
|
|
renderPrimaryCurrency () {
|
|
|
|
const { token, transaction: { txParams: { data } = {} } = {}, value } = this.props
|
|
|
|
|
|
|
|
return token
|
|
|
|
? (
|
|
|
|
<TokenCurrencyDisplay
|
|
|
|
className="transaction-list-item__amount transaction-list-item__amount--primary"
|
|
|
|
token={token}
|
|
|
|
transactionData={data}
|
|
|
|
prefix="-"
|
|
|
|
/>
|
|
|
|
) : (
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-16 04:18:01 +02:00
|
|
|
className="transaction-list-item__amount transaction-list-item__amount--primary"
|
|
|
|
value={value}
|
2018-10-17 01:03:29 +02:00
|
|
|
type={PRIMARY}
|
2018-08-16 04:18:01 +02:00
|
|
|
prefix="-"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSecondaryCurrency () {
|
|
|
|
const { token, value } = this.props
|
|
|
|
|
|
|
|
return token
|
|
|
|
? null
|
|
|
|
: (
|
2018-10-17 01:03:29 +02:00
|
|
|
<UserPreferencedCurrencyDisplay
|
2018-08-16 04:18:01 +02:00
|
|
|
className="transaction-list-item__amount transaction-list-item__amount--secondary"
|
|
|
|
value={value}
|
2018-10-17 01:03:29 +02:00
|
|
|
prefix="-"
|
|
|
|
type={SECONDARY}
|
2018-08-16 04:18:01 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-07-31 07:03:20 +02:00
|
|
|
render () {
|
2018-08-03 05:20:15 +02:00
|
|
|
const {
|
2018-09-17 19:34:29 +02:00
|
|
|
assetImages,
|
2018-08-03 05:20:15 +02:00
|
|
|
methodData,
|
2018-08-07 10:57:46 +02:00
|
|
|
nonceAndDate,
|
2018-09-17 19:34:29 +02:00
|
|
|
showCancel,
|
|
|
|
showRetry,
|
2018-09-07 22:59:05 +02:00
|
|
|
tokenData,
|
2018-09-17 19:34:29 +02:00
|
|
|
transaction,
|
2018-08-03 05:20:15 +02:00
|
|
|
} = this.props
|
2018-07-31 07:03:20 +02:00
|
|
|
const { txParams = {} } = transaction
|
2018-08-31 21:37:30 +02:00
|
|
|
const { showTransactionDetails } = this.state
|
2018-09-07 22:59:05 +02:00
|
|
|
const toAddress = tokenData
|
|
|
|
? tokenData.params && tokenData.params[0] && tokenData.params[0].value || txParams.to
|
|
|
|
: txParams.to
|
2018-08-03 05:20:15 +02:00
|
|
|
|
2018-07-31 07:03:20 +02:00
|
|
|
return (
|
2018-08-31 21:37:30 +02:00
|
|
|
<div className="transaction-list-item">
|
|
|
|
<div
|
|
|
|
className="transaction-list-item__grid"
|
|
|
|
onClick={this.handleClick}
|
|
|
|
>
|
2018-08-03 05:20:15 +02:00
|
|
|
<Identicon
|
|
|
|
className="transaction-list-item__identicon"
|
2018-09-07 22:59:05 +02:00
|
|
|
address={toAddress}
|
2018-08-03 05:20:15 +02:00
|
|
|
diameter={34}
|
2018-09-07 22:59:05 +02:00
|
|
|
image={assetImages[toAddress]}
|
2018-08-03 05:20:15 +02:00
|
|
|
/>
|
|
|
|
<TransactionAction
|
|
|
|
transaction={transaction}
|
|
|
|
methodData={methodData}
|
|
|
|
className="transaction-list-item__action"
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className="transaction-list-item__nonce"
|
2018-08-07 10:57:46 +02:00
|
|
|
title={nonceAndDate}
|
2018-08-03 05:20:15 +02:00
|
|
|
>
|
2018-08-07 10:57:46 +02:00
|
|
|
{ nonceAndDate }
|
2018-08-03 05:20:15 +02:00
|
|
|
</div>
|
|
|
|
<TransactionStatus
|
|
|
|
className="transaction-list-item__status"
|
2018-10-16 00:00:47 +02:00
|
|
|
statusKey={getStatusKey(transaction)}
|
2018-09-09 01:18:26 +02:00
|
|
|
title={(
|
|
|
|
(transaction.err && transaction.err.rpc)
|
|
|
|
? transaction.err.rpc.message
|
2018-09-09 01:26:02 +02:00
|
|
|
: transaction.err && transaction.err.message
|
2018-09-09 01:18:26 +02:00
|
|
|
)}
|
2018-08-03 05:20:15 +02:00
|
|
|
/>
|
2018-08-16 04:18:01 +02:00
|
|
|
{ this.renderPrimaryCurrency() }
|
|
|
|
{ this.renderSecondaryCurrency() }
|
2018-07-31 07:03:20 +02:00
|
|
|
</div>
|
2018-09-18 04:35:47 +02:00
|
|
|
<div className={classnames('transaction-list-item__expander', {
|
|
|
|
'transaction-list-item__expander--show': showTransactionDetails,
|
|
|
|
})}>
|
|
|
|
{
|
|
|
|
showTransactionDetails && (
|
|
|
|
<div className="transaction-list-item__details-container">
|
|
|
|
<TransactionListItemDetails
|
|
|
|
transaction={transaction}
|
|
|
|
onRetry={this.handleRetry}
|
|
|
|
showRetry={showRetry && methodData.done}
|
|
|
|
onCancel={this.handleCancel}
|
|
|
|
showCancel={showCancel}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</div>
|
2018-07-31 07:03:20 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|