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

call this.txStateManager.setTxStatusConfirmed before async call in confirmTransaction (#9522)

* call this.txStateManager.setTxStatusConfirmed before async call in confirmTransaction in the transactions controller

* Clone txMeta before setTxStatusConfirmed in confirmTransaction

* Correctly updateTx in confirmTransaction

* Track swaps event only if it is a swap transaction
This commit is contained in:
Dan J Miller 2020-10-08 16:01:35 -02:30 committed by GitHub
parent e20cf61915
commit 325dd9c036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import { ethers } from 'ethers'
import NonceTracker from 'nonce-tracker' import NonceTracker from 'nonce-tracker'
import log from 'loglevel' import log from 'loglevel'
import BigNumber from 'bignumber.js' import BigNumber from 'bignumber.js'
import { cloneDeep } from 'lodash'
import { import {
TOKEN_METHOD_APPROVE, TOKEN_METHOD_APPROVE,
TOKEN_METHOD_TRANSFER, TOKEN_METHOD_TRANSFER,
@ -562,9 +563,9 @@ export default class TransactionController extends EventEmitter {
async confirmTransaction (txId, txReceipt) { async confirmTransaction (txId, txReceipt) {
// get the txReceipt before marking the transaction confirmed // get the txReceipt before marking the transaction confirmed
// to ensure the receipt is gotten before the ui revives the tx // to ensure the receipt is gotten before the ui revives the tx
const txMeta = this.txStateManager.getTx(txId) const initialTxMeta = this.txStateManager.getTx(txId)
if (!txMeta) { if (!initialTxMeta) {
return return
} }
@ -575,24 +576,25 @@ export default class TransactionController extends EventEmitter {
? txReceipt.gasUsed ? txReceipt.gasUsed
: txReceipt.gasUsed.toString(16) : txReceipt.gasUsed.toString(16)
txMeta.txReceipt = { initialTxMeta.txReceipt = {
...txReceipt, ...txReceipt,
gasUsed, gasUsed,
} }
this.txStateManager.setTxStatusConfirmed(txId)
this._markNonceDuplicatesDropped(txId)
if (txMeta.transactionCategory === SWAP) { this.txStateManager.updateTx(initialTxMeta, 'transactions#confirmTransaction - add txReceipt')
if (initialTxMeta.transactionCategory === SWAP) {
const txMeta = cloneDeep(initialTxMeta)
const postTxBalance = await this.query.getBalance(txMeta.txParams.from) const postTxBalance = await this.query.getBalance(txMeta.txParams.from)
txMeta.postTxBalance = postTxBalance.toString(16) txMeta.postTxBalance = postTxBalance.toString(16)
this._trackSwapsMetrics(txMeta)
} }
this.txStateManager.updateTx(txMeta, 'transactions#confirmTransaction - add txReceipt')
this._trackSwapsMetrics(txMeta)
} catch (err) { } catch (err) {
log.error(err) log.error(err)
} }
this.txStateManager.setTxStatusConfirmed(txId)
this._markNonceDuplicatesDropped(txId)
} }
/** /**