From ba0fa5ccab17b52daa73bf1fc92a04ad0693c513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos?= Date: Wed, 25 Mar 2026 15:58:39 +0000 Subject: [PATCH] chore(runway): cherry-pick fix: hides perps buttons in ai insights when user has a position cp-7.71.0 (#27919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR is a bug fix for https://github.com/MetaMask/metamask-mobile/issues/27916 where: - In the AI Market Insights in Perps, the action buttons are wrong when user has an open position: the action buttons should be the same in AI market insight page and market page, ie. “modify” and “Close” when user has an open position Fix: - When the user has an existing perps position, the MarketInsights footer action buttons (Long/Short) are hidden since the relevant actions (modify/close) live on the Perps market details page - The "AI summary for information only" disclaimer is moved inline below the feedback section when the footer is hidden, so it remains visible - Position state is passed via route params (hasPerpsPosition) from the caller rather than fetched async inside MarketInsightsView, preventing a flash where buttons briefly appear then disappear while the position loads ## **Changelog** CHANGELOG entry: Fixed a bug that was causing incorrect Perps action buttons to be displayed ## **Related issues** Fixes: https://github.com/MetaMask/metamask-mobile/issues/27916 ## **Manual testing steps** ```gherkin - Open MarketInsights from token details → Swap/Buy buttons visible with disclaimer in footer - Open MarketInsights from perps with no position → Long/Short buttons visible with disclaimer in footer - Open MarketInsights from perps with an existing position → no footer buttons, disclaimer shown below "Was this helpful?" - Verify no flash/layout shift on the perps + position flow ``` ## **Screenshots/Recordings** ### **Before** https://github.com/user-attachments/assets/0373c1bb-d433-4c9a-8768-117a40d98f9e ### **After** SCR-20260325-nzfa ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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] > **Low Risk** > Low risk UI/navigation tweak that changes which CTAs are shown based on a new route param; main risk is incorrect param wiring causing missing actions or disclaimer placement in the Perps insights flow. > > **Overview** > Fixes Perps AI Market Insights showing inappropriate `Long`/`Short` CTAs when the user already has an open position. > > Adds a `hasPerpsPosition` route param (set by `PerpsMarketDetailsView`) and uses it in `MarketInsightsView` to **hide the footer action buttons** for Perps-with-position while **keeping the informational disclaimer visible** by moving it inline under the feedback section for that case. > > Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 833593b6e060e6e8c51a711b921f69d7b53ed4aa. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot). --- .../MarketInsightsView/MarketInsightsView.tsx | 103 ++++++++++-------- .../PerpsMarketDetailsView.tsx | 3 +- 2 files changed, 62 insertions(+), 44 deletions(-) diff --git a/app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.tsx b/app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.tsx index facf0801787..dc761d86a29 100644 --- a/app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.tsx +++ b/app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.tsx @@ -153,6 +153,8 @@ interface MarketInsightsRouteParams { tokenChainId?: string; /** When true, indicates the view was opened from the Perps market details view */ isPerps?: boolean; + /** When true, the user has an existing perps position for this asset */ + hasPerpsPosition?: boolean; } /** @@ -182,6 +184,7 @@ const MarketInsightsView: React.FC = () => { tokenName, tokenChainId, isPerps = false, + hasPerpsPosition = false, } = route.params; const isMarketInsightsEnabled = isPerps @@ -660,65 +663,79 @@ const MarketInsightsView: React.FC = () => { > {strings('market_insights.helpful_prompt')} + {isPerps && hasPerpsPosition && ( + + {strings('market_insights.footer_disclaimer')} + + )} - - {isPerps ? ( - - - - - ) : ( - - + {!(isPerps && hasPerpsPosition) && ( + + {isPerps ? ( + - - + ) : ( + + + + + + + + + )} + + + {strings('market_insights.footer_disclaimer')} + - )} - - - {strings('market_insights.footer_disclaimer')} - - + )} {selectedTrend ? ( = () => { assetSymbol: market.symbol, assetIdentifier: market.symbol, isPerps: true, + hasPerpsPosition: !!existingPosition, }); - }, [market?.symbol, navigation, track]); + }, [market?.symbol, navigation, track, existingPosition]); // Handler for order selection - navigates to order details const handleOrderSelect = useCallback(