mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 18:41:38 +01:00
tx-controller - failed state is a finished state
This commit is contained in:
parent
dc4e3ef241
commit
a91200fd08
@ -138,18 +138,20 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
async newUnapprovedTransaction (txParams) {
|
async newUnapprovedTransaction (txParams) {
|
||||||
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
|
log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`)
|
||||||
const txMeta = await this.addUnapprovedTransaction(txParams)
|
const initialTxMeta = await this.addUnapprovedTransaction(txParams)
|
||||||
this.emit('newUnapprovedTx', txMeta)
|
this.emit('newUnapprovedTx', initialTxMeta)
|
||||||
// listen for tx completion (success, fail)
|
// listen for tx completion (success, fail)
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.txStateManager.once(`${txMeta.id}:finished`, (completedTx) => {
|
this.txStateManager.once(`${initialTxMeta.id}:finished`, (finishedTxMeta) => {
|
||||||
switch (completedTx.status) {
|
switch (finishedTxMeta.status) {
|
||||||
case 'submitted':
|
case 'submitted':
|
||||||
return resolve(completedTx.hash)
|
return resolve(finishedTxMeta.hash)
|
||||||
case 'rejected':
|
case 'rejected':
|
||||||
return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
|
return reject(new Error('MetaMask Tx Signature: User denied transaction signature.'))
|
||||||
|
case 'failed':
|
||||||
|
return reject(new Error(finishedTxMeta.err.message))
|
||||||
default:
|
default:
|
||||||
return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`))
|
return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -240,7 +240,7 @@ module.exports = class TransactionStateManger extends EventEmitter {
|
|||||||
txMeta.status = status
|
txMeta.status = status
|
||||||
this.emit(`${txMeta.id}:${status}`, txId)
|
this.emit(`${txMeta.id}:${status}`, txId)
|
||||||
this.emit(`tx:status-update`, txId, status)
|
this.emit(`tx:status-update`, txId, status)
|
||||||
if (status === 'submitted' || status === 'rejected') {
|
if (['submitted', 'rejected', 'failed'].includes(status)) {
|
||||||
this.emit(`${txMeta.id}:finished`, txMeta)
|
this.emit(`${txMeta.id}:finished`, txMeta)
|
||||||
}
|
}
|
||||||
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
|
this.updateTx(txMeta, `txStateManager: setting status to ${status}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user