Skip to content
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

Merged
merged 1 commit into from
Nov 10, 2020

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Oct 27, 2020

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#292

Additional fixes are commented on in the diff

@danjm danjm requested a review from a team as a code owner October 27, 2020 12:21
@danjm danjm requested a review from kumavis October 27, 2020 12:21
@github-actions
Copy link
Contributor

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(
Copy link
Contributor Author

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({
Copy link
Contributor Author

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,
Copy link
Contributor Author

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) {
})
}

Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

numberOfDecimals: 6,
})
const averageSavings = usedQuote.isBestQuote
? decEthToConvertedCurrency(
usedQuote.savings?.total,
'usd',
conversionRate,
usdConversionRate,
Copy link
Contributor Author

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

@brad-decker
Copy link
Contributor

@danjm sorry for dropping the ball on reviewing this. Could you rebase and I'll make this my next priority?

@danjm danjm force-pushed the usd-swaps-analytics-gas-fees branch from a1e44a1 to 9aa8bd5 Compare November 3, 2020 20:24
@danjm
Copy link
Contributor Author

danjm commented Nov 3, 2020

@brad-decker this has been rebased on top of latest develop

@danjm danjm force-pushed the usd-swaps-analytics-gas-fees branch from 9aa8bd5 to c9eac81 Compare November 4, 2020 02:50
@brad-decker
Copy link
Contributor

@danjm this has conflict markers in it, e.g <<<< HEAD

@danjm danjm force-pushed the usd-swaps-analytics-gas-fees branch from c9eac81 to 6f15458 Compare November 6, 2020 15:49
@danjm
Copy link
Contributor Author

danjm commented Nov 6, 2020

@brad-decker This has been rebased, and the error you identified removed

@danjm danjm force-pushed the usd-swaps-analytics-gas-fees branch from 6f15458 to eedd5e4 Compare November 6, 2020 16:26
@metamaskbot
Copy link
Collaborator

Builds ready [eedd5e4]
Page Load Metrics (434 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint318437115
domContentLoaded26962943212560
load27063043412560
domInteractive26962843212560

brad-decker
brad-decker previously approved these changes Nov 6, 2020
Copy link
Contributor

@brad-decker brad-decker left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, actually, maybe not...

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, thanks @danjm

@danjm danjm force-pushed the usd-swaps-analytics-gas-fees branch from 588f472 to 2198a8a Compare November 10, 2020 16:54
@metamaskbot
Copy link
Collaborator

Builds ready [2198a8a]
Page Load Metrics (375 ± 63 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298040105
domContentLoaded26374837413163
load26574937513163
domInteractive26374737313163

@danjm danjm merged commit bcd5f2a into develop Nov 10, 2020
@danjm danjm deleted the usd-swaps-analytics-gas-fees branch November 10, 2020 17:39
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants