2018-06-23 08:52:45 +02:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import ConfirmTransactionSwitch from './confirm-transaction-switch.component'
|
2019-03-29 17:05:23 +01:00
|
|
|
import {
|
|
|
|
TOKEN_METHOD_TRANSFER,
|
|
|
|
TOKEN_METHOD_APPROVE,
|
|
|
|
TOKEN_METHOD_TRANSFER_FROM,
|
2019-06-18 14:17:14 +02:00
|
|
|
SEND_ETHER_ACTION_KEY,
|
2019-03-29 17:05:23 +01:00
|
|
|
} from '../../helpers/constants/transactions'
|
2019-06-18 14:17:14 +02:00
|
|
|
import { unconfirmedTransactionsListSelector } from '../../selectors/confirm-transaction'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2019-06-18 14:17:14 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
const { metamask: { unapprovedTxs } } = state
|
|
|
|
const { match: { params = {}, url } } = ownProps
|
|
|
|
const urlId = url && url.match(/\d+/) && url.match(/\d+/)[0]
|
|
|
|
const { id: paramsId } = params
|
|
|
|
const transactionId = paramsId || urlId
|
|
|
|
|
|
|
|
const unconfirmedTransactions = unconfirmedTransactionsListSelector(state)
|
|
|
|
const totalUnconfirmed = unconfirmedTransactions.length
|
|
|
|
const transaction = totalUnconfirmed
|
|
|
|
? unapprovedTxs[transactionId] || unconfirmedTransactions[totalUnconfirmed - 1]
|
|
|
|
: {}
|
2018-06-25 21:06:57 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
2019-06-18 14:17:14 +02:00
|
|
|
txData: transaction,
|
|
|
|
isEtherTransaction: transaction && transaction.transactionCategory === SEND_ETHER_ACTION_KEY,
|
|
|
|
isTokenMethod: [TOKEN_METHOD_APPROVE, TOKEN_METHOD_TRANSFER, TOKEN_METHOD_TRANSFER_FROM].includes(transaction && transaction.transactionCategory && transaction.transactionCategory.toLowerCase()),
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ConfirmTransactionSwitch)
|