Commit 74dbb8d
authored
chore(predict): opt in useNavigation to AppNavigationProp (Phase 4) (#33458)
<!--
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.
-->
<!--
mms-check directive vocabulary — read by
.github/scripts/shared/pr-template-checks.ts
at module load to build the validation plan. Directives are invisible in
rendered
markdown and must NOT be removed or edited without updating the
validator registry.
type=text Section must contain non-placeholder prose.
type=changelog Section must have a valid CHANGELOG entry: line.
type=issue-link Section must have a Fixes:/Closes:/Refs: line with a
value.
type=manual-testing Section must have real testing steps or an explicit
N/A.
type=screenshot Section must have evidence (image/URL) or an explicit
N/A.
type=checklist Section must have all checkboxes consciously checked.
required=true|false Whether a missing/invalid section runs the validator
at all.
blocking=true|false Whether a failure of this check fails the CI
workflow.
Default: false — failures are shown as warnings in the sticky
comment but do not block the PR.
Sections without a directive are checked for structural presence only.
-->
## **Description**
<!-- mms-check: type=text required=true -->
<!--
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?
-->
**Phase 4 of the incremental React Navigation typing migration — Predict
feature.**
Predict production call sites still used untyped `useNavigation()` (or
the feature-local `NavigationProp<PredictNavigationParamList>` /
`NativeStackNavigationProp<PredictNavigationParamList>`), so they were
checked only against the Predict param list (or the loose global
`ReactNavigation.RootParamList`) and could not enforce route names /
params against the app-wide `RootStackParamList`. This PR opts Predict
into the strict path via `useNavigation<AppNavigationProp>()` (and
`AppStackNavigationProp` where stack-only APIs are needed).
This is effectively **types-only**
### What changed
1. **Opt-in across Predict (~51 production files)**
- `useNavigation()` /
`useNavigation<NavigationProp<PredictNavigationParamList>>()` →
`useNavigation<AppNavigationProp>()`
- Added `import type { AppNavigationProp }` from
`app/core/NavigationService/types`
- Covers feed / home sections, market cards, market details, positions,
transactions, buy/sell previews, buy-with-any-token, add-funds,
world-cup modules, GTM modal, and hooks
2. **Guard prop retype**
(`app/components/UI/Predict/hooks/usePredictActionGuard.ts`)
- `navigation: NavigationProp<PredictNavigationParamList>` →
`navigation: AppNavigationProp`, so callers passing the root-typed
navigation no longer clash with the guard
3. **Stack-only APIs use `AppStackNavigationProp`**
(`app/components/UI/Predict/views/PredictBuyWithAnyToken/hooks/usePredictBuyActions.ts`)
-
`useNavigation<NativeStackNavigationProp<PredictNavigationParamList>>()`
→ `useNavigation<AppStackNavigationProp>()` (needs native-stack
`transitionEnd` event + `StackActions.pop()`)
- Dropped the now-unused `NativeStackNavigationProp` import
4. **Removed a redundant cast**
(`app/components/UI/Predict/views/PredictMarketDetails/PredictMarketDetails.tsx`)
- The Polymarket-resolution Webview navigation previously did
`(navigation as unknown as AppNavigationProp).navigate(...)` because
`navigation` was typed to the Predict stack. Now that `navigation` is
`AppNavigationProp`, the cast (and its TODO) are gone
5. **`PredictEntryPoint` widened**
(`app/components/UI/Predict/types/navigation.ts`)
- Added `REWARDS`, `GTM_MODAL`, `BUY_PREVIEW` entry points that were
already used at runtime but not part of the type union
6. **`AppStackNavigationProp` JSDoc clarified**
(`app/core/NavigationService/types.ts`)
- Documents that it is for stack-only APIs (incl. native-stack events
like `transitionEnd`) and remains keyed to the loose global
`RootParamList` during Phase 4; prefer `AppNavigationProp` for strict
route/param checking
## **Changelog**
<!-- mms-check: type=changelog required=true blocking=true -->
<!--
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:null
## **Related issues**
<!-- mms-check: type=issue-link required=true -->
Fixes:https://consensyssoftware.atlassian.net/browse/MCWP-675
## **Manual testing steps**
<!-- mms-check: type=manual-testing required=true -->
N/A
## **Screenshots/Recordings**
<!-- mms-check: type=screenshot required=true -->
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
N/A
## **Pre-merge author checklist**
<!-- mms-check: type=checklist required=true -->
<!--
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.
-->
- [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.
#### 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`.
-->
- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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]
> **Low Risk**
> Types-only refactor across Predict navigation; no logic changes beyond
removing an unsafe cast that should now type-check correctly.
>
> **Overview**
> **Phase 4** of the React Navigation typing migration: Predict
production code now uses app-wide navigation types instead of untyped
`useNavigation()` or `NavigationProp<PredictNavigationParamList>`.
>
> Across **~50+ Predict files** (components, views, hooks, contexts),
call sites switch to `useNavigation<AppNavigationProp>()` with imports
from `core/NavigationService/types`. **`usePredictActionGuard`** now
expects `AppNavigationProp`, so guarded flows align with root stack
typing. **`usePredictBuyActions`** uses `AppStackNavigationProp` for
stack-only APIs (e.g. `transitionEnd`, `StackActions`).
>
> In **`PredictMarketDetails`**, Polymarket resolution Webview
navigation drops the `(navigation as unknown as AppNavigationProp)` cast
now that navigation is already root-typed.
>
> **`PredictEntryPoint`** adds `REWARDS`, `GTM_MODAL`, and `BUY_PREVIEW`
to match runtime analytics usage. **`AppStackNavigationProp`** JSDoc
notes when to prefer it vs `AppNavigationProp` during Phase 4.
>
> No intended runtime behavior change—compile-time route/param checking
against `RootStackParamList`.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1c81771. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent cd436a6 commit 74dbb8d
54 files changed
Lines changed: 155 additions & 202 deletions
File tree
- app
- components/UI/Predict
- components
- FeaturedCarousel
- PredictActivityDetail
- PredictActivity
- PredictAddFundsSheet
- PredictBalance
- PredictCryptoUpDownMarketCard
- PredictCryptoUpDownPositions
- PredictDetailsHeaderSkeleton
- PredictGTMModal
- PredictMarketMultiple
- PredictMarketOutcome
- PredictMarketSingle
- PredictMarketSportCard
- PredictNewButton
- PredictPositionsEmpty
- PredictPositionsHeader
- PredictPositionsList
- PredictPositionsViewHeader
- PredictWorldCupMainFeedBanner
- PredictWorldCupWinnerModule
- contexts
- hooks
- types
- views
- PredictAddFundsModal
- PredictBuyPreview
- PredictBuyWithAnyToken
- components
- PredictBuyPreviewHeader
- PredictPayWithRow
- hooks
- PredictFeedView
- PredictFeed
- PredictHome
- components
- PredictCategoriesSection
- PredictLiveNowSection
- PredictPopularTodaySection
- PredictPortfolio
- PredictTrendingSection
- PredictMarketDetails
- PredictPositionsView
- PredictSellPreview
- PredictTransactionsView
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 25 | + | |
28 | 26 | | |
29 | 27 | | |
30 | 28 | | |
| |||
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | | - | |
51 | | - | |
| 48 | + | |
52 | 49 | | |
53 | 50 | | |
54 | 51 | | |
| |||
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 29 | + | |
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
| |||
66 | 64 | | |
67 | 65 | | |
68 | 66 | | |
69 | | - | |
70 | | - | |
| 67 | + | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
Lines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
| |||
Lines changed: 4 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 58 | + | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
| |||
1124 | 1122 | | |
1125 | 1123 | | |
1126 | 1124 | | |
1127 | | - | |
1128 | | - | |
| 1125 | + | |
1129 | 1126 | | |
1130 | 1127 | | |
1131 | 1128 | | |
| |||
Lines changed: 3 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
| |||
45 | 42 | | |
46 | 43 | | |
47 | 44 | | |
48 | | - | |
49 | 45 | | |
50 | 46 | | |
51 | 47 | | |
| |||
62 | 58 | | |
63 | 59 | | |
64 | 60 | | |
65 | | - | |
66 | | - | |
| 61 | + | |
67 | 62 | | |
68 | 63 | | |
69 | 64 | | |
| |||
app/components/UI/Predict/components/PredictDetailsHeaderSkeleton/PredictDetailsHeaderSkeleton.tsx
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
0 commit comments