mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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 () {
|
describe('#setUseBlockie', function () {
|
||||||
let setUseBlockieSpy
|
let setUseBlockieSpy
|
||||||
|
|
||||||
|
@ -376,13 +376,4 @@ describe('App State', function () {
|
|||||||
|
|
||||||
assert.equal(state.gasIsLoading, false)
|
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,
|
pendingTransactions: PropTypes.array,
|
||||||
completedTransactions: PropTypes.array,
|
completedTransactions: PropTypes.array,
|
||||||
selectedToken: PropTypes.object,
|
selectedToken: PropTypes.object,
|
||||||
updateNetworkNonce: PropTypes.func,
|
|
||||||
assetImages: PropTypes.object,
|
assetImages: PropTypes.object,
|
||||||
fetchBasicGasAndTimeEstimates: PropTypes.func,
|
fetchBasicGasAndTimeEstimates: PropTypes.func,
|
||||||
fetchGasEstimates: PropTypes.func,
|
fetchGasEstimates: PropTypes.func,
|
||||||
@ -30,14 +29,11 @@ export default class TransactionList extends PureComponent {
|
|||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const {
|
const {
|
||||||
pendingTransactions,
|
pendingTransactions,
|
||||||
updateNetworkNonce,
|
|
||||||
fetchBasicGasAndTimeEstimates,
|
fetchBasicGasAndTimeEstimates,
|
||||||
fetchGasEstimates,
|
fetchGasEstimates,
|
||||||
transactionTimeFeatureActive,
|
transactionTimeFeatureActive,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
updateNetworkNonce()
|
|
||||||
|
|
||||||
if (transactionTimeFeatureActive && pendingTransactions.length) {
|
if (transactionTimeFeatureActive && pendingTransactions.length) {
|
||||||
fetchBasicGasAndTimeEstimates()
|
fetchBasicGasAndTimeEstimates()
|
||||||
.then(({ blockTime }) => fetchGasEstimates(blockTime))
|
.then(({ blockTime }) => fetchGasEstimates(blockTime))
|
||||||
@ -48,16 +44,11 @@ export default class TransactionList extends PureComponent {
|
|||||||
const { pendingTransactions: prevPendingTransactions = [] } = prevProps
|
const { pendingTransactions: prevPendingTransactions = [] } = prevProps
|
||||||
const {
|
const {
|
||||||
pendingTransactions = [],
|
pendingTransactions = [],
|
||||||
updateNetworkNonce,
|
|
||||||
fetchBasicGasAndTimeEstimates,
|
fetchBasicGasAndTimeEstimates,
|
||||||
fetchGasEstimates,
|
fetchGasEstimates,
|
||||||
transactionTimeFeatureActive,
|
transactionTimeFeatureActive,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
if (pendingTransactions.length > prevPendingTransactions.length) {
|
|
||||||
updateNetworkNonce()
|
|
||||||
}
|
|
||||||
|
|
||||||
const transactionTimeFeatureWasActivated = !prevProps.transactionTimeFeatureActive && transactionTimeFeatureActive
|
const transactionTimeFeatureWasActivated = !prevProps.transactionTimeFeatureActive && transactionTimeFeatureActive
|
||||||
const pendingTransactionAdded = pendingTransactions.length > 0 && prevPendingTransactions.length === 0
|
const pendingTransactionAdded = pendingTransactions.length > 0 && prevPendingTransactions.length === 0
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
} from '../../../selectors/transactions'
|
} from '../../../selectors/transactions'
|
||||||
import { getSelectedAddress, getAssetImages, getFeatureFlags } from '../../../selectors/selectors'
|
import { getSelectedAddress, getAssetImages, getFeatureFlags } from '../../../selectors/selectors'
|
||||||
import { selectedTokenSelector } from '../../../selectors/tokens'
|
import { selectedTokenSelector } from '../../../selectors/tokens'
|
||||||
import { updateNetworkNonce } from '../../../store/actions'
|
|
||||||
import { fetchBasicGasAndTimeEstimates, fetchGasEstimates } from '../../../ducks/gas/gas.duck'
|
import { fetchBasicGasAndTimeEstimates, fetchGasEstimates } from '../../../ducks/gas/gas.duck'
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
@ -26,25 +25,12 @@ const mapStateToProps = (state) => {
|
|||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => {
|
const mapDispatchToProps = (dispatch) => {
|
||||||
return {
|
return {
|
||||||
updateNetworkNonce: (address) => dispatch(updateNetworkNonce(address)),
|
|
||||||
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
|
fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)),
|
||||||
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
|
fetchBasicGasAndTimeEstimates: () => dispatch(fetchBasicGasAndTimeEstimates()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
const TransactionListContainer = connect(mapStateToProps, mapDispatchToProps)(TransactionList)
|
||||||
const { selectedAddress, ...restStateProps } = stateProps
|
|
||||||
const { updateNetworkNonce, ...restDispatchProps } = dispatchProps
|
|
||||||
|
|
||||||
return {
|
|
||||||
...restStateProps,
|
|
||||||
...restDispatchProps,
|
|
||||||
...ownProps,
|
|
||||||
updateNetworkNonce: () => updateNetworkNonce(selectedAddress),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const TransactionListContainer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(TransactionList)
|
|
||||||
|
|
||||||
TransactionListContainer.propTypes = {
|
TransactionListContainer.propTypes = {
|
||||||
isWideViewport: PropTypes.bool,
|
isWideViewport: PropTypes.bool,
|
||||||
|
@ -40,7 +40,6 @@ export default function reduceApp (state = {}, action) {
|
|||||||
buyView: {},
|
buyView: {},
|
||||||
isMouseUser: false,
|
isMouseUser: false,
|
||||||
gasIsLoading: false,
|
gasIsLoading: false,
|
||||||
networkNonce: null,
|
|
||||||
defaultHdPaths: {
|
defaultHdPaths: {
|
||||||
trezor: `m/44'/60'/0'/0`,
|
trezor: `m/44'/60'/0'/0`,
|
||||||
ledger: `m/44'/60'/0'/0/0`,
|
ledger: `m/44'/60'/0'/0/0`,
|
||||||
@ -314,12 +313,6 @@ export default function reduceApp (state = {}, action) {
|
|||||||
gasIsLoading: false,
|
gasIsLoading: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
case actionConstants.SET_NETWORK_NONCE:
|
|
||||||
return {
|
|
||||||
...appState,
|
|
||||||
networkNonce: action.value,
|
|
||||||
}
|
|
||||||
|
|
||||||
case actionConstants.SET_PREVIOUS_PROVIDER:
|
case actionConstants.SET_PREVIOUS_PROVIDER:
|
||||||
if (action.value === 'loading') {
|
if (action.value === 'loading') {
|
||||||
return appState
|
return appState
|
||||||
|
@ -40,7 +40,6 @@ export default {
|
|||||||
SHOW_SEND_TOKEN_PAGE: 'SHOW_SEND_TOKEN_PAGE',
|
SHOW_SEND_TOKEN_PAGE: 'SHOW_SEND_TOKEN_PAGE',
|
||||||
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
||||||
SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL',
|
SET_ACCOUNT_LABEL: 'SET_ACCOUNT_LABEL',
|
||||||
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',
|
||||||
|
@ -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) {
|
export function setMouseUserState (isMouseUser) {
|
||||||
return {
|
return {
|
||||||
type: actionConstants.SET_MOUSE_USER_STATE,
|
type: actionConstants.SET_MOUSE_USER_STATE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user