mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update retry transaction logic to use network nonce
This commit is contained in:
parent
5dcd8ceb7b
commit
b48a293af0
@ -20,6 +20,20 @@ export default class TransactionList extends PureComponent {
|
||||
completedTransactions: PropTypes.array,
|
||||
transactionToRetry: PropTypes.object,
|
||||
selectedToken: PropTypes.object,
|
||||
updateNetworkNonce: PropTypes.func,
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
this.props.updateNetworkNonce()
|
||||
}
|
||||
|
||||
componentDidUpdate (prevProps) {
|
||||
const { pendingTransactions: prevPendingTransactions = [] } = prevProps
|
||||
const { pendingTransactions = [], updateNetworkNonce } = this.props
|
||||
|
||||
if (pendingTransactions.length > prevPendingTransactions.length) {
|
||||
updateNetworkNonce()
|
||||
}
|
||||
}
|
||||
|
||||
shouldShowRetry = transaction => {
|
||||
|
@ -7,22 +7,44 @@ import {
|
||||
submittedPendingTransactionsSelector,
|
||||
completedTransactionsSelector,
|
||||
} from '../../selectors/transactions'
|
||||
import { getSelectedAddress } from '../../selectors'
|
||||
import { selectedTokenSelector } from '../../selectors/tokens'
|
||||
import { getLatestSubmittedTxWithEarliestNonce } from '../../helpers/transactions.util'
|
||||
import { getLatestSubmittedTxWithNonce } from '../../helpers/transactions.util'
|
||||
import { updateNetworkNonce } from '../../actions'
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const pendingTransactions = pendingTransactionsSelector(state)
|
||||
const submittedPendingTransactions = submittedPendingTransactionsSelector(state)
|
||||
const networkNonce = state.appState.networkNonce
|
||||
|
||||
return {
|
||||
completedTransactions: completedTransactionsSelector(state),
|
||||
pendingTransactions,
|
||||
transactionToRetry: getLatestSubmittedTxWithEarliestNonce(submittedPendingTransactions),
|
||||
transactionToRetry: getLatestSubmittedTxWithNonce(submittedPendingTransactions, networkNonce),
|
||||
selectedToken: selectedTokenSelector(state),
|
||||
selectedAddress: getSelectedAddress(state),
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
updateNetworkNonce: address => dispatch(updateNetworkNonce(address)),
|
||||
}
|
||||
}
|
||||
|
||||
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
||||
const { selectedAddress, ...restStateProps } = stateProps
|
||||
const { updateNetworkNonce, ...restDispatchProps } = dispatchProps
|
||||
|
||||
return {
|
||||
...restStateProps,
|
||||
...restDispatchProps,
|
||||
...ownProps,
|
||||
updateNetworkNonce: () => updateNetworkNonce(selectedAddress),
|
||||
}
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withRouter,
|
||||
connect(mapStateToProps)
|
||||
connect(mapStateToProps, mapDispatchToProps, mergeProps)
|
||||
)(TransactionList)
|
||||
|
@ -2,7 +2,6 @@ import ethUtil from 'ethereumjs-util'
|
||||
import MethodRegistry from 'eth-method-registry'
|
||||
import abi from 'human-standard-token-abi'
|
||||
import abiDecoder from 'abi-decoder'
|
||||
import { hexToDecimal } from './conversions.util'
|
||||
|
||||
import {
|
||||
TOKEN_METHOD_TRANSFER,
|
||||
@ -76,21 +75,20 @@ export function getTransactionActionKey (transaction, methodData) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getLatestSubmittedTxWithEarliestNonce (transactions = []) {
|
||||
export function getLatestSubmittedTxWithNonce (transactions = [], nonce = '0x0') {
|
||||
if (!transactions.length) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return transactions.reduce((acc, current) => {
|
||||
const accNonce = hexToDecimal(acc.nonce)
|
||||
const currentNonce = hexToDecimal(current.nonce)
|
||||
const { submittedTime, txParams: { nonce: currentNonce } = {} } = current
|
||||
|
||||
if (currentNonce < accNonce) {
|
||||
return current
|
||||
} else if (currentNonce === accNonce) {
|
||||
return current.submittedTime > acc.submittedTime ? current : acc
|
||||
if (currentNonce === nonce) {
|
||||
return acc.submittedTime
|
||||
? submittedTime > acc.submittedTime ? current : acc
|
||||
: current
|
||||
} else {
|
||||
return acc
|
||||
}
|
||||
})
|
||||
}, {})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user