-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix gas_fees properties collected for swaps analytics events #9727
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
@@ -239,7 +238,11 @@ export default class GasModalPageContainer extends Component { | |||
properties: { | |||
speed_set: speedSet, | |||
gas_mode: this.state.selectedTab, | |||
gas_fees: sumHexWEIsToRenderableFiat([this.props.value, newSwapGasTotal, this.props.customTotalSupplement], 'usd', this.props.conversionRate)?.slice(1), | |||
gas_fees: sumHexWEIsToUnformattedFiat( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.props.value
should not be included in the "gas_fees" that are calculated here
const destinationValue = calcTokenAmount(usedQuote.destinationAmount, destinationTokenInfo.decimals || 18).toPrecision(8) | ||
const usedGasLimitEstimate = usedQuote?.gasEstimateWithRefund || (`0x${decimalToHex(usedQuote?.averageGas || 0)}`) | ||
const totalGasLimitEstimate = (new BigNumber(usedGasLimitEstimate, 16)).plus(usedQuote.approvalNeeded?.gas || '0x0', 16).toString(16) | ||
const gasEstimateTotalInEth = getValueFromWeiHex({ | ||
const gasEstimateTotalInUSD = getValueFromWeiHex({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name gasEstimateTotalInEth
did not reflect the the content/value of this variable
@@ -480,7 +479,7 @@ export const signAndSendTransactions = (history, metaMetricsEvent) => { | |||
available_quotes: getQuotes(state)?.length, | |||
other_quote_selected: usedQuote.aggregator !== getTopQuote(state)?.aggregator, | |||
other_quote_selected_source: usedQuote.aggregator === getTopQuote(state)?.aggregator ? '' : usedQuote.aggregator, | |||
gas_fees: formatCurrency(gasEstimateTotalInEth, 'usd')?.slice(1), | |||
gas_fees: gasEstimateTotalInUSD, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting is both unnecessary and diverges from what we want in our analytics, which is an unformatted decimal number
@@ -171,14 +171,23 @@ export function addHexes (aHexWEI, bHexWEI) { | |||
}) | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file don't change the functionality of sumHexWEIsToRenderableFiat
, while making part of the logic previously in sumHexWEIsToRenderableFiat
exportable via sumHexWEIsToUnformattedFiat
if (usedQuote && tradeTxParams) { | ||
const renderableGasFees = getRenderableGasFeesForQuote(usedQuote.gasEstimateWithRefund || usedQuote.averageGas, approveTxParams?.gas || '0x0', tradeTxParams.gasPrice, currentCurrency, conversionRate) | ||
feeinFiat = renderableGasFees.feeinFiat?.slice(1) | ||
const renderableGasFees = getRenderableGasFeesForQuote(usedQuote.gasEstimateWithRefund || usedQuote.averageGas, approveTxParams?.gas || '0x0', tradeTxParams.gasPrice, currentCurrency, usdConversionRate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting is both unnecessary and diverges from what we want in our analytics, which is an unformatted decimal number, which is what rawNetworkFees
gives us.
ui/app/ducks/swaps/swaps.js
Outdated
numberOfDecimals: 6, | ||
}) | ||
const averageSavings = usedQuote.isBestQuote | ||
? decEthToConvertedCurrency( | ||
usedQuote.savings?.total, | ||
'usd', | ||
conversionRate, | ||
usdConversionRate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While not a gas_fees
property, the averageSavings
calculation was also incorrectly using on the conversionRate
, when we want our analytics in USD
@danjm sorry for dropping the ball on reviewing this. Could you rebase and I'll make this my next priority? |
a1e44a1
to
9aa8bd5
Compare
@brad-decker this has been rebased on top of latest develop |
9aa8bd5
to
c9eac81
Compare
@danjm this has conflict markers in it, e.g |
c9eac81
to
6f15458
Compare
@brad-decker This has been rebased, and the error you identified removed |
6f15458
to
eedd5e4
Compare
Builds ready [eedd5e4]
Page Load Metrics (434 ± 60 ms)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a question that is non blocking
@@ -102,7 +102,7 @@ export default function AwaitingSwap({ | |||
request_type: fetchParams?.balanceError ? 'Quote' : 'Order', | |||
slippage: fetchParams?.slippage, | |||
custom_slippage: fetchParams?.slippage === 2, | |||
gas_fees: feeinFiat, | |||
gas_fees: feeinUnformattedFiat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we also want to trade the usdConversionRate at the time of transaction or no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, sounds like a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, actually, maybe not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this gives us anything we need. We might want to also add the used gas limit here (as we already know the price). But I think that is for a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thanks @danjm
eedd5e4
to
588f472
Compare
588f472
to
2198a8a
Compare
Builds ready [2198a8a]
Page Load Metrics (375 ± 63 ms)
|
This is in response to a comment on another PR.
A few fixes are included here. The most important is that the
gas_fees
property on analytics events should be denominated in USD. This will allow all gas fees data to be easily comparible. This requires MetaMask/core#292Additional fixes are commented on in the diff