mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Remove unused network nonce state (#8395)
This state hasn't been used since #5886. The nonce we display in our UI is now from the background, rather than queried directly from the front-end. This also means we save making this network call each time a pending transaction is added, and each time the transaction list is mounted.
This commit is contained in:
parent
ec08e5c029
commit
5fe25e41b7
@ -1318,41 +1318,6 @@ describe('Actions', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('#updateNetworkNonce', function () {
|
||||
let getTransactionCountSpy
|
||||
|
||||
afterEach(function () {
|
||||
getTransactionCountSpy.restore()
|
||||
})
|
||||
|
||||
it('calls getTransactionCount', async function () {
|
||||
const store = mockStore()
|
||||
getTransactionCountSpy = sinon.spy(global.ethQuery, 'getTransactionCount')
|
||||
|
||||
await store.dispatch(actions.updateNetworkNonce())
|
||||
assert(getTransactionCountSpy.calledOnce)
|
||||
})
|
||||
|
||||
it('errors when getTransactionCount throws', async function () {
|
||||
const store = mockStore()
|
||||
const expectedActions = [
|
||||
{ type: 'DISPLAY_WARNING', value: 'error' },
|
||||
]
|
||||
|
||||
getTransactionCountSpy = sinon.stub(global.ethQuery, 'getTransactionCount')
|
||||
getTransactionCountSpy.callsFake((_, callback) => {
|
||||
callback(new Error('error'))
|
||||
})
|
||||
|
||||
try {
|
||||
await store.dispatch(actions.updateNetworkNonce())
|
||||
assert.fail('Should have thrown error')
|
||||
} catch (_) {
|
||||
assert.deepEqual(store.getActions(), expectedActions)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#setUseBlockie', function () {
|
||||
let setUseBlockieSpy
|
||||
|
||||
|
@ -376,13 +376,4 @@ describe('App State', function () {
|
||||
|
||||
assert.equal(state.gasIsLoading, false)
|
||||
})
|
||||
|
||||
it('sets network nonce', function () {
|
||||
const state = reduceApp(metamaskState, {
|
||||
type: actions.SET_NETWORK_NONCE,
|
||||
value: '33',
|
||||
})
|
||||
|
||||
assert.equal(state.networkNonce, '33')
|
||||
})
|
||||
})
|
||||
|
@ -19,7 +19,6 @@ export default class TransactionList extends PureComponent {
|
||||
pendingTransactions: PropTypes.array,
|
||||
completedTransactions: PropTypes.array,
|
||||
selectedToken: PropTypes.object,
|
||||
updateNetworkNonce: PropTypes.func,
|
||||
assetImages: PropTypes.object,
|
||||
fetchBasicGasAndTimeEstimates: PropTypes.func,
|
||||
fetchGasEstimates: PropTypes.func,
|
||||
@ -30,14 +29,11 @@ export default class TransactionList extends PureComponent {
|
||||
componentDidMount () {
|
||||
const {
|
||||
pendingTransactions,
|
||||
updateNetworkNonce,
|
||||
fetchBasicGasAndTimeEstimates,
|
||||
fetchGasEstimates,
|
||||
transactionTimeFeatureActive,
|
||||
} = this.props
|
||||
|
||||
updateNetworkNonce()
|
||||
|
||||
if (transactionTimeFeatureActive && pendingTransactions.length) {
|
||||
fetchBasicGasAndTimeEstimates()
|
||||
.then(({ blockTime }) => fetchGasEstimates(blockTime))
|
||||
@ -48,16 +44,11 @@ export default class TransactionList extends PureComponent {
|
||||
const { pendingTransactions: prevPendingTransactions = [] } = prevProps
|
||||
const {
|
||||
pendingTransactions = [],
|
||||
updateNetworkNonce,
|
||||
fetchBasicGasAndTimeEstimates,
|
||||
fetchGasEstimates,
|
||||
transactionTimeFeatureActive,
|
||||
} = this.props
|
||||
|
||||
if (pendingTransactions.length > prevPendingTransactions.length) {
|
||||
updateNetworkNonce()
|
||||
}
|
||||
|
||||
const transactionTimeFeatureWasActivated = !prevProps.transactionTimeFeatureActive && transactionTimeFeatureActive
|
||||
const pendingTransactionAdded = pendingTransactions.length > 0 && prevPendingTransactions.length === 0
|
||||
|
||||
|
@ -7,7 +7,6 @@ import {
|
||||
} from '../../../selectors/transactions'
|
||||
import { getSelectedAddress, getAssetImages, getFeatureFlags } from '../../../selectors/selectors'
|
||||
import { selectedTokenSelector } from '../../../selectors/tokens'
|
||||
import { updateNetworkNonce } from '../../../store/actions'
|
||||
import { fetchBasicGasAndTimeEstimates, fetchGasEstimates } from '../../../ducks/gas/gas.duck'
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
@ -26,25 +25,12 @@ const mapStateToProps = (state) => {
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
updateNetworkNonce: (address) => dispatch(updateNetworkNonce(address)),
|
||||
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
|
||||
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
|
||||
}
|
||||
}
|
||||
|
||||
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
||||
const { selectedAddress, ...restStateProps } = stateProps
|
||||
const { updateNetworkNonce, ...restDispatchProps } = dispatchProps
|
||||
|
||||
return {
|
||||
...restStateProps,
|
||||
...restDispatchProps,
|
||||
...ownProps,
|
||||
updateNetworkNonce: () => updateNetworkNonce(selectedAddress),
|
||||
}
|
||||
}
|
||||
|
||||
const TransactionListContainer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(TransactionList)
|
||||
const TransactionListContainer = connect(mapStateToProps, mapDispatchToProps)(TransactionList)
|
||||
|
||||
TransactionListContainer.propTypes = {
|
||||
isWideViewport: PropTypes.bool,
|
||||
|
@ -40,7 +40,6 @@ export default function reduceApp (state = {}, action) {
|
||||
buyView: {},
|
||||
isMouseUser: false,
|
||||
gasIsLoading: false,
|
||||
networkNonce: null,
|
||||
defaultHdPaths: {
|
||||
trezor: `m/44'/60'/0'/0`,
|
||||
ledger: `m/44'/60'/0'/0/0`,
|
||||
@ -314,12 +313,6 @@ export default function reduceApp (state = {}, action) {
|
||||
gasIsLoading: false,
|
||||
}
|
||||
|
||||
case actionConstants.SET_NETWORK_NONCE:
|
||||
return {
|
||||
...appState,
|
||||
networkNonce: action.value,
|
||||
}
|
||||
|
||||
case actionConstants.SET_PREVIOUS_PROVIDER:
|
||||
if (action.value === 'loading') {
|
||||
return appState
|
||||
|
@ -40,7 +40,6 @@ export default {
|
||||
SHOW_SEND_TOKEN_PAGE: 'SHOW_SEND_TOKEN_PAGE',
|
||||
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
||||
SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL',
|
||||
SET_NETWORK_NONCE: 'SET_NETWORK_NONCE',
|
||||
// tx conf screen
|
||||
COMPLETED_TX: 'COMPLETED_TX',
|
||||
TRANSACTION_ERROR: 'TRANSACTION_ERROR',
|
||||
|
@ -1891,28 +1891,6 @@ export function completeOnboarding () {
|
||||
}
|
||||
}
|
||||
|
||||
export function setNetworkNonce (networkNonce) {
|
||||
return {
|
||||
type: actionConstants.SET_NETWORK_NONCE,
|
||||
value: networkNonce,
|
||||
}
|
||||
}
|
||||
|
||||
export function updateNetworkNonce (address) {
|
||||
return (dispatch) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
global.ethQuery.getTransactionCount(address, (err, data) => {
|
||||
if (err) {
|
||||
dispatch(displayWarning(err.message))
|
||||
return reject(err)
|
||||
}
|
||||
dispatch(setNetworkNonce(data))
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function setMouseUserState (isMouseUser) {
|
||||
return {
|
||||
type: actionConstants.SET_MOUSE_USER_STATE,
|
||||
|
Loading…
Reference in New Issue
Block a user