mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix gas_fees properties collected for swaps analytics events (#9727)
This commit is contained in:
parent
14d85b1332
commit
bcd5f2a7c1
@ -155,7 +155,7 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.currencyRateController = new CurrencyRateController(
|
this.currencyRateController = new CurrencyRateController(
|
||||||
undefined,
|
{ includeUSDRate: true },
|
||||||
initState.CurrencyController,
|
initState.CurrencyController,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ describe('gas-modal-page-container container', function () {
|
|||||||
},
|
},
|
||||||
currentCurrency: 'abc',
|
currentCurrency: 'abc',
|
||||||
conversionRate: 50,
|
conversionRate: 50,
|
||||||
|
usdConversionRate: 123,
|
||||||
preferences: {
|
preferences: {
|
||||||
showFiatInTestnets: false,
|
showFiatInTestnets: false,
|
||||||
},
|
},
|
||||||
|
@ -49,7 +49,7 @@ import { calcTokenAmount } from '../../helpers/utils/token-util'
|
|||||||
import {
|
import {
|
||||||
getSelectedAccount,
|
getSelectedAccount,
|
||||||
getTokenExchangeRates,
|
getTokenExchangeRates,
|
||||||
conversionRateSelector as getConversionRate,
|
getUSDConversionRate,
|
||||||
} from '../../selectors'
|
} from '../../selectors'
|
||||||
import {
|
import {
|
||||||
ERROR_FETCHING_QUOTES,
|
ERROR_FETCHING_QUOTES,
|
||||||
@ -58,7 +58,6 @@ import {
|
|||||||
SWAP_FAILED_ERROR,
|
SWAP_FAILED_ERROR,
|
||||||
SWAPS_FETCH_ORDER_CONFLICT,
|
SWAPS_FETCH_ORDER_CONFLICT,
|
||||||
} from '../../helpers/constants/swaps'
|
} from '../../helpers/constants/swaps'
|
||||||
import { formatCurrency } from '../../helpers/utils/confirm-tx.util'
|
|
||||||
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'
|
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'
|
||||||
|
|
||||||
const GAS_PRICES_LOADING_STATES = {
|
const GAS_PRICES_LOADING_STATES = {
|
||||||
@ -613,7 +612,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
|
|||||||
usedTradeTxParams.gas = maxGasLimit
|
usedTradeTxParams.gas = maxGasLimit
|
||||||
usedTradeTxParams.gasPrice = usedGasPrice
|
usedTradeTxParams.gasPrice = usedGasPrice
|
||||||
|
|
||||||
const conversionRate = getConversionRate(state)
|
const usdConversionRate = getUSDConversionRate(state)
|
||||||
const destinationValue = calcTokenAmount(
|
const destinationValue = calcTokenAmount(
|
||||||
usedQuote.destinationAmount,
|
usedQuote.destinationAmount,
|
||||||
destinationTokenInfo.decimals || 18,
|
destinationTokenInfo.decimals || 18,
|
||||||
@ -624,10 +623,10 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
|
|||||||
const totalGasLimitEstimate = new BigNumber(usedGasLimitEstimate, 16)
|
const totalGasLimitEstimate = new BigNumber(usedGasLimitEstimate, 16)
|
||||||
.plus(usedQuote.approvalNeeded?.gas || '0x0', 16)
|
.plus(usedQuote.approvalNeeded?.gas || '0x0', 16)
|
||||||
.toString(16)
|
.toString(16)
|
||||||
const gasEstimateTotalInEth = getValueFromWeiHex({
|
const gasEstimateTotalInUSD = getValueFromWeiHex({
|
||||||
value: calcGasTotal(totalGasLimitEstimate, usedGasPrice),
|
value: calcGasTotal(totalGasLimitEstimate, usedGasPrice),
|
||||||
toCurrency: 'usd',
|
toCurrency: 'usd',
|
||||||
conversionRate,
|
conversionRate: usdConversionRate,
|
||||||
numberOfDecimals: 6,
|
numberOfDecimals: 6,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -646,7 +645,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => {
|
|||||||
usedQuote.aggregator === getTopQuote(state)?.aggregator
|
usedQuote.aggregator === getTopQuote(state)?.aggregator
|
||||||
? ''
|
? ''
|
||||||
: usedQuote.aggregator,
|
: usedQuote.aggregator,
|
||||||
gas_fees: formatCurrency(gasEstimateTotalInEth, 'usd')?.slice(1),
|
gas_fees: gasEstimateTotalInUSD,
|
||||||
estimated_gas: estimatedGasLimit.toString(10),
|
estimated_gas: estimatedGasLimit.toString(10),
|
||||||
suggested_gas_price: fastGasEstimate,
|
suggested_gas_price: fastGasEstimate,
|
||||||
used_gas_price: hexWEIToDecGWEI(usedGasPrice),
|
used_gas_price: hexWEIToDecGWEI(usedGasPrice),
|
||||||
|
@ -182,13 +182,17 @@ export function addHexes(aHexWEI, bHexWEI) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sumHexWEIsToRenderableFiat(
|
export function sumHexWEIs(hexWEIs) {
|
||||||
|
return hexWEIs.filter((n) => n).reduce(addHexes)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sumHexWEIsToUnformattedFiat(
|
||||||
hexWEIs,
|
hexWEIs,
|
||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
) {
|
) {
|
||||||
const hexWEIsSum = hexWEIs.filter((n) => n).reduce(addHexes)
|
const hexWEIsSum = sumHexWEIs(hexWEIs)
|
||||||
const ethTotal = decEthToConvertedCurrency(
|
const convertedTotal = decEthToConvertedCurrency(
|
||||||
getValueFromWeiHex({
|
getValueFromWeiHex({
|
||||||
value: hexWEIsSum,
|
value: hexWEIsSum,
|
||||||
toCurrency: 'ETH',
|
toCurrency: 'ETH',
|
||||||
@ -197,5 +201,18 @@ export function sumHexWEIsToRenderableFiat(
|
|||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
)
|
)
|
||||||
return formatCurrency(ethTotal, convertedCurrency)
|
return convertedTotal
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sumHexWEIsToRenderableFiat(
|
||||||
|
hexWEIs,
|
||||||
|
convertedCurrency,
|
||||||
|
conversionRate,
|
||||||
|
) {
|
||||||
|
const convertedTotal = sumHexWEIsToUnformattedFiat(
|
||||||
|
hexWEIs,
|
||||||
|
convertedCurrency,
|
||||||
|
conversionRate,
|
||||||
|
)
|
||||||
|
return formatCurrency(convertedTotal, convertedCurrency)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { useHistory } from 'react-router-dom'
|
|||||||
import { I18nContext } from '../../../contexts/i18n'
|
import { I18nContext } from '../../../contexts/i18n'
|
||||||
import { useNewMetricEvent } from '../../../hooks/useMetricEvent'
|
import { useNewMetricEvent } from '../../../hooks/useMetricEvent'
|
||||||
import { MetaMetricsContext } from '../../../contexts/metametrics.new'
|
import { MetaMetricsContext } from '../../../contexts/metametrics.new'
|
||||||
import { getCurrentCurrency, conversionRateSelector } from '../../../selectors'
|
import { getCurrentCurrency, getUSDConversionRate } from '../../../selectors'
|
||||||
import {
|
import {
|
||||||
getUsedQuote,
|
getUsedQuote,
|
||||||
getFetchParams,
|
getFetchParams,
|
||||||
@ -69,14 +69,14 @@ export default function AwaitingSwap({
|
|||||||
const approveTxParams = useSelector(getApproveTxParams)
|
const approveTxParams = useSelector(getApproveTxParams)
|
||||||
const swapsGasPrice = useSelector(getUsedSwapsGasPrice)
|
const swapsGasPrice = useSelector(getUsedSwapsGasPrice)
|
||||||
const currentCurrency = useSelector(getCurrentCurrency)
|
const currentCurrency = useSelector(getCurrentCurrency)
|
||||||
const conversionRate = useSelector(conversionRateSelector)
|
const usdConversionRate = useSelector(getUSDConversionRate)
|
||||||
|
|
||||||
const [timeRemainingExpired, setTimeRemainingExpired] = useState(false)
|
const [timeRemainingExpired, setTimeRemainingExpired] = useState(false)
|
||||||
const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState(
|
const [trackedQuotesExpiredEvent, setTrackedQuotesExpiredEvent] = useState(
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
|
||||||
let feeinFiat
|
let feeinUnformattedFiat
|
||||||
|
|
||||||
if (usedQuote && swapsGasPrice) {
|
if (usedQuote && swapsGasPrice) {
|
||||||
const renderableNetworkFees = getRenderableNetworkFeesForQuote(
|
const renderableNetworkFees = getRenderableNetworkFeesForQuote(
|
||||||
@ -84,12 +84,12 @@ export default function AwaitingSwap({
|
|||||||
approveTxParams?.gas || '0x0',
|
approveTxParams?.gas || '0x0',
|
||||||
swapsGasPrice,
|
swapsGasPrice,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
conversionRate,
|
usdConversionRate,
|
||||||
usedQuote?.trade?.value,
|
usedQuote?.trade?.value,
|
||||||
sourceTokenInfo?.symbol,
|
sourceTokenInfo?.symbol,
|
||||||
usedQuote.sourceAmount,
|
usedQuote.sourceAmount,
|
||||||
)
|
)
|
||||||
feeinFiat = renderableNetworkFees.feeinFiat?.slice(1)
|
feeinUnformattedFiat = renderableNetworkFees.rawNetworkFees
|
||||||
}
|
}
|
||||||
|
|
||||||
const quotesExpiredEvent = useNewMetricEvent({
|
const quotesExpiredEvent = useNewMetricEvent({
|
||||||
@ -101,7 +101,7 @@ export default function AwaitingSwap({
|
|||||||
request_type: fetchParams?.balanceError ? 'Quote' : 'Order',
|
request_type: fetchParams?.balanceError ? 'Quote' : 'Order',
|
||||||
slippage: fetchParams?.slippage,
|
slippage: fetchParams?.slippage,
|
||||||
custom_slippage: fetchParams?.slippage === 2,
|
custom_slippage: fetchParams?.slippage === 2,
|
||||||
gas_fees: feeinFiat,
|
gas_fees: feeinUnformattedFiat,
|
||||||
},
|
},
|
||||||
category: 'swaps',
|
category: 'swaps',
|
||||||
})
|
})
|
||||||
|
@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
|
|||||||
import PageContainer from '../../../components/ui/page-container'
|
import PageContainer from '../../../components/ui/page-container'
|
||||||
import { Tabs, Tab } from '../../../components/ui/tabs'
|
import { Tabs, Tab } from '../../../components/ui/tabs'
|
||||||
import { calcGasTotal } from '../../send/send.utils'
|
import { calcGasTotal } from '../../send/send.utils'
|
||||||
import { sumHexWEIsToRenderableFiat } from '../../../helpers/utils/conversions.util'
|
import { sumHexWEIsToUnformattedFiat } from '../../../helpers/utils/conversions.util'
|
||||||
import AdvancedGasInputs from '../../../components/app/gas-customization/advanced-gas-inputs'
|
import AdvancedGasInputs from '../../../components/app/gas-customization/advanced-gas-inputs'
|
||||||
import BasicTabContent from '../../../components/app/gas-customization/gas-modal-page-container/basic-tab-content'
|
import BasicTabContent from '../../../components/app/gas-customization/gas-modal-page-container/basic-tab-content'
|
||||||
import { GAS_ESTIMATE_TYPES } from '../../../helpers/constants/common'
|
import { GAS_ESTIMATE_TYPES } from '../../../helpers/constants/common'
|
||||||
@ -35,8 +35,7 @@ export default class GasModalPageContainer extends Component {
|
|||||||
disableSave: PropTypes.bool,
|
disableSave: PropTypes.bool,
|
||||||
customGasLimitMessage: PropTypes.string,
|
customGasLimitMessage: PropTypes.string,
|
||||||
customTotalSupplement: PropTypes.string,
|
customTotalSupplement: PropTypes.string,
|
||||||
value: PropTypes.string,
|
usdConversionRate: PropTypes.string,
|
||||||
conversionRate: PropTypes.string,
|
|
||||||
customGasPrice: PropTypes.string,
|
customGasPrice: PropTypes.string,
|
||||||
customGasLimit: PropTypes.string,
|
customGasLimit: PropTypes.string,
|
||||||
setSwapsCustomizationModalPrice: PropTypes.func,
|
setSwapsCustomizationModalPrice: PropTypes.func,
|
||||||
@ -246,14 +245,10 @@ export default class GasModalPageContainer extends Component {
|
|||||||
category: 'swaps',
|
category: 'swaps',
|
||||||
properties: {
|
properties: {
|
||||||
speed_set: this.state.gasSpeedType,
|
speed_set: this.state.gasSpeedType,
|
||||||
gas_fees: sumHexWEIsToRenderableFiat(
|
gas_fees: sumHexWEIsToUnformattedFiat(
|
||||||
[
|
[newSwapGasTotal, this.props.customTotalSupplement],
|
||||||
this.props.value,
|
|
||||||
newSwapGasTotal,
|
|
||||||
this.props.customTotalSupplement,
|
|
||||||
],
|
|
||||||
'usd',
|
'usd',
|
||||||
this.props.conversionRate,
|
this.props.usdConversionRate,
|
||||||
)?.slice(1),
|
)?.slice(1),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
getCurrentEthBalance,
|
getCurrentEthBalance,
|
||||||
getDefaultActiveButtonIndex,
|
getDefaultActiveButtonIndex,
|
||||||
getRenderableGasButtonData,
|
getRenderableGasButtonData,
|
||||||
|
getUSDConversionRate,
|
||||||
} from '../../../selectors'
|
} from '../../../selectors'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -118,8 +119,7 @@ const mapStateToProps = (state) => {
|
|||||||
insufficientBalance,
|
insufficientBalance,
|
||||||
customGasLimitMessage,
|
customGasLimitMessage,
|
||||||
customTotalSupplement,
|
customTotalSupplement,
|
||||||
conversionRate,
|
usdConversionRate: getUSDConversionRate(state),
|
||||||
value,
|
|
||||||
disableSave: insufficientBalance,
|
disableSave: insufficientBalance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,3 +359,7 @@ export function getOriginOfCurrentTab(state) {
|
|||||||
export function getIpfsGateway(state) {
|
export function getIpfsGateway(state) {
|
||||||
return state.metamask.ipfsGateway
|
return state.metamask.ipfsGateway
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUSDConversionRate(state) {
|
||||||
|
return state.metamask.usdConversionRate
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user