Display value of current pending tx nonce

This commit is contained in:
Victor Baranov 2020-06-10 15:57:50 +03:00
parent 083c37d866
commit a7c51f8607
3 changed files with 37 additions and 0 deletions

View File

@ -444,6 +444,7 @@ module.exports = class MetamaskController extends EventEmitter {
markPasswordForgotten: this.markPasswordForgotten.bind(this),
unMarkPasswordForgotten: this.unMarkPasswordForgotten.bind(this),
getGasPrice: (cb) => cb(null, this.getGasPrice()),
getPendingNonce: nodeify(this.getPendingNonce, this),
// shapeshift
createShapeShiftTx: this.createShapeShiftTx.bind(this),

View File

@ -29,6 +29,18 @@ const optionalDataValueStyle = {
}
class SendTransactionScreen extends PersistentForm {
constructor (props) {
super(props)
this.state = {
pendingNonce: null,
}
}
async getPendingNonce () {
const pendingNonce = await this.props.dispatch(actions.getPendingNonce(this.props.address))
this.setState({pendingNonce: pendingNonce})
}
render () {
this.persistentFormParentId = 'send-tx-form'
@ -117,12 +129,17 @@ class SendTransactionScreen extends PersistentForm {
dataset={{
persistentFormid: 'tx-custom-nonce',
}}
defaultValue={this.state.pendingNonce}
/>
</section>
</div>
)
}
componentDidMount () {
this.getPendingNonce()
}
componentWillUnmount () {
this.props.dispatch(actions.displayWarning(''))
}

View File

@ -188,6 +188,7 @@ const actions = {
signTokenTx: signTokenTx,
updateTransaction,
updateAndApproveTx,
getPendingNonce,
cancelTx,
cancelTxs,
completedTx: completedTx,
@ -1304,6 +1305,24 @@ function updateAndApproveTx (txData) {
}
}
function getPendingNonce (address) {
log.info('actions: getPendingNonce')
return (dispatch) => {
log.debug(`actions calling background.getPendingNonce`)
dispatch(actions.showLoadingIndication())
return new Promise((resolve, reject) => {
background.getPendingNonce(address, (err, nonce) => {
if (err) {
dispatch(actions.displayWarning(err.message))
return reject(err)
}
dispatch(actions.hideLoadingIndication())
resolve(nonce)
})
})
}
}
function completedTx (id) {
return {
type: actions.COMPLETED_TX,