Skip to content

Commit

Permalink
Catch gas estimate errors
Browse files Browse the repository at this point in the history
There were two cases where bad gas estimate data was resulting in
crashes. These two places have been wrapped in a `try ... catch` to
handle the absence of gas estimate data.

The errors are still reported to Sentry so that we can track down the
root cause of this corrupted gas estimate data at some point in the
future. We plan on adding additional context to Sentry soon that should
help with this.

Fixes #8992
  • Loading branch information
Gudahtt committed Jul 16, 2020
1 parent 022ef13 commit 97484d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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 97484d6

Please sign in to comment.