Commit 262d190
feat: uses position id to render trader position page (#29403)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until this PR meets the canonical
Definition of Ready For Review in `docs/readme/ready-for-review.md`.
In short: the template must be materially complete (not just section
titles
present), all status checks must be currently passing, and the only
expected
follow-up commits must be reviewer-driven.
-->
## **Description**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
https://github.com/user-attachments/assets/5c903575-d495-49ef-8462-986d76558f5a
`TraderPositionView` previously could only be reached by tapping a row
in `TraderProfileView` because it required the full `Position` object as
a route param. This PR makes the screen self-sufficient: given just
`traderId + positionId`, it fetches the canonical position by UUID and
the trader profile on its own. The existing row-tap path is unchanged —
when `position` is passed it's used directly, no fetch fires.
This is the foundation for deep-link support (push notifications, shared
URLs); the `linking` URL config itself lands in a separate PR.
## What changed
**New `useTraderPosition(positionId)` hook**
Wraps `SocialService.fetchPositionById({ positionId })` via `useQuery`,
mirroring the pattern used by `useTraderPositions` and
`useTraderProfile`. Disabled when `positionId` is undefined, so the
row-tap path pays zero network cost.
**Three explicit render states in `TraderPositionView`**
- **Content** — `position` resolved (from row-tap snapshot or canonical
fetch).
- **Skeleton** — fetch in flight and no bootstrap available (cold-start
deep link).
- **Fallback** — fetch failed and no bootstrap; renders an error
illustration with a "back to profile" CTA.
**`TraderPositionSkeleton` and `TraderPositionFallback` components**
Lifted from PR #29378 (which also wanted these). They're
framework-agnostic — no dependency on the alternate matching scheme used
in that PR — so they drop in cleanly here.
**Trader name/image self-resolution**
`traderName` and `traderImageUrl` are now optional in the route
contract. When absent (e.g. arriving via deep link with only IDs), the
screen calls the existing `useTraderProfile(traderId)` hook to populate
the header. Row-tap still passes them, so no extra fetch on that path.
**Route contract update**
```ts
// Before
TraderPositionView: {
traderId: string;
traderName: string;
traderImageUrl?: string;
tokenSymbol: string;
position?: Position;
};
// After
TraderPositionView: {
traderId: string;
tokenSymbol: string;
position?: Position; // row-tap snapshot (no fetch)
positionId?: string; // deep-link path (triggers fetch)
traderName?: string; // resolved via useTraderProfile if absent
traderImageUrl?: string; // resolved via useTraderProfile if absent
};
```
At least one of `position` or `positionId` must be passed. Old call
sites (`TraderProfileView` row-tap) are unchanged.
## Why `positionId` rather than a composite key
Compared to the alternative of identifying a position by `(tokenAddress,
chain, positionContext)`:
- `positionId` is the canonical UUID minted by the backend. Two
re-entered positions on the same token never collide.
- No address normalisation is needed. No EVM-vs-Solana case rules. No
hardcoded chain allowlist that needs updating when a new chain ships.
- Robust to position state transitions — open → closed mid-flight
doesn't break URL resolution because we don't bake the open/closed flag
into the identifier.
- Mirrors the API: `GET /v1/traders/:traderId/positions/:positionId`.
## Out of scope (TODOs)
- **Deep-link URL config.** `NavigationContainer linking` mapping
`leaderboard/:traderId/positions/:positionId` → `TraderPositionView`.
Lands in a follow-up.
- **Background refresh / polling.** Once the screen is open, the
position is a static snapshot. Future change: add `refetchInterval` to
`useTraderPosition` and, on the row-tap path, also kick off a background
fetch keyed by `position.positionId` to refresh + poll. Same
canonical-only-after-resolve policy used elsewhere.
- **Push-notification payload prefetch.** If notifications carry
`traderName`, pass it through to skip the `useTraderProfile` fetch on
cold-start.
## Files changed
| File | Change |
|---|---|
| `hooks/useTraderPosition.ts` | NEW — single-position fetch via
`SocialService:fetchPositionById` |
| `hooks/useTraderPosition.test.ts` | NEW — 5 unit tests (query key,
disabled state, success, loading, error) |
| `components/TraderPositionSkeleton.tsx` | NEW — full-screen skeleton |
| `components/TraderPositionFallback.tsx` | NEW — error state with
back-to-profile CTA |
| `TraderPositionView.tsx` | Resolve position via row-tap → hook
fallback; resolve trader profile via `useTraderProfile` fallback; render
skeleton / fallback / content |
| `TraderPositionView.testIds.ts` | Added SKELETON / FALLBACK /
FALLBACK_PRIMARY_ACTION test IDs |
| `TraderPositionView.test.tsx` | New mocks for the two new hooks;
replaced two stale tests + added 3 new flow tests |
| `core/NavigationService/types.ts` | Made `traderName`/`traderImageUrl`
optional; added `positionId?: string` |
| `locales/languages/en.json` | Added 4 fallback strings |
No changes to `TraderProfileView` — row-tap fast path stays free of any
extra fetch.
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: no-changelog
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
<!--
Every checklist item must be consciously assessed before marking this PR
as
"Ready for review". A checked box means you deliberately considered that
responsibility, not that you literally performed every action listed.
Unchecked boxes are ambiguous: they are not an implicit "N/A" and they
are not
a silent "skip". See `docs/readme/ready-for-review.md` for the full
checklist
semantics.
-->
- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I've included tests if applicable
- [ ] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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.
#### 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](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **Pre-merge reviewer checklist**
<!--
Reviewer checklist items follow the same semantics as the author
checklist: an
unchecked box is ambiguous, a checked box means the reviewer consciously
assessed that responsibility. See `docs/readme/ready-for-review.md`.
-->
- [ ] 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]
> **Medium Risk**
> Adds new data-fetching paths and route contract changes for
`TraderPositionView`, which could affect deep-link/edge-case navigation
and initial loading behavior, but scope is limited to the Social
Leaderboard feature.
>
> **Overview**
> `TraderPositionView` can now be opened without an in-memory `position`
snapshot by optionally accepting a `positionId` route param and fetching
the canonical position via a new `useTraderPosition` hook;
`traderName`/`traderImageUrl` are also now optional and are fetched via
`useTraderProfile` when missing.
>
> The screen adds explicit **skeleton**, **fallback**, and **content**
render states (with new
`TraderPositionSkeleton`/`TraderPositionFallback` components and i18n
strings), gates Quick Buy to only open once a position is resolved, and
updates/extends tests and test IDs to cover the new flows. Dependency
`@metamask/social-controllers` is bumped to `^2.2.0` to support the new
fetch-by-id API.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7ba0bd0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: António Regadas <antonio.regadas@consensys.net>1 parent cdbc929 commit 262d190
11 files changed
Lines changed: 562 additions & 78 deletions
File tree
- app
- components/Views/SocialLeaderboard/TraderPositionView
- components
- hooks
- locales/languages
Lines changed: 74 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
83 | 104 | | |
84 | 105 | | |
85 | 106 | | |
| |||
184 | 205 | | |
185 | 206 | | |
186 | 207 | | |
187 | | - | |
| 208 | + | |
188 | 209 | | |
189 | 210 | | |
190 | 211 | | |
191 | 212 | | |
192 | 213 | | |
193 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
194 | 219 | | |
195 | 220 | | |
196 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
197 | 229 | | |
198 | | - | |
| 230 | + | |
199 | 231 | | |
200 | 232 | | |
201 | 233 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
206 | 272 | | |
207 | 273 | | |
208 | 274 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
Lines changed: 97 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | | - | |
35 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
42 | 63 | | |
43 | 64 | | |
44 | 65 | | |
| |||
55 | 76 | | |
56 | 77 | | |
57 | 78 | | |
58 | | - | |
| 79 | + | |
59 | 80 | | |
60 | 81 | | |
61 | 82 | | |
62 | 83 | | |
63 | 84 | | |
64 | 85 | | |
65 | | - | |
66 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
67 | 90 | | |
68 | 91 | | |
69 | 92 | | |
| |||
73 | 96 | | |
74 | 97 | | |
75 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
76 | 104 | | |
77 | 105 | | |
78 | 106 | | |
| |||
84 | 112 | | |
85 | 113 | | |
86 | 114 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
143 | 179 | | |
144 | 180 | | |
145 | 181 | | |
| |||
0 commit comments