Commit 35588df
authored
fix(preidct): prioritize sport market type sorting over price sorting in feed (#28602)
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->
## **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?
-->
Sport cards on the Predict feed and carousel were displaying the wrong
market type (e.g. spreads or totals) instead of moneyline. This happened
because `sortMarkets()` checked the `sortBy` parameter **before**
`isSportEvent()`. Since both `getMarkets()` and `getCarouselMarkets()`
always pass `sortMarketsBy: 'price'`, the `sortSportMarkets()` branch —
which enforces moneyline → spreads → totals ordering — was never
reached. The sport card components (`PredictMarketSportCard`,
`FeaturedCarouselSportCard`) all use `market.outcomes[0]` to select the
displayed market, so whichever market had the highest price would show
up instead of the moneyline market.
**Fix**: Move the `isSportEvent()` check above the `sortBy` check in
`sortMarkets()` so sport events always use sport-type-based ordering
regardless of the `sortBy` parameter. Non-sport events are unaffected
and continue to respect `sortBy` as before.
## **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: null
## **Related issues**
Fixes:
[PRED-814](https://consensyssoftware.atlassian.net/browse/PRED-814)
## **Manual testing steps**
```gherkin
Feature: Sport card moneyline market display
Scenario: sport cards on the feed show the moneyline market
Given the user is on the Predict tab
And the feed contains sport events with multiple market types (moneyline, spreads, totals)
When the user views a sport card on the feed
Then the card displays the moneyline market outcomes (team names with win probabilities)
And the card does not display spread or total market outcomes
Scenario: sport cards on the featured carousel show the moneyline market
Given the user is on the Predict home screen
And the featured carousel contains sport events
When the user views a sport card in the carousel
Then the card displays the moneyline market outcomes
And the card does not display spread or total market outcomes
Scenario: non-sport markets remain sorted by price
Given the user is on the Predict tab
And the feed contains non-sport prediction markets
When the user views the market cards
Then markets are sorted by price in descending order as before
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/e93b1754-ba6d-4005-a17e-110b2173f1cf
### **After**
<!-- [screenshots/recordings] -->
https://github.com/user-attachments/assets/d5fcf806-5eae-44e3-af43-57218d81063a
## **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.
<!-- Generated with the help of the pr-description AI skill -->
[PRED-814]:
https://consensyssoftware.atlassian.net/browse/PRED-814?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: small, well-tested change to market ordering logic that only
affects how sport events choose their primary market in the
feed/carousel.
>
> **Overview**
> Fixes sport event market ordering so `sortMarkets()` always applies
`sortSportMarkets()` (moneyline → spreads → totals) *before* any
`sortBy`/`event.sortBy` price-based sorting.
>
> Updates unit tests to reflect the new precedence, adding coverage that
sport events ignore both passed-in and event-level `sortBy`, while
non-sport events continue to respect price sorting.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7f885c7. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 0c26cf4 commit 35588df
File tree
2 files changed
+79
-10
lines changed- app/components/UI/Predict/providers/polymarket
2 files changed
+79
-10
lines changedLines changed: 75 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1970 | 1970 | | |
1971 | 1971 | | |
1972 | 1972 | | |
1973 | | - | |
| 1973 | + | |
1974 | 1974 | | |
1975 | | - | |
| 1975 | + | |
1976 | 1976 | | |
1977 | | - | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
1978 | 1999 | | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
1979 | 2008 | | |
1980 | 2009 | | |
1981 | 2010 | | |
| |||
1986 | 2015 | | |
1987 | 2016 | | |
1988 | 2017 | | |
1989 | | - | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
1990 | 2059 | | |
1991 | | - | |
1992 | | - | |
| 2060 | + | |
| 2061 | + | |
1993 | 2062 | | |
1994 | 2063 | | |
1995 | 2064 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
670 | 670 | | |
671 | 671 | | |
672 | 672 | | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
673 | 677 | | |
674 | 678 | | |
675 | 679 | | |
| |||
678 | 682 | | |
679 | 683 | | |
680 | 684 | | |
681 | | - | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| |||
0 commit comments