Custom nonce fixes (#7240)

* Allow default nextNonce to be the custom nonce in cases where highest locally pending is higher than nextNonce

* Reset custom nonce in cases of transaction submission failures

* Make the recommended nonce in the custom nonce field the true 'nextNonce'

* Revert automatic setting of custom nonce to nextNonce

* Make the nextNonce the default placeholder value

* Fix getNextNonce

* Remove unused nonceFieldPlaceholder message

* Fix nits in getPendingNonce and getNextNonce

* Properly handle errors in getNextNonce

* Improve placeholder and value defaults in custom nonce field

* Remove custom error message from getNextNonce
feature/default_network_editable
Dan J Miller 5 years ago committed by GitHub
parent 45a8fdebf7
commit e6e8897434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/_locales/en/messages.json
  2. 18
      app/scripts/metamask-controller.js
  3. 5
      ui/app/pages/confirm-transaction-base/confirm-transaction-base.component.js
  4. 6
      ui/app/store/actions.js

@ -198,9 +198,6 @@
"nonceField": {
"message": "Customize transaction nonce"
},
"nonceFieldPlaceholder": {
"message": "Automatically calculate"
},
"nonceFieldHeading": {
"message": "Custom Nonce"
},

@ -520,6 +520,7 @@ module.exports = class MetamaskController extends EventEmitter {
isNonceTaken: nodeify(txController.isNonceTaken, txController),
estimateGas: nodeify(this.estimateGas, this),
getPendingNonce: nodeify(this.getPendingNonce, this),
getNextNonce: nodeify(this.getNextNonce, this),
// messageManager
signMessage: nodeify(this.signMessage, this),
@ -1612,13 +1613,28 @@ module.exports = class MetamaskController extends EventEmitter {
* @returns Promise<number>
*/
async getPendingNonce (address) {
const { nonceDetails, releaseLock} = await this.txController.nonceTracker.getNonceLock(address)
const { nonceDetails, releaseLock } = await this.txController.nonceTracker.getNonceLock(address)
const pendingNonce = nonceDetails.params.highestSuggested
releaseLock()
return pendingNonce
}
/**
* Returns the next nonce according to the nonce-tracker
* @param address {string} - The hex string address for the transaction
* @returns Promise<number>
*/
async getNextNonce (address) {
let nonceLock
try {
nonceLock = await this.txController.nonceTracker.getNonceLock(address)
} finally {
nonceLock.releaseLock()
}
return nonceLock.nextNonce
}
//=============================================================================
// CONFIG
//=============================================================================

@ -282,7 +282,7 @@ export default class ConfirmTransactionBase extends Component {
<TextField
type="number"
min="0"
placeholder={ this.context.t('nonceFieldPlaceholder') }
placeholder={ nextNonce }
onChange={({ target: { value } }) => {
if (!value.length || Number(value) < 0) {
updateCustomNonce('')
@ -293,7 +293,7 @@ export default class ConfirmTransactionBase extends Component {
}}
fullWidth
margin="dense"
value={customNonceValue || nextNonce || ''}
value={ customNonceValue || '' }
/>
</div>
</div>
@ -494,6 +494,7 @@ export default class ConfirmTransactionBase extends Component {
submitting: false,
submitError: error.message,
})
updateCustomNonce('')
})
}
})

@ -2932,13 +2932,13 @@ function getNextNonce () {
return (dispatch, getState) => {
const address = getState().metamask.selectedAddress
return new Promise((resolve, reject) => {
background.getPendingNonce(address, (err, pendingNonce) => {
background.getNextNonce(address, (err, nextNonce) => {
if (err) {
dispatch(actions.displayWarning(err.message))
return reject(err)
}
dispatch(setNextNonce(pendingNonce))
resolve(pendingNonce)
dispatch(setNextNonce(nextNonce))
resolve(nextNonce)
})
})
}

Loading…
Cancel
Save