mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
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
This commit is contained in:
parent
45a8fdebf7
commit
e6e8897434
@ -198,9 +198,6 @@
|
|||||||
"nonceField": {
|
"nonceField": {
|
||||||
"message": "Customize transaction nonce"
|
"message": "Customize transaction nonce"
|
||||||
},
|
},
|
||||||
"nonceFieldPlaceholder": {
|
|
||||||
"message": "Automatically calculate"
|
|
||||||
},
|
|
||||||
"nonceFieldHeading": {
|
"nonceFieldHeading": {
|
||||||
"message": "Custom Nonce"
|
"message": "Custom Nonce"
|
||||||
},
|
},
|
||||||
|
@ -520,6 +520,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
isNonceTaken: nodeify(txController.isNonceTaken, txController),
|
isNonceTaken: nodeify(txController.isNonceTaken, txController),
|
||||||
estimateGas: nodeify(this.estimateGas, this),
|
estimateGas: nodeify(this.estimateGas, this),
|
||||||
getPendingNonce: nodeify(this.getPendingNonce, this),
|
getPendingNonce: nodeify(this.getPendingNonce, this),
|
||||||
|
getNextNonce: nodeify(this.getNextNonce, this),
|
||||||
|
|
||||||
// messageManager
|
// messageManager
|
||||||
signMessage: nodeify(this.signMessage, this),
|
signMessage: nodeify(this.signMessage, this),
|
||||||
@ -1612,13 +1613,28 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
* @returns Promise<number>
|
* @returns Promise<number>
|
||||||
*/
|
*/
|
||||||
async getPendingNonce (address) {
|
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
|
const pendingNonce = nonceDetails.params.highestSuggested
|
||||||
|
|
||||||
releaseLock()
|
releaseLock()
|
||||||
return pendingNonce
|
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
|
// CONFIG
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
@ -282,7 +282,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
<TextField
|
<TextField
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
placeholder={ this.context.t('nonceFieldPlaceholder') }
|
placeholder={ nextNonce }
|
||||||
onChange={({ target: { value } }) => {
|
onChange={({ target: { value } }) => {
|
||||||
if (!value.length || Number(value) < 0) {
|
if (!value.length || Number(value) < 0) {
|
||||||
updateCustomNonce('')
|
updateCustomNonce('')
|
||||||
@ -293,7 +293,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
margin="dense"
|
margin="dense"
|
||||||
value={customNonceValue || nextNonce || ''}
|
value={ customNonceValue || '' }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -494,6 +494,7 @@ export default class ConfirmTransactionBase extends Component {
|
|||||||
submitting: false,
|
submitting: false,
|
||||||
submitError: error.message,
|
submitError: error.message,
|
||||||
})
|
})
|
||||||
|
updateCustomNonce('')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -2932,13 +2932,13 @@ function getNextNonce () {
|
|||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const address = getState().metamask.selectedAddress
|
const address = getState().metamask.selectedAddress
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
background.getPendingNonce(address, (err, pendingNonce) => {
|
background.getNextNonce(address, (err, nextNonce) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
dispatch(actions.displayWarning(err.message))
|
dispatch(actions.displayWarning(err.message))
|
||||||
return reject(err)
|
return reject(err)
|
||||||
}
|
}
|
||||||
dispatch(setNextNonce(pendingNonce))
|
dispatch(setNextNonce(nextNonce))
|
||||||
resolve(pendingNonce)
|
resolve(nextNonce)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user