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

Include trade.value in calculation of displayed network fees #9621

Merged
merged 5 commits into from
Oct 27, 2020

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Oct 16, 2020

This PR corrects an error in how we were rendering the displayed network fees on the view quote screen. For some aggregators, trade.value can be greater than the amount of eth being swapped (0 in the case of swapping an ERC-20, and sourceAmount in the case of swapping ETH). We weren't properly factoring this in before, and this could cause some rendered networks fees to be a little lower than they should be.

@danjm danjm requested a review from a team as a code owner October 16, 2020 13:55
@danjm danjm requested a review from rekmarks October 16, 2020 13:55
@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.

@metamaskbot
Copy link
Collaborator

Builds ready [57c0821]
Page Load Metrics (412 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint29433642
domContentLoaded25161041010551
load25361241210550
domInteractive25161041010551

@rekmarks rekmarks changed the title Include trade.value is in calculation of displayed network fees Include trade.value in calculation of displayed network fees Oct 20, 2020
@rekmarks
Copy link
Member

Rather than repeating the ethFee calculations in the UI, why don't we slap the ethFee calculated in the background (introduced in #9611) onto the quote objects and use them directly?

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

I'm not sure I understand that description of the problem.

Are you saying that the "network fee" was lower than intended for some aggregators, because the "network fee" is intended to be the gas fee plus the aggregator fee (at least in the cases where the aggregator fee was included in trade.value)? The tooltip shown in-app describes the network fee as being solely the gas fee.

ui/app/pages/swaps/swaps.util.js Outdated Show resolved Hide resolved
@danjm
Copy link
Contributor Author

danjm commented Oct 22, 2020

Let's block this PR on #9675, and then refactor it rely more on some of the logic added to the background controller in that PR

@danjm danjm assigned danjm and unassigned danjm Oct 22, 2020
@danjm danjm added the DO-NOT-MERGE Pull requests that should not be merged label Oct 22, 2020
@danjm danjm marked this pull request as draft October 22, 2020 14:13
@danjm danjm added T16-deploy-blocker and removed DO-NOT-MERGE Pull requests that should not be merged labels Oct 22, 2020
@danjm danjm force-pushed the fix-network-fee-display branch from 5fdbacb to 1716da5 Compare October 26, 2020 20:25
@danjm danjm marked this pull request as ready for review October 26, 2020 20:33
@danjm danjm force-pushed the fix-network-fee-display branch from 1716da5 to d5c3c9b Compare October 26, 2020 21:01
@danjm
Copy link
Contributor Author

danjm commented Oct 26, 2020

Are you saying that the "network fee" was lower than intended for some aggregators, because the "network fee" is intended to be the gas fee plus the aggregator fee (at least in the cases where the aggregator fee was included in trade.value)?

Yes, but for the displayed network fee only. The amount submitted is correct.

The tooltip shown in-app describes the network fee as being solely the gas fee.

Right, and the custom gas modal does not represent this in the total. I'll see if I can put together a straightforward fix for that.

@Gudahtt
Copy link
Member

Gudahtt commented Oct 26, 2020

I was not referring to the custom gas modal. The tooltip for "Estimated network fee" on the "View quote" page says this:

The gas fee covers the cost of processing your swap and storing it on the Ethereum network. MetaMask does not profit from this fee.

It seems misleading to describe it as a "gas fee" and to make no mention that it includes more than just the gas fee.

sourceTokenInfo?.symbol,
usedQuote.sourceAmount,
)
feeinFiat = renderableNetworkFees.feeinFiat?.slice(1)
Copy link
Member

Choose a reason for hiding this comment

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

Was this an attempt to remove the dollar sign from the value? This will be broken for any locale that represents numbers in some manner other than <symbol><number>.

formatCurrency returns a string that is meant to be displayed exactly as-is. You'll need to return the number directly if you want to use it without any symbol.

Copy link
Member

Choose a reason for hiding this comment

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

I'm noticing now that this was a pre-existing problem. It's definitely a release blocker though - this would give very wrong answers in some cases (e.g. 1,000 $ would turn into 000 $).

Copy link
Member

Choose a reason for hiding this comment

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

I've discovered that this is done in two other places as well, but in all cases the result is used solely for metrics. So maybe not a release blocker then luckily.

Still something we should fix at some point though, so our metrics aren't skewed for other locales.

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 has been addressed in a separate PR: #9727

There were more problems than just stated in the above comments. In particular, as all of these are just used for our metrics, they should all be denominated in USD.

@danjm
Copy link
Contributor Author

danjm commented Oct 27, 2020

I was not referring to the custom gas modal. The tooltip for "Estimated network fee" on the "View quote" page says this:

Yeah, I was not clear in my response. I said "Right," which was an affirmation of your point about the tooltip, and then I said something about the custom gas modal to say that your general point also applies to that in a way. Right now we say you can "Edit" the network fee, which includes these aggregator fees, clicking "Edit" opens the custom gas modal, but these aggregator fees are not represented there.

@danjm danjm force-pushed the fix-network-fee-display branch from d5c3c9b to eecf114 Compare October 27, 2020 15:05
@danjm
Copy link
Contributor Author

danjm commented Oct 27, 2020

@Gudahtt eecf114fd updates the tooltip copy and the display of fees in the gas customization modal

Here are some screenshots of the latter (done by adding fake extra fees to the api response because at present no aggregator is including those extra fees... at least on the few quotes I tested)

Screenshots

Gudahtt
Gudahtt previously approved these changes Oct 27, 2020
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! One minor suggestion

ui/app/pages/swaps/swaps.util.js Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Member

Gudahtt commented Oct 27, 2020

Oh, prettier needs to be run again to sort the new localized messages.

@danjm
Copy link
Contributor Author

danjm commented Oct 27, 2020

@Gudahtt message sorting / linting done in latest commit

Gudahtt
Gudahtt previously approved these changes Oct 27, 2020
@metamaskbot
Copy link
Collaborator

Builds ready [8b66039]
Page Load Metrics (452 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298041147
domContentLoaded26576445015173
load26676645215173
domInteractive26576345015173

@danjm danjm merged commit a4f817e into develop Oct 27, 2020
@danjm danjm deleted the fix-network-fee-display branch October 27, 2020 19:02
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 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.

5 participants