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

feat: Support gas fee flows in swaps #12495

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Nov 29, 2024

Description

This PR aims to adapt estimateGasFee from TransactionController for swaps trade and approval transactions. For more information please see the extension PR applies same functionality: MetaMask/metamask-extension#27612

Also adding basic unit tests for QuoteView screen.

Related issues

Fixes: https://github.com/MetaMask/mobile-planning/issues/2026

Manual testing steps

  • Regression testing of internal swaps.
  • Smart swaps and standard.
  • Specific tests on Linea chains.

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Nov 29, 2024
@OGPoyraz OGPoyraz marked this pull request as ready for review December 2, 2024 12:24
@OGPoyraz OGPoyraz requested review from a team as code owners December 2, 2024 12:24
@OGPoyraz OGPoyraz added the Run Smoke E2E Triggers smoke e2e on Bitrise label Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

https://bitrise.io/ Bitrise

🔄🔄🔄 pr_smoke_e2e_pipeline started on Bitrise...🔄🔄🔄

Commit hash: d1c85a7
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/54e836dd-1648-4193-9c00-ff822d5cb512

Note

  • This comment will auto-update when build completes
  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@OGPoyraz OGPoyraz added Run Smoke E2E Triggers smoke e2e on Bitrise team-swaps and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 1b2166e
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/7ba3e7b2-abdb-44ef-bcb1-21495b99cff4

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

Copy link

sonarcloud bot commented Dec 2, 2024

let tradeGasFeeEstimates;
const tradeTransaction = selectedQuote.trade;

if (isEIP1559Network) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor, is it worth encapsulating all this logic in the existing getTransactionPropertiesFromGasEstimates but also passing the quote argument?


let approvalGasFeeEstimates;

if (isEIP1559Network) {
Copy link
Member

Choose a reason for hiding this comment

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

If we expanded getTransactionPropertiesFromGasEstimates, could we just call again here but with the approval transaction or quote instead?


const { TransactionController } = Engine.context;

const transactionGasFeeResponse = await TransactionController.estimateGasFee({
Copy link
Member

Choose a reason for hiding this comment

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

Should we use the transaction controller utils file here instead?

@@ -156,3 +156,11 @@ export const selectNetworkClientId = createSelector(
(networkControllerState: NetworkState) =>
networkControllerState.selectedNetworkClientId,
);

export const selectIsEIP1559Network = createSelector(
Copy link
Member

Choose a reason for hiding this comment

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

We could also determine this from the gas fee estimate type, but this is better as it reduces coupling on the gas fee controller ❤️


const mockSelectedNetworkClientId = '1';

describe('NetworkController Selectors', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but Redux discourage testing unit selectors in favour of mocking state in all component and hook tests so they get covered there.

const { maxFeePerGas } = transactionGasFeeEstimates?.high ?? {};
const { maxPriorityFeePerGas } = transactionGasFeeEstimates?.high ?? {};

const baseAndPriorityFeePerGas = maxPriorityFeePerGas
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed in mobile since we add this return straight to the transaction params? And estimatedBaseFeeGwei also?

@infiniteflower
Copy link
Contributor

Tested and seems to be working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-confirmations Push issues to confirmations team team-swaps
Projects
Status: Needs more work from the author
Development

Successfully merging this pull request may close these issues.

4 participants