mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Get nonce for showing retry button using ethQuery transaction count.
This commit is contained in:
parent
1d4ee6bf76
commit
e98c3b4c01
@ -14,6 +14,11 @@ QUnit.test('renders list items successfully', (assert) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
global.ethQuery = global.ethQuery || {}
|
||||||
|
global.ethQuery.getTransactionCount = (_, cb) => {
|
||||||
|
cb(null, '0x3')
|
||||||
|
}
|
||||||
|
|
||||||
async function runTxListItemsTest (assert, done) {
|
async function runTxListItemsTest (assert, done) {
|
||||||
console.log('*** start runTxListItemsTest')
|
console.log('*** start runTxListItemsTest')
|
||||||
const selectState = await queryAsync($, 'select')
|
const selectState = await queryAsync($, 'select')
|
||||||
|
@ -143,6 +143,8 @@ var actions = {
|
|||||||
exportAccountComplete,
|
exportAccountComplete,
|
||||||
SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL',
|
SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL',
|
||||||
setAccountLabel,
|
setAccountLabel,
|
||||||
|
updateNetworkNonce,
|
||||||
|
SET_NETWORK_NONCE: 'SET_NETWORK_NONCE',
|
||||||
// tx conf screen
|
// tx conf screen
|
||||||
COMPLETED_TX: 'COMPLETED_TX',
|
COMPLETED_TX: 'COMPLETED_TX',
|
||||||
TRANSACTION_ERROR: 'TRANSACTION_ERROR',
|
TRANSACTION_ERROR: 'TRANSACTION_ERROR',
|
||||||
@ -2116,6 +2118,24 @@ function updateFeatureFlags (updatedFeatureFlags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setNetworkNonce (networkNonce) {
|
||||||
|
return {
|
||||||
|
type: actions.SET_NETWORK_NONCE,
|
||||||
|
value: networkNonce,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNetworkNonce (address) {
|
||||||
|
return (dispatch) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
global.ethQuery.getTransactionCount(address, (err, data) => {
|
||||||
|
dispatch(setNetworkNonce(data))
|
||||||
|
resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setMouseUserState (isMouseUser) {
|
function setMouseUserState (isMouseUser) {
|
||||||
return {
|
return {
|
||||||
type: actions.SET_MOUSE_USER_STATE,
|
type: actions.SET_MOUSE_USER_STATE,
|
||||||
|
@ -35,6 +35,7 @@ function mapStateToProps (state) {
|
|||||||
currentCurrency: getCurrentCurrency(state),
|
currentCurrency: getCurrentCurrency(state),
|
||||||
contractExchangeRates: state.metamask.contractExchangeRates,
|
contractExchangeRates: state.metamask.contractExchangeRates,
|
||||||
selectedAddressTxList: state.metamask.selectedAddressTxList,
|
selectedAddressTxList: state.metamask.selectedAddressTxList,
|
||||||
|
networkNonce: state.appState.networkNonce,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +210,7 @@ TxListItem.prototype.showRetryButton = function () {
|
|||||||
selectedAddressTxList,
|
selectedAddressTxList,
|
||||||
transactionId,
|
transactionId,
|
||||||
txParams,
|
txParams,
|
||||||
|
networkNonce,
|
||||||
} = this.props
|
} = this.props
|
||||||
if (!txParams) {
|
if (!txParams) {
|
||||||
return false
|
return false
|
||||||
@ -222,11 +224,7 @@ TxListItem.prototype.showRetryButton = function () {
|
|||||||
const currentTxIsLatestWithNonce = lastSubmittedTxWithCurrentNonce &&
|
const currentTxIsLatestWithNonce = lastSubmittedTxWithCurrentNonce &&
|
||||||
lastSubmittedTxWithCurrentNonce.id === transactionId
|
lastSubmittedTxWithCurrentNonce.id === transactionId
|
||||||
if (currentSubmittedTxs.length > 0) {
|
if (currentSubmittedTxs.length > 0) {
|
||||||
const earliestSubmitted = currentSubmittedTxs.reduce((tx1, tx2) => {
|
currentTxSharesEarliestNonce = currentNonce === networkNonce
|
||||||
if (tx1.submittedTime < tx2.submittedTime) return tx1
|
|
||||||
return tx2
|
|
||||||
})
|
|
||||||
currentTxSharesEarliestNonce = currentNonce === earliestSubmitted.txParams.nonce
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentTxSharesEarliestNonce && currentTxIsLatestWithNonce && Date.now() - transactionSubmittedTime > 30000
|
return currentTxSharesEarliestNonce && currentTxIsLatestWithNonce && Date.now() - transactionSubmittedTime > 30000
|
||||||
|
@ -8,7 +8,7 @@ const selectors = require('../selectors')
|
|||||||
const TxListItem = require('./tx-list-item')
|
const TxListItem = require('./tx-list-item')
|
||||||
const ShiftListItem = require('./shift-list-item')
|
const ShiftListItem = require('./shift-list-item')
|
||||||
const { formatDate } = require('../util')
|
const { formatDate } = require('../util')
|
||||||
const { showConfTxPage } = require('../actions')
|
const { showConfTxPage, updateNetworkNonce } = require('../actions')
|
||||||
const classnames = require('classnames')
|
const classnames = require('classnames')
|
||||||
const { tokenInfoGetter } = require('../token-util')
|
const { tokenInfoGetter } = require('../token-util')
|
||||||
const { withRouter } = require('react-router-dom')
|
const { withRouter } = require('react-router-dom')
|
||||||
@ -28,12 +28,14 @@ function mapStateToProps (state) {
|
|||||||
return {
|
return {
|
||||||
txsToRender: selectors.transactionsSelector(state),
|
txsToRender: selectors.transactionsSelector(state),
|
||||||
conversionRate: selectors.conversionRateSelector(state),
|
conversionRate: selectors.conversionRateSelector(state),
|
||||||
|
selectedAddress: selectors.getSelectedAddress(state),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps (dispatch) {
|
function mapDispatchToProps (dispatch) {
|
||||||
return {
|
return {
|
||||||
showConfTxPage: ({ id }) => dispatch(showConfTxPage({ id })),
|
showConfTxPage: ({ id }) => dispatch(showConfTxPage({ id })),
|
||||||
|
updateNetworkNonce: (address) => dispatch(updateNetworkNonce(address))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +46,20 @@ function TxList () {
|
|||||||
|
|
||||||
TxList.prototype.componentWillMount = function () {
|
TxList.prototype.componentWillMount = function () {
|
||||||
this.tokenInfoGetter = tokenInfoGetter()
|
this.tokenInfoGetter = tokenInfoGetter()
|
||||||
|
this.props.updateNetworkNonce(this.props.selectedAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
TxList.prototype.componentDidUpdate = function (prevProps) {
|
||||||
|
const oldTxsToRender = prevProps.txsToRender
|
||||||
|
const {
|
||||||
|
txsToRender: newTxsToRender,
|
||||||
|
selectedAddress,
|
||||||
|
updateNetworkNonce,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
|
if (newTxsToRender.length > oldTxsToRender.length) {
|
||||||
|
updateNetworkNonce(selectedAddress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TxList.prototype.render = function () {
|
TxList.prototype.render = function () {
|
||||||
|
@ -65,6 +65,7 @@ function reduceApp (state, action) {
|
|||||||
buyView: {},
|
buyView: {},
|
||||||
isMouseUser: false,
|
isMouseUser: false,
|
||||||
gasIsLoading: false,
|
gasIsLoading: false,
|
||||||
|
networkNonce: null,
|
||||||
}, state.appState)
|
}, state.appState)
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@ -701,6 +702,11 @@ function reduceApp (state, action) {
|
|||||||
gasIsLoading: false,
|
gasIsLoading: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case actions.SET_NETWORK_NONCE:
|
||||||
|
return extend(appState, {
|
||||||
|
networkNonce: action.value,
|
||||||
|
})
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return appState
|
return appState
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user