Skip to content

Commit

Permalink
Merge branch 'develop' into remove-accounts-accountTracker-cachedBala…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
tmashuang authored Jul 17, 2020
2 parents b282364 + 7b2218a commit 42c84ac
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,4 +793,5 @@ export default class TransactionController extends EventEmitter {
const currentNetworkTxList = this.txStateManager.getTxList(MAX_MEMSTORE_TX_LIST_SIZE)
this.memStore.updateState({ unapprovedTxs, currentNetworkTxList })
}

}
10 changes: 10 additions & 0 deletions app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,14 @@ export default class TransactionStateManager extends EventEmitter {
const transactionList = this.getFullTxList()
this._saveTxList(transactionList.filter((txMeta) => txMeta.id !== txId))
}

/**
* Filters out the unapproved transactions
*/

clearUnapprovedTxs () {
const transactions = this.getFullTxList()
const nonUnapprovedTxs = transactions.filter((tx) => tx.status !== 'unapproved')
this._saveTxList(nonUnapprovedTxs)
}
}
3 changes: 3 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ export default class MetamaskController extends EventEmitter {
// clear cachedBalances
this.cachedBalancesController.clearCachedBalances()

// clear unapproved transactions
this.txController.txStateManager.clearUnapprovedTxs()

// create new vault
const vault = await keyringController.createNewVaultAndRestore(password, seed)

Expand Down
19 changes: 19 additions & 0 deletions test/unit/app/controllers/transactions/tx-state-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,23 @@ describe('TransactionStateManager', function () {
assert.equal(txStateManager.getFullTxList()[0].id, 2, 'txList should have a id of 2')
})
})

describe('#clearUnapprovedTxs', function () {
it('removes unapproved transactions', function () {
const txMetas = [
{ id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
{ id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId },
{ id: 2, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: otherNetworkId },
{ id: 3, status: 'confirmed', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: otherNetworkId },
]

txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))

txStateManager.clearUnapprovedTxs()

const unapprovedTxList = txStateManager.getFullTxList().filter((tx) => tx.status === 'unapproved')

assert.equal(unapprovedTxList.length, 0)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { connect } from 'react-redux'
import GasModalPageContainer from './gas-modal-page-container.component'
import { captureException } from '@sentry/browser'
import {
hideModal,
setGasLimit,
Expand Down Expand Up @@ -124,6 +125,12 @@ const mapStateToProps = (state, ownProps) => {
conversionRate,
})

let currentTimeEstimate = ''
try {
currentTimeEstimate = getRenderableTimeEstimate(customGasPrice, gasPrices, estimatedTimes)
} catch (error) {
captureException(error)
}

return {
hideBasic,
Expand All @@ -134,7 +141,7 @@ const mapStateToProps = (state, ownProps) => {
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
customGasTotal,
newTotalFiat,
currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, gasPrices, estimatedTimes),
currentTimeEstimate,
blockTime: getBasicGasEstimateBlockTime(state),
customPriceIsSafe: isCustomPriceSafe(state),
maxModeOn,
Expand Down
15 changes: 10 additions & 5 deletions ui/app/hooks/useTransactionTimeRemaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { hexWEIToDecGWEI } from '../helpers/utils/conversions.util'
import { useSelector } from 'react-redux'
import { useRef, useEffect, useState, useMemo } from 'react'
import { isEqual } from 'lodash'
import { captureException } from '@sentry/browser'
import { getRawTimeEstimateData } from '../helpers/utils/gas-time-estimates.util'
import { getCurrentLocale } from '../ducks/metamask/metamask'


/**
* Calculate the number of minutes remaining until the transaction completes.
* @param {number} initialTimeEstimate - timestamp for the projected completion time
Expand Down Expand Up @@ -55,10 +55,15 @@ export function useTransactionTimeRemaining (
// Memoize this value so it can be used as a dependency in the effect below
const initialTimeEstimate = useMemo(() => {
const customGasPrice = Number(hexWEIToDecGWEI(currentGasPrice))
const {
newTimeEstimate,
} = getRawTimeEstimateData(customGasPrice, gasPrices, estimatedTimes)
return newTimeEstimate
try {
const {
newTimeEstimate,
} = getRawTimeEstimateData(customGasPrice, gasPrices, estimatedTimes)
return newTimeEstimate
} catch (error) {
captureException(error)
return NaN
}
}, [ currentGasPrice, gasPrices, estimatedTimes ])

useEffect(() => {
Expand Down

0 comments on commit 42c84ac

Please sign in to comment.