2018-07-31 07:03:20 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import TransactionListItem from '../transaction-list-item'
|
2018-08-06 22:45:56 +02:00
|
|
|
import ShapeShiftTransactionListItem from '../shift-list-item'
|
|
|
|
import { TRANSACTION_TYPE_SHAPESHIFT } from '../../constants/transactions'
|
2018-07-31 07:03:20 +02:00
|
|
|
|
|
|
|
export default class TransactionList extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
pendingTransactions: [],
|
|
|
|
completedTransactions: [],
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
pendingTransactions: PropTypes.array,
|
|
|
|
completedTransactions: PropTypes.array,
|
2018-08-06 07:25:58 +02:00
|
|
|
selectedToken: PropTypes.object,
|
2018-08-12 06:12:30 +02:00
|
|
|
updateNetworkNonce: PropTypes.func,
|
2018-08-30 18:51:57 +02:00
|
|
|
assetImages: PropTypes.object,
|
2018-08-12 06:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.props.updateNetworkNonce()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { pendingTransactions: prevPendingTransactions = [] } = prevProps
|
|
|
|
const { pendingTransactions = [], updateNetworkNonce } = this.props
|
|
|
|
|
|
|
|
if (pendingTransactions.length > prevPendingTransactions.length) {
|
|
|
|
updateNetworkNonce()
|
|
|
|
}
|
2018-08-03 05:20:15 +02:00
|
|
|
}
|
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
shouldShowRetry = (transactionGroup, isEarliestNonce) => {
|
|
|
|
const { transactions = [], hasRetried } = transactionGroup
|
|
|
|
const [earliestTransaction = {}] = transactions
|
|
|
|
const { submittedTime } = earliestTransaction
|
|
|
|
return Date.now() - submittedTime > 30000 && isEarliestNonce && !hasRetried
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldShowCancel (transactionGroup) {
|
|
|
|
const { hasCancelled } = transactionGroup
|
|
|
|
return !hasCancelled
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
renderTransactions () {
|
|
|
|
const { t } = this.context
|
2018-08-30 22:19:10 +02:00
|
|
|
const { pendingTransactions = [], completedTransactions = [] } = this.props
|
2018-12-09 21:48:06 +01:00
|
|
|
const pendingLength = pendingTransactions.length
|
|
|
|
|
2018-07-31 07:03:20 +02:00
|
|
|
return (
|
|
|
|
<div className="transaction-list__transactions">
|
|
|
|
{
|
2018-12-09 21:48:06 +01:00
|
|
|
pendingLength > 0 && (
|
2018-07-31 07:03:20 +02:00
|
|
|
<div className="transaction-list__pending-transactions">
|
|
|
|
<div className="transaction-list__header">
|
2018-08-01 04:37:38 +02:00
|
|
|
{ `${t('queue')} (${pendingTransactions.length})` }
|
2018-07-31 07:03:20 +02:00
|
|
|
</div>
|
|
|
|
{
|
2018-12-09 21:48:06 +01:00
|
|
|
pendingTransactions.map((transactionGroup, index) => (
|
2018-12-13 03:33:46 +01:00
|
|
|
this.renderTransaction(transactionGroup, index, true)
|
2018-08-01 04:56:51 +02:00
|
|
|
))
|
2018-07-31 07:03:20 +02:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
<div className="transaction-list__completed-transactions">
|
|
|
|
<div className="transaction-list__header">
|
|
|
|
{ t('history') }
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
completedTransactions.length > 0
|
2018-12-09 21:48:06 +01:00
|
|
|
? completedTransactions.map((transactionGroup, index) => (
|
|
|
|
this.renderTransaction(transactionGroup, index)
|
2018-08-01 04:56:51 +02:00
|
|
|
))
|
2018-07-31 07:03:20 +02:00
|
|
|
: this.renderEmpty()
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-12-13 03:33:46 +01:00
|
|
|
renderTransaction (transactionGroup, index, isPendingTx = false) {
|
2018-08-30 18:51:57 +02:00
|
|
|
const { selectedToken, assetImages } = this.props
|
2018-12-09 21:48:06 +01:00
|
|
|
const { transactions = [] } = transactionGroup
|
2018-08-06 22:45:56 +02:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
return transactions[0].key === TRANSACTION_TYPE_SHAPESHIFT
|
2018-08-06 22:45:56 +02:00
|
|
|
? (
|
|
|
|
<ShapeShiftTransactionListItem
|
2018-12-09 21:48:06 +01:00
|
|
|
{ ...transactions[0] }
|
2018-08-06 22:45:56 +02:00
|
|
|
key={`shapeshift${index}`}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<TransactionListItem
|
2018-12-09 21:48:06 +01:00
|
|
|
transactionGroup={transactionGroup}
|
|
|
|
key={`${transactionGroup.nonce}:${index}`}
|
2018-12-13 03:33:46 +01:00
|
|
|
showRetry={isPendingTx && this.shouldShowRetry(transactionGroup, index === 0)}
|
2018-12-09 21:48:06 +01:00
|
|
|
showCancel={isPendingTx && this.shouldShowCancel(transactionGroup)}
|
2018-08-06 22:45:56 +02:00
|
|
|
token={selectedToken}
|
2018-08-30 18:51:57 +02:00
|
|
|
assetImages={assetImages}
|
2018-08-06 22:45:56 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-07-31 07:03:20 +02:00
|
|
|
renderEmpty () {
|
|
|
|
return (
|
|
|
|
<div className="transaction-list__empty">
|
|
|
|
<div className="transaction-list__empty-text">
|
|
|
|
{ this.context.t('noTransactions') }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div className="transaction-list">
|
2018-08-01 04:56:51 +02:00
|
|
|
{ this.renderTransactions() }
|
2018-07-31 07:03:20 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|