Skip to content

feat(asset-details): add Quick Buy entry point to Token Details sticky footer#30725

Merged
xavier-brochard merged 17 commits into
mainfrom
feat/asset-details-quick-buy
Jun 2, 2026
Merged

feat(asset-details): add Quick Buy entry point to Token Details sticky footer#30725
xavier-brochard merged 17 commits into
mainfrom
feat/asset-details-quick-buy

Conversation

@xavier-brochard

@xavier-brochard xavier-brochard commented May 28, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a Quick Buy entry point to the Token (Asset) Details screen as a third icon button (a filled lightning bolt) in the sticky footer, next to the existing Buy/Sell and Swap actions. Tapping it opens the existing Quick Buy bottom sheet — the same UX that Top Traders positions launch today — pre-targeted at the token currently being viewed.

To make this reuse clean, the Quick Buy module is generalized so its core no longer depends on Social-API position shapes. Each host (Top Traders, Asset Details) becomes responsible for normalizing its chain id into a canonical CaipChainId at the adapter layer.

Why

  • Reach: Quick Buy was reachable only from Top Traders positions. Surfacing it on Token Details gives every supported asset a one-tap purchase path.
  • Reuse: same bottom sheet, same internal flow, same analytics funnel — only the entry point and the target token change.
  • Architecture: pushes host-specific concerns (chain string → CAIP normalization, feature set, analytics source) out of the Quick Buy core and into per-host adapters. The Quick Buy core now consumes a single canonical QuickBuyTarget shape regardless of where it was invoked from.

What changed

Quick Buy core (generalization, no behavior change)

  • QuickBuyTarget.chain is now CaipChainId (was a Social-API chain name string).
  • useQuickBuyController and useQuickBuySetup consume target.chain as CAIP directly — no more internal chainNameToId lookup.
  • TraderPositionQuickBuy (the existing host adapter) does the position-name → CAIP conversion locally via positionToQuickBuyTarget, which now returns QuickBuyTarget | null when a chain name can't be mapped.
  • Tests updated to match the new contract (helper createTarget to keep type-safety around the new nullable mapper).

New Asset Details entry point

  • TokenDetailsStickyFooter gains an optional third button rendered only when onQuickBuyPress is provided. Styled as a 48×48 circular icon-only button with the success-accent color, matching the Figma spec for Swap-Next.
  • AssetDetailsQuickBuy adapter maps TokenDetailsRouteParams (TokenI-shaped) → QuickBuyTarget, normalizing chainId to CAIP via formatChainIdToCaip with a safe null fallback when the chain can't be parsed.
  • TokenDetails.tsx wires the visibility state and renders the adapter as an overlay.
  • Analytics source 'asset_details' added to QuickBuySheetSource; sticky footer tracking gains a 'quick_buy' CTA type.

Icon (temporary)

  • Ships a local flash-filled.svg rendered through ButtonAnimated because the Design System doesn't yet expose IconName.FlashFilled.
  • Companion upstream PR opened against MetaMask/metamask-design-system: feat(shared,react,react-native): add FlashFilled icon metamask-design-system#1191. Once that lands and @metamask/design-system-react-native publishes a new minor, a follow-up PR will replace the local SVG with IconName.FlashFilled.

Out of scope

  • The Quick Buy module is kept in its current location under Views/SocialLeaderboard/TraderPositionView/components/QuickBuy. Relocating it to a feature-neutral folder is a separate refactor.
  • Asset-Details-specific token gating (e.g. unsupported chains, native asset edge cases) — the adapter falls back to a null target, which keeps the sheet inert; finer gating to be added if the analytics flag a problem post-launch.

Changelog

CHANGELOG entry: Added a Quick Buy lightning-bolt button to the Asset Details screen for one-tap token purchases.

Related issues

Fixes:

Manual testing steps

Feature: Asset Details Quick Buy entry point

  Scenario: User opens Quick Buy from Token Details
    Given the user has a wallet imported
    And the user is on the Token Details screen for a supported token (e.g. ETH on Mainnet)

    When the user taps the lightning-bolt button in the sticky footer
    Then the Quick Buy bottom sheet opens
    And the destination token is pre-filled with the asset being viewed
    And haptic feedback fires on press

  Scenario: User dismisses the Quick Buy sheet
    Given the Quick Buy sheet is open from Token Details

    When the user dismisses the sheet (backdrop tap or swipe down)
    Then the Token Details screen is visible again
    And the sticky footer remains interactive

  Scenario: Token has an unsupported chain
    Given the user is on Token Details for a token whose chain can't be CAIP-normalized

    When the user taps the lightning-bolt button
    Then the sheet stays inert (no crash, no broken state)

  Scenario: Regression — Top Traders Quick Buy still works
    Given the user has a Top Traders profile open
    And the user is viewing a trader's position

    When the user taps the Quick Buy CTA on that position
    Then the Quick Buy sheet opens with the position's token pre-targeted
    And the existing flow behaves identically to before this PR

Screenshots/Recordings

Before

image

After

image

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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.

Made with Cursor


Note

Medium Risk
Reuses bridge/Quick Buy submit and quote paths with a new entry surface; changes are mostly behind a remote flag but still affect trade analytics and chain targeting contracts shared with Top Traders.

Overview
Adds a version-gated remote flag (socialAiAssetDetailsQuickBuy) and, when enabled, a lightning Quick Buy control on Token Details that opens the existing Quick Buy sheet for the asset in view (haptics, asset_details analytics, sticky footer quick_buy CTA).

Introduces AssetDetailsQuickBuy to map route token → QuickBuyTarget (CAIP chain via formatChainIdToCaip, null target when mapping fails). Generalizes Quick Buy so QuickBuyTarget.chain is CaipChainId end-to-end; leaderboard mapping moves to positionToQuickBuyTarget (nullable for unknown chains). Trade/submit analytics can run without a trader address when entered from asset details.

Temporary local flash-filled.svg until design-system FlashFilled ships.

Reviewed by Cursor Bugbot for commit 9a87cb9. Bugbot is set up for automated code reviews on this repo. Configure here.

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

@xavier-brochard xavier-brochard added the team-social-ai Social & AI team label May 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Icon has been added 🎉
Can we have a followup to remove this and use the MMDS lib?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have the change ready in a local branch already :) Will follow-up with it

@xavier-brochard xavier-brochard marked this pull request as ready for review May 28, 2026 10:38
@xavier-brochard xavier-brochard requested a review from a team as a code owner May 28, 2026 10:39
Comment thread app/components/UI/TokenDetails/components/TokenDetailsStickyFooter.test.tsx Outdated
Comment thread app/components/UI/TokenDetails/Views/TokenDetails.test.tsx
@xavier-brochard xavier-brochard force-pushed the feat/asset-details-quick-buy branch from 9af9d4b to 1be4ad0 Compare May 29, 2026 12:22
@github-actions github-actions Bot added the risk:medium AI analysis: medium risk label May 29, 2026
@xavier-brochard xavier-brochard requested review from a team as code owners May 29, 2026 13:02
Comment thread app/components/UI/TokenDetails/hooks/useStickyFooterTracking.ts
@xavier-brochard xavier-brochard force-pushed the feat/asset-details-quick-buy branch from 40a41ff to f8279de Compare June 1, 2026 07:55
Comment thread app/components/UI/TokenDetails/components/AssetDetailsQuickBuy.tsx
Comment thread app/components/UI/TokenDetails/components/AssetDetailsQuickBuy.tsx Outdated
@github-actions github-actions Bot added size-XL and removed size-L labels Jun 1, 2026
zone-live
zone-live previously approved these changes Jun 1, 2026
onSwapPress,
onBuyPress,
onQuickBuyPress,
quickBuyTestID,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure why we pass down the test id, shouldnt we just hardcode it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's passed down on purpose because TokenDetailsStickyFooter is a shared component rendered by multiple different screens, and each screen needs its buttons to carry a different testID so E2E tests can target the right screen.

@xavier-brochard xavier-brochard enabled auto-merge June 1, 2026 09:05
tommasini
tommasini previously approved these changes Jun 1, 2026
hjetpoluru
hjetpoluru previously approved these changes Jun 1, 2026

@hjetpoluru hjetpoluru 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.

e2e related file changes lgtm

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

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 007886a. Configure here.

Comment thread app/components/UI/TokenDetails/components/AssetDetailsQuickBuy.tsx Outdated
xavier-brochard and others added 16 commits June 2, 2026 10:07
…y footer

Adds a third lightning-bolt button to the Token Details sticky footer that
opens the existing Quick Buy bottom sheet (previously only reachable from
Top Traders positions).

Generalizes the Quick Buy module so `QuickBuyTarget.chain` is a canonical
`CaipChainId` rather than a Social-API position chain name. Each host
(Top Traders, Asset Details) now normalizes its chain id into CAIP at the
boundary, decoupling the Quick Buy core from host-specific shapes.

The filled lightning icon is shipped temporarily as a local SVG asset
pending the upstream `IconName.FlashFilled` addition in the MetaMask
Design System.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Updated tests for AssetDetailsQuickBuy to ensure it mounts hidden by default with the current token.
- Added a test to verify that the Quick Buy button opens the AssetDetailsQuickBuy when pressed.
- Changed the assertion method for checking the presence of the Quick Buy button in TokenDetailsStickyFooter to use `toBeOnTheScreen()` for better clarity.
- Added a new selector to manage the visibility of the Quick Buy feature in the TokenDetails component.
- Updated the TokenDetails component to conditionally render the AssetDetailsQuickBuy based on the feature flag.
- Enhanced tests to verify the behavior of the Quick Buy button when the feature is enabled or disabled, ensuring it does not mount when disabled.
- Introduced unit tests for the new selector to validate its functionality against various scenarios.
…iant

- Updated the TokenDetails component to use the new selector `selectSocialAiAssetDetailsQuickBuyEnabled` instead of the deprecated `selectAssetDetailsShowQuickBuyEnabled`.
- Removed the old selector and its associated tests to streamline the feature flag management for Quick Buy functionality.
- Adjusted tests to ensure they reflect the changes in the selector and maintain expected behavior.
…o feature flag constants

- Introduced a new feature flag constant for the Social AI Asset Details Quick Buy functionality in the known feature flag constants file.
- Updated the feature flag registry to include the new flag, ensuring it is set to active and configured for production use.
- Added tracking for trade submission and completion events in the Quick Buy controller, allowing analytics to capture when trades are submitted and completed.
- Updated the trade properties to conditionally include the trader's address based on context, ensuring accurate analytics reporting for both trader and non-trader scenarios.
- Enhanced unit tests to verify the correct behavior of trade-level analytics, ensuring that the tracking functions are called with the expected parameters.
…orts

- Updated the TokenDetails component to improve Quick Buy integration, including the addition of new imports for better functionality.
- Refactored the TokenDetailsStickyFooter to ensure the FlashFilledIcon is correctly imported and utilized.
- Cleaned up unused imports and organized the code structure for better readability and maintainability.
- Enhanced unit tests to verify the correct behavior of the Quick Buy feature in various scenarios.
- Refactored imports in the TokenDetailsStickyFooter and QuickBuy components for improved organization and readability.
- Enhanced unit tests for TraderPositionQuickBuy and useQuickBuyController to ensure accurate functionality and coverage.
- Updated the Quick Buy setup logic to streamline the integration with Redux and improve performance.
- Cleaned up unused imports and optimized the code structure across multiple files.
Replace the local flash-filled.svg with the design system Icon
(IconName.FlashFilled) in the sticky footer quick buy button and
drop the now-obsolete asset and its test mock.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
- Updated the target calculation in AssetDetailsQuickBuy to read only the necessary primitive fields from the token, preventing unnecessary re-fetches of quotes.
- Improved dependency array in useMemo to include only relevant fields, enhancing performance and stability of the component.
The asset details quick buy target required address, symbol and name to
all be defined, so native assets (e.g. ETH) whose route params lack a
name produced a null target and the sheet never opened. Only require
chainId and address, falling back to symbol for the display name.

Co-authored-by: Cursor <cursoragent@cursor.com>
…tests

- Reordered imports in `QuickBuyContext.test.tsx` for consistency.
- Updated the chain identifier from 'base' to 'eip155:8453' in the mock target to reflect the correct blockchain context.
- Added unit tests to verify that the AssetDetailsQuickBuy component correctly passes a null target when the token address is either an empty string or null.
- Updated the target calculation logic to ensure it handles these cases appropriately.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.72%. Comparing base (044726b) to head (9a87cb9).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...kenDetails/components/TokenDetailsStickyFooter.tsx 57.14% 0 Missing and 3 partials ⚠️
...I/TokenDetails/components/AssetDetailsQuickBuy.tsx 88.23% 0 Missing and 2 partials ⚠️
...components/QuickBuy/hooks/useQuickBuyController.ts 50.00% 0 Missing and 2 partials ⚠️
.../components/UI/TokenDetails/Views/TokenDetails.tsx 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #30725    +/-   ##
========================================
  Coverage   82.72%   82.72%            
========================================
  Files        5566     5575     +9     
  Lines      143286   143474   +188     
  Branches    33099    33163    +64     
========================================
+ Hits       118529   118685   +156     
- Misses      16870    16883    +13     
- Partials     7887     7906    +19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@juanmigdr juanmigdr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, found these issues while testing (Audio ON) but @xavier-brochard has said that he will fix them all in an upcoming PR

Screen.Recording.2026-06-02.at.12.33.19.mov

@xavier-brochard xavier-brochard added this pull request to the merge queue Jun 2, 2026
Merged via the queue into main with commit 1096b41 Jun 2, 2026
155 of 159 checks passed
@xavier-brochard xavier-brochard deleted the feat/asset-details-quick-buy branch June 2, 2026 11:17
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk:medium AI analysis: medium risk size-XL skip-e2e skip E2E test jobs team-social-ai Social & AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants