Skip to content

refactor: extract various business logic into separate utilities#26678

Merged
GeorgeGkas merged 9 commits into
mainfrom
swaps-4188
Feb 27, 2026
Merged

refactor: extract various business logic into separate utilities#26678
GeorgeGkas merged 9 commits into
mainfrom
swaps-4188

Conversation

@GeorgeGkas

@GeorgeGkas GeorgeGkas commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Description

Extract various logic into separate pure functions and hooks.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/SWAPS-4188

Manual testing steps

This PR introduce no change to business logic. Ensure that no regressions got introduced. 

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.

Note

Medium Risk
Mostly refactoring with broad surface-area touch in Bridge quoting/fee display and validation filtering; moderate risk of UI regressions around fee formatting and when quote sections render/clear on expiry.

Overview
Refactors Bridge quote presentation logic into reusable utilities/hooks. Network-fee formatting is extracted to formatNetworkFee + useFormattedNetworkFee, and gas-sponsorship logic is moved into useIsNetworkGasSponsored + useShouldRenderGasSponsoredBanner, with gasless detection centralized in isGaslessQuote.

Hardens quote-driven UI and data selection. BridgeView now avoids rendering the bottom action section when there’s no activeQuote (fixing an expiry/redirect edge case), and useBridgeQuoteData adds validQuotes by filtering sorted quotes to those matching the selected destination token and non-expired state.

Consolidates fiat formatting. The existing useFiatFormatter hook is simplified to delegate to a new shared util/formatFiat helper, with extensive new unit tests added across the new hooks/utilities.

Written by Cursor Bugbot for commit 9096d32. This will update automatically on new commits. Configure here.

@GeorgeGkas GeorgeGkas added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Feb 27, 2026
@GeorgeGkas GeorgeGkas marked this pull request as ready for review February 27, 2026 10:01
@GeorgeGkas GeorgeGkas requested a review from a team as a code owner February 27, 2026 10:01
@github-actions

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 Feb 27, 2026
Comment thread app/components/UI/Bridge/hooks/useShouldRenderGasSponsoredBanner/index.ts Outdated
Comment thread app/components/UI/Bridge/hooks/useShouldRenderGasSponsoredBanner/index.ts Outdated
Comment thread app/components/UI/Bridge/hooks/useBridgeQuoteData/index.ts Outdated
isExpired,
blockaidError,
shouldShowPriceImpactWarning,
validQuotes,

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.

validQuotes is exported here but never imported/used anywhere in the app. Why export it? (and also, why even have it at all? Dead code? 🤔 )

}

const QuoteDetailsCard: React.FC<QuoteDetailsCardProps> = ({
hasInsufficientBalance,

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.

We import hasInsufficientBalance here intentionally to minimize use of useLatestBalance, which is RPC expensive and soon to be deprecated (hopefully 🙏 ).

We should keep this hasInsufficientBalance param and pass it into useShouldRenderGasSponsoredBanner so the hook can use that directly.

@GeorgeGkas GeorgeGkas requested a review from bfullam February 27, 2026 16:11
bfullam
bfullam previously approved these changes Feb 27, 2026
Comment thread app/components/UI/Bridge/Views/BridgeView/index.tsx Outdated

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@GeorgeGkas GeorgeGkas requested a review from bfullam February 27, 2026 17:19
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeTrade, SmokeConfirmations
  • Selected Performance tags: @PerformanceSwaps
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
This PR refactors Bridge-related code by extracting utility functions and hooks:

  1. Bridge-specific changes:

    • New hooks: useFormattedNetworkFee, useIsNetworkGasSponsored, useShouldRenderGasSponsoredBanner
    • New utilities: formatNetworkFee.ts, isGaslessQuote.ts
    • BridgeView: Added early return when no active quote exists (edge case fix)
    • QuoteDetailsCard: Refactored to use new hooks
    • useBridgeQuoteData: Added validQuotes filtering and uses new useFormattedNetworkFee
  2. Shared utility refactoring:

    • Extracted formatFiat.ts from useFiatFormatter hook
    • The useFiatFormatter hook is used in many places including confirmations, SimulationDetails, Earn, and Perps

SmokeTrade is selected because:

  • All Bridge and Swap functionality is covered by this tag
  • Tests include bridge-action-smoke.spec.ts, swap-action-smoke.spec.ts, gasless-swap.spec.ts
  • The changes directly affect quote display, network fee formatting, and gas sponsored banner logic

SmokeConfirmations is selected because:

  • The useFiatFormatter hook (which now delegates to the new formatFiat utility) is used in multiple confirmation components:
    • transaction-details-bridge-fee-row
    • transaction-details-hero
    • bridge-fee-row, total-row, receive-row, pay-with-row
    • useFeeCalculations, useFeeCalculationsTransactionBatch
    • useTokenAmount, useTokenWithBalance
  • Any regression in fiat formatting could affect confirmation displays

The changes are primarily refactoring with comprehensive unit tests added, but the shared formatFiat utility affects multiple areas of the app.

Performance Test Selection:
The changes affect the Bridge/Swap quote data processing and display. The useBridgeQuoteData hook now includes additional filtering logic (validQuotes) and the network fee formatting has been refactored. While these are primarily refactoring changes, the swap flow performance tests should verify that quote fetching and display performance is not impacted. The @PerformanceSwaps tag covers swap execution and quote fetching times which are relevant to these changes.

View GitHub Actions results

@GeorgeGkas GeorgeGkas added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit cdf56ce Feb 27, 2026
92 of 93 checks passed
@GeorgeGkas GeorgeGkas deleted the swaps-4188 branch February 27, 2026 20:13
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 27, 2026
@metamaskbot metamaskbot added the release-7.69.0 Issue or pull request that will be included in release 7.69.0 label Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.69.0 Issue or pull request that will be included in release 7.69.0 size-XL team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants