1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #5310 from MetaMask/getPendingNonce-hotfix

Adds getPendingNonce method to provider initialization in metamask-controller.
This commit is contained in:
Thomas Huang 2018-09-24 08:45:25 -05:00 committed by GitHub
commit 82ec86d953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -38,6 +38,6 @@ function createPendingNonceMiddleware ({ getPendingNonce }) {
const address = req.params[0] const address = req.params[0]
const blockRef = req.params[1] const blockRef = req.params[1]
if (blockRef !== 'pending') return next() if (blockRef !== 'pending') return next()
req.result = await getPendingNonce(address) res.result = await getPendingNonce(address)
}) })
} }

View File

@ -268,6 +268,7 @@ module.exports = class MetamaskController extends EventEmitter {
// msg signing // msg signing
processEthSignMessage: this.newUnsignedMessage.bind(this), processEthSignMessage: this.newUnsignedMessage.bind(this),
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
getPendingNonce: this.getPendingNonce.bind(this),
} }
const providerProxy = this.networkController.initializeProvider(providerOpts) const providerProxy = this.networkController.initializeProvider(providerOpts)
return providerProxy return providerProxy
@ -1362,6 +1363,19 @@ module.exports = class MetamaskController extends EventEmitter {
return '0x' + percentileNumBn.mul(GWEI_BN).toString(16) return '0x' + percentileNumBn.mul(GWEI_BN).toString(16)
} }
/**
* Returns the nonce that will be associated with a transaction once approved
* @param address {string} - The hex string address for the transaction
* @returns Promise<number>
*/
async getPendingNonce (address) {
const { nonceDetails, releaseLock} = await this.txController.nonceTracker.getNonceLock(address)
const pendingNonce = nonceDetails.params.highestSuggested
releaseLock()
return pendingNonce
}
//============================================================================= //=============================================================================
// CONFIG // CONFIG
//============================================================================= //=============================================================================