Skip to content

feat(bridge): implement bridge quote fetching #14413

Merged
amitabh94 merged 27 commits into
mainfrom
MMS-1886-bridge-quote-fetching
Apr 14, 2025
Merged

feat(bridge): implement bridge quote fetching #14413
amitabh94 merged 27 commits into
mainfrom
MMS-1886-bridge-quote-fetching

Conversation

@amitabh94

@amitabh94 amitabh94 commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

Description

This PR enable the fetching of live quotes from the bridge controller and displays the quote information on the QuoteDetails Card when source and destination tokens are selected.

  • Added useBridgeQuoteData hook to manage bridge quote data and formatting
  • Added useBridgeQuoteRequest hook for handling quote request updates
  • Updated QuoteDetailsCard to use real quote data instead of mock data
  • Enhanced TokenInputArea with loading states and improved formatting
  • Improved error handling and type safety throughout the bridge components

This PR covers the following:

  • Fetch quotes from Bridge Controller as soon as tokens and amount are populated
  • Refreshes quotes if amount is less than available balance upto max refresh count
  • Does not refresh quote when insufficient balance
  • Populates the destination amount as soon as the quotes are fetched
  • Loading state for when quotes are being fetched
  • Hides the quote details card when quote expires
  • Editing the slippage causes the quotes to refresh

This does not currently include:

  • Calculation for Network Fee

Related issues

Related to: MMS-1886

Manual testing steps

  1. Navigate to the bridge UI form wallet actions
  2. Select a source tokena nd destination token
  3. Enter the source amount
  4. You should see the destination amount getting populated and quote details card appear with all the quote information

Screenshots/Recordings

1. Bridge Quote Display

  • Navigate to the Bridge screen
  • Select source and destination tokens
  • Enter an amount
  • Verify that quote details are displayed correctly:
    - Estimated time
    - Exchange rate
    - Price impact
    - Slippage tolerance

2. Loading States

  • Verify loading skeletons appear when:
    • Initially loading quotes
    • Refreshing quotes
    • Changing tokens or amounts

3. Quote Updates

  • Change the source amount
  • Verify quote updates after debounce period
  • Verify quote expiration handling
  • Test with different token pairs

Before

After

Bridge.Quote.Fetching.mov

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.

@github-actions

github-actions Bot commented Apr 3, 2025

Copy link
Copy Markdown
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 metamaskbot added the team-swaps-and-bridge Swaps and Bridge team label Apr 3, 2025
@amitabh94 amitabh94 force-pushed the MMS-1886-bridge-quote-fetching branch from 5c01f4b to 6b615bb Compare April 4, 2025 04:05
- Introduced hooks `useBridgeQuoteData` and `useBridgeQuoteRequest` for managing bridge quote data and requests.
- Updated `BridgeView` to utilize new hooks for fetching and displaying bridge quotes.
- Enhanced `QuoteDetailsCard` to render quote details based on fetched data.
- Modified `TokenInputArea` to show loading state while fetching quote data.
- Added Redux state management for selected quotes in the bridge slice.
- Updated `useBridgeQuoteData` and `useBridgeQuoteRequest` hooks to improve quote fetching logic and state management.
- Refactored `BridgeView` to utilize the new hooks, ensuring accurate display of active quotes and loading states.
- Enhanced `TokenInputArea` to show a loading skeleton while fetching quote data.
- Introduced utility functions for quote refresh logic and expiration checks.
- Updated Redux state management in the bridge slice to reflect changes in quote handling.
- Removed unused `selectDestAmount` from `BridgeView` to simplify state management.
- Adjusted loading skeleton height in `TokenInputArea` for better UI consistency.
- Updated `useBridgeQuoteData` to handle undefined values for `destTokenAmount` and `formattedDestTokenAmount`.
- Enhanced quote data formatting to include calculated price impact percentage from the active quote.
- Added comments for future improvements regarding network fee and price impact calculations.
- Updated `formattedDestTokenAmount` in `useBridgeQuoteData` to display two decimal places for better precision in the UI.
- This change enhances the clarity of displayed amounts for users during bridge transactions.
@amitabh94 amitabh94 force-pushed the MMS-1886-bridge-quote-fetching branch from d953d11 to c26a43b Compare April 10, 2025 02:32
- Added a check for `formattedQuoteData` in the `QuoteDetailsCard` component to ensure all necessary data is present before rendering.
- This improvement prevents potential rendering issues when quote data is incomplete, enhancing the user experience during bridge transactions.
@amitabh94 amitabh94 requested a review from Copilot April 10, 2025 02:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

app/core/Engine/Engine.ts:1039

  • Ensure that the renamed action 'AccountsController:getSelectedMultichainAccount' is consistently updated in all related components and documentation to reflect multichain support.
'AccountsController:getSelectedMultichainAccount',

app/components/UI/Bridge/index.tsx:175

  • [nitpick] Review the inclusion of 'dispatch' in the dependency array of the updateQuoteParams useEffect; if dispatch is not used within the updateQuoteParams callback, consider removing it to prevent unnecessary effect executions.
dispatch,

@amitabh94 amitabh94 requested a review from Copilot April 10, 2025 03:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

app/core/Engine/Engine.ts:1039

  • The renamed messenger action 'AccountsController:getSelectedMultichainAccount' should be cross-verified with related configurations and documentation to ensure consistency across the codebase.
          'AccountsController:getSelectedMultichainAccount',

app/components/UI/Bridge/components/QuoteDetailsCard/QuoteDetailsCard.tsx:90

  • [nitpick] Resetting the expanded state only on sourceToken and destToken changes might not cover scenarios where the underlying quote data updates, potentially leading to UI inconsistencies. Consider adding dependencies such as sourceAmount or formattedQuoteData if changes in quotes should also reset the expanded state.
  useEffect(() => { setIsExpanded(false); }, [sourceToken, destToken]);

- Updated the `BridgeDestTokenSelector`, `BridgeSourceNetworkSelector`, and `BridgeSourceTokenSelector` tests to utilize the new `bridgeTestInitialState` for improved state management.
- Refactored `QuoteDetailsCard` to utilize `formattedQuoteData` directly, enhancing clarity and reducing redundancy in the component.
- Introduced new hooks `useBridgeQuoteData` and `useBridgeQuoteRequest` for better management of bridge quote data and requests, streamlining the overall quote handling process.
- Improved the formatting of displayed quote data, ensuring accurate representation of network fees and rates in the UI.
- Added comprehensive tests to ensure the correct functionality of the new hooks and components.
- Updated `mockBridgeReducerState` to set a defined `sourceAmount` for better test consistency.
- Introduced multiple new mock quote files for various asset types and bridging scenarios, including ERC20 to ERC20, native to ERC20, and SOL to ERC20.
- Added detailed mock data for quotes, including fee structures and processing times, to facilitate comprehensive testing of bridge functionalities.
- Refactored `QuoteDetailsCard` to utilize Redux selectors for `sourceToken`, `destToken`, and `sourceAmount`, improving state management and reducing prop drilling.
- Updated `useBridgeQuoteData` hook to return only `formattedQuoteData`, streamlining the data flow and enhancing component clarity.
- This change enhances the maintainability of the component and aligns with best practices for state management in Redux.
- Introduced `createBridgeControllerState` and `createBridgeTestState` functions to facilitate the creation of mock states for bridge components and hooks.
- These utilities allow for easy overrides of default state values, improving the flexibility and reliability of tests.
- Comprehensive tests have been added to ensure the correct functionality of the new utilities, enhancing overall test coverage for bridge-related features.
… hooks

- Introduced comprehensive unit tests for the `useBridgeQuoteData` hook, covering scenarios such as available quotes, expired quotes, loading states, and fetch errors.
- Added tests for the `useBridgeQuoteRequest` hook to ensure it returns a debounced function.
- These tests enhance the reliability and maintainability of the bridge functionality by ensuring correct behavior under various conditions.
- Modified `mockBridgeReducerState` to use specific chain IDs for improved consistency in tests.
- Replaced `initialState` with `createBridgeTestState` in `QuoteDetailsCard` tests to leverage the updated mock state, enhancing test reliability.
- This refactor aligns with best practices for state management and improves the clarity of test setups.
@amitabh94 amitabh94 marked this pull request as ready for review April 11, 2025 06:43
@amitabh94 amitabh94 requested a review from a team as a code owner April 11, 2025 06:43
@amitabh94 amitabh94 requested a review from a team April 11, 2025 06:43
- Deleted several mock quote files that are no longer needed, including `mock-quotes-erc20-erc20.json`, `mock-quotes-erc20-native.json`, `mock-quotes-native-erc20-eth.json`, `mock-quotes-native-erc20.json`, `mock-quotes-sol-erc20.json`, and `mock-quotes-native-erc20.json`.
- Updated the `QuoteDetailsCard` test to use a new mock file, `mock-quotes-sol-sol.json`, ensuring tests remain relevant and accurate.
- This cleanup improves the maintainability of the codebase by removing obsolete data and aligning with current testing practices.
@amitabh94 amitabh94 requested a review from Copilot April 11, 2025 06:56
@MetaMask MetaMask deleted a comment from github-actions Bot Apr 12, 2025
@MetaMask MetaMask deleted a comment from github-actions Bot Apr 12, 2025
@MetaMask MetaMask deleted a comment from github-actions Bot Apr 12, 2025
@github-actions

github-actions Bot commented Apr 12, 2025

Copy link
Copy Markdown
Contributor

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: a7d07c6
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/a389b862-18ea-4c28-8dc8-fa11b06975e2

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

@sonarqubecloud

Copy link
Copy Markdown

@amitabh94 amitabh94 added this pull request to the merge queue Apr 14, 2025
Merged via the queue into main with commit cbf181e Apr 14, 2025
@amitabh94 amitabh94 deleted the MMS-1886-bridge-quote-fetching branch April 14, 2025 14:26
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 14, 2025
@metamaskbot metamaskbot added the release-7.46.0 Issue or pull request that will be included in release 7.46.0 label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.46.0 Issue or pull request that will be included in release 7.46.0 team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants