Commit af6ba34
authored
feat: allow add account predict flow (#22856)
## **Description**
Switches the reward point calculation for predict from a hard coded
approach to using the rewards API. It also uses the same approach
recently introduced in the swaps flow, to allow add their account if
it's not correctly tied to their rewards subscription.
## **Changelog**
CHANGELOG entry: Estimate reward points in predict flow
## **Related issues**
Fixes: https://consensyssoftware.atlassian.net/browse/RWDS-801
## **Screenshots/Recordings**
### **After**
<img width="732" height="1041" alt="Screenshot-88"
src="https://github.com/user-attachments/assets/9e4e27c6-2fab-4382-8d0f-69d861f4780b"
/>
---
<img width="701" height="823" alt="Screenshot-2025-11-18-10:30:28"
src="https://github.com/user-attachments/assets/b8fd489e-610a-422c-8d23-67ae24daa4d3"
/>
---
<img width="500" height="600" alt="Screenshot-2025-11-18-10:31:15"
src="https://github.com/user-attachments/assets/64bbfc9e-4bd2-48e7-9574-479f6299a2f5"
/>
---
<img width="774" height="307" alt="Screenshot-2025-11-18-10:32:21"
src="https://github.com/user-attachments/assets/996f3b03-dfc2-4897-8c65-2d81b8e584a2"
/>
## **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**
- [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]
> Switch Predict to API-based points estimation with opt-in handling,
update UI to show points/add-account, and extend rewards types/tests.
>
> - **Predict flow**:
> - Update `PredictBuyPreview` to use `usePredictRewards(totalFee)` and
drive rewards UI; compute `shouldShowRewardsRow` and pass
`accountOptedIn`, `estimatedPoints`, loading/error to
`PredictFeeSummary`.
> - `PredictFeeSummary` props renamed `shouldShowRewards` →
`shouldShowRewardsRow`; add `accountOptedIn`, error tooltip; render
`AddRewardsAccount` when not opted in; wire `RewardPointsAnimation`
states.
> - **Hook: `usePredictRewards`**:
> - New signature accepts `totalFeeAmountUsd`; selects multichain
account by `POLYGON_MAINNET_CAIP_CHAIN_ID` and formats CAIP-10 without
bridge-controller.
> - Checks feature flag and subscription, opt-in status/support;
estimates points via `RewardsController:estimatePoints` using
`POLYGON_USDC_CAIP_ASSET_ID` and `parseUnits` with 6 decimals.
> - Subscribes to `RewardsController:accountLinked`; returns
`{enabled,isLoading,accountOptedIn,shouldShowRewardsRow,estimatedPoints,hasError}`.
> - **Rewards UI**:
> - `RewardPointsAnimation`: make `infoOnPress` optional; hide info icon
unless provided; support `hideValue` from hook.
> - **Types/Constants**:
> - Extend rewards types with `EstimatePredictContextDto`, add `PREDICT`
to `PointsEventEarnType`.
> - Add `POLYGON_USDC_CAIP_ASSET_ID` constant.
> - **Tests**:
> - Comprehensive updates for new props/flows, loading/error states,
subscription/opt-in paths, and animation behavior.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
dadabd0. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent f01fb75 commit af6ba34
File tree
10 files changed
+845
-200
lines changed- app
- components/UI
- Predict
- components/PredictFeeSummary
- hooks
- providers/polymarket
- views/PredictBuyPreview
- Rewards/components/RewardPointsAnimation
- core/Engine/controllers/rewards-controller
10 files changed
+845
-200
lines changedLines changed: 180 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
13 | 33 | | |
14 | 34 | | |
15 | 35 | | |
| |||
52 | 72 | | |
53 | 73 | | |
54 | 74 | | |
55 | | - | |
56 | | - | |
| 75 | + | |
| 76 | + | |
57 | 77 | | |
58 | 78 | | |
59 | 79 | | |
60 | 80 | | |
61 | 81 | | |
62 | 82 | | |
| 83 | + | |
| 84 | + | |
63 | 85 | | |
64 | 86 | | |
65 | 87 | | |
| |||
70 | 92 | | |
71 | 93 | | |
72 | 94 | | |
73 | | - | |
| 95 | + | |
74 | 96 | | |
75 | 97 | | |
76 | | - | |
| 98 | + | |
77 | 99 | | |
78 | 100 | | |
79 | 101 | | |
| |||
84 | 106 | | |
85 | 107 | | |
86 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
87 | 127 | | |
88 | 128 | | |
89 | 129 | | |
| |||
173 | 213 | | |
174 | 214 | | |
175 | 215 | | |
176 | | - | |
| 216 | + | |
177 | 217 | | |
178 | 218 | | |
179 | | - | |
| 219 | + | |
180 | 220 | | |
181 | 221 | | |
182 | 222 | | |
| |||
186 | 226 | | |
187 | 227 | | |
188 | 228 | | |
| 229 | + | |
189 | 230 | | |
190 | 231 | | |
191 | | - | |
| 232 | + | |
192 | 233 | | |
193 | 234 | | |
194 | | - | |
| 235 | + | |
| 236 | + | |
195 | 237 | | |
196 | 238 | | |
197 | 239 | | |
| |||
203 | 245 | | |
204 | 246 | | |
205 | 247 | | |
206 | | - | |
| 248 | + | |
207 | 249 | | |
208 | 250 | | |
209 | | - | |
| 251 | + | |
| 252 | + | |
210 | 253 | | |
211 | 254 | | |
212 | 255 | | |
| |||
215 | 258 | | |
216 | 259 | | |
217 | 260 | | |
218 | | - | |
| 261 | + | |
219 | 262 | | |
220 | 263 | | |
221 | | - | |
| 264 | + | |
| 265 | + | |
222 | 266 | | |
223 | 267 | | |
224 | 268 | | |
225 | 269 | | |
226 | 270 | | |
227 | 271 | | |
228 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
229 | 395 | | |
230 | 396 | | |
231 | 397 | | |
232 | 398 | | |
233 | 399 | | |
234 | 400 | | |
235 | | - | |
| 401 | + | |
| 402 | + | |
236 | 403 | | |
237 | 404 | | |
238 | 405 | | |
| |||
Lines changed: 21 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| |||
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
90 | | - | |
| 93 | + | |
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
| |||
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
| |||
0 commit comments