Commit 46c79cb
authored
fix(perps): missing max leverage badge in screen header (MetaMask#24133)
## **Description**
Fixes missing max leverage badge in the asset screen header when
navigating from Recent Activity → Trade Details → "Trade again" button.
**Root cause:** `PerpsPositionTransactionView` was creating a minimal
market object with only `symbol` and `name` fields, missing
`maxLeverage` and other required properties.
**Solution:** Use `usePerpsMarkets` hook to get the complete market data
(same pattern as `PerpsCard`). This hook:
- Uses shared cached market data (no duplicate network requests)
- Provides immediate data if already cached
- Follows established patterns in the codebase
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2187
## **Manual testing steps**
```gherkin
Feature: Max leverage badge in asset screen header
Scenario: User navigates from Recent Activity to asset details
Given user has recent trading activity
And user is on Perps home screen
When user taps on a recent activity item
Then user sees trade details screen
When user taps "Trade again" button
Then user sees asset details screen
And max leverage badge is visible in header (e.g., "25x" for ETH)
```
## **Screenshots/Recordings**
### **Before**
Max leverage badge missing in header when navigating from Recent
Activity
https://github.com/user-attachments/assets/41ddb087-9c41-419d-ade9-29d0c47b091d
### **After**
Max leverage badge visible in header (e.g., "25x" for ETH)
https://github.com/user-attachments/assets/e1aa5432-abb4-4ae9-9404-9c7290bb40a1
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Ensures the market header shows correct max leverage by enriching
minimal route market data via `usePerpsMarkets` and hiding the badge
when unavailable, with accompanying tests.
>
> - **Perps Market Details**:
> - Enriches route `market` using `usePerpsMarkets` when `maxLeverage`
is missing; skips fetch if not needed.
> - Uses enriched/route `market` across the view; updates navbar setup
accordingly.
> - **Header**:
> - Renders `PerpsLeverage` only when `market.maxLeverage` exists.
> - **Transactions**:
> - `PerpsPositionTransactionView` navigates with minimal `{ symbol,
name }`; relies on details view enrichment.
> - **Tests**:
> - Add market data enrichment tests in
`PerpsMarketDetailsView.test.tsx` (full, minimal, and missing enrichment
cases).
> - Update transaction view test to assert navigation with minimal
market data.
> - Add header test for rendering without `maxLeverage`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9ed6c86. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 3f58ef5 commit 46c79cb
6 files changed
Lines changed: 271 additions & 91 deletions
File tree
- app/components/UI/Perps
- Views
- PerpsMarketDetailsView
- PerpsTransactionsView
- components/PerpsMarketHeader
Lines changed: 146 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
272 | 289 | | |
273 | 290 | | |
274 | 291 | | |
| |||
356 | 373 | | |
357 | 374 | | |
358 | 375 | | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
| 376 | + | |
366 | 377 | | |
367 | 378 | | |
368 | 379 | | |
| |||
2187 | 2198 | | |
2188 | 2199 | | |
2189 | 2200 | | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
2190 | 2329 | | |
0 commit comments