Skip to content

Commit 16dafe9

Browse files
chore(runway): cherry-pick fix(predict): cp-7.62.0 use bestAsk from live price updates (buy) (#24894)
- fix(predict): cp-7.62.0 use bestAsk from live price updates (buy) (#24852) ## **Description** Updates unit tests for `PredictActionButtons` and `PredictGameChart` components to accommodate the logic change from using `price` to `bestAsk` for live price updates. 1. **Reason for change**: The components were updated to use `bestAsk` (the ask price) instead of `price` from live price updates for more accurate pricing display. 2. **Solution**: Updated test expectations and mock data to reflect the new `bestAsk` usage. ## **Changelog** CHANGELOG entry: null ## **Related issues** https://consensyssoftware.atlassian.net/browse/PRED-491 ## **Manual testing steps** ```gherkin Feature: Unit tests for Predict components Scenario: Tests pass with bestAsk price logic Given the test suite is run When running yarn jest PredictActionButtons.test.tsx PredictGameChart.wrapper.test.tsx Then all tests pass successfully ``` ## **Screenshots/Recordings** N/A - Test-only changes ### **Before** N/A ### **After** N/A ## **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] > Adopts `bestAsk` from live price updates for more accurate displayed buy prices. > > - Updates `PredictActionButtons.tsx` to use `yesLivePrice.bestAsk` / `noLivePrice.bestAsk` when available > - Updates `PredictGameChart.tsx` live update logic to compute values from `bestAsk` > - Adjusts unit tests and mocks to include `bestAsk` fields and new expected cent values (e.g., 72→73, 80→81, 55→56) > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit c99ff04. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> [52b9241](52b9241) Co-authored-by: Luis Taniça <matallui@gmail.com>
1 parent 6932d5a commit 16dafe9

4 files changed

Lines changed: 78 additions & 24 deletions

File tree

app/components/UI/Predict/components/PredictActionButtons/PredictActionButtons.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ describe('PredictActionButtons', () => {
361361

362362
renderWithProvider(<PredictActionButtons {...props} />);
363363

364-
expect(screen.getByText('YES · 72¢')).toBeOnTheScreen();
365-
expect(screen.getByText('NO · 28¢')).toBeOnTheScreen();
364+
expect(screen.getByText('YES · 73¢')).toBeOnTheScreen();
365+
expect(screen.getByText('NO · 29¢')).toBeOnTheScreen();
366366
});
367367

368368
it('falls back to static prices when live prices unavailable', () => {
@@ -397,7 +397,7 @@ describe('PredictActionButtons', () => {
397397

398398
renderWithProvider(<PredictActionButtons {...props} />);
399399

400-
expect(screen.getByText('YES · 80¢')).toBeOnTheScreen();
400+
expect(screen.getByText('YES · 81¢')).toBeOnTheScreen();
401401
expect(screen.getByText('NO · 35¢')).toBeOnTheScreen();
402402
});
403403

@@ -459,8 +459,8 @@ describe('PredictActionButtons', () => {
459459

460460
renderWithProvider(<PredictActionButtons {...props} />);
461461

462-
expect(screen.getByText('SEA · 55¢')).toBeOnTheScreen();
463-
expect(screen.getByText('DEN · 45¢')).toBeOnTheScreen();
462+
expect(screen.getByText('SEA · 56¢')).toBeOnTheScreen();
463+
expect(screen.getByText('DEN · 46¢')).toBeOnTheScreen();
464464
});
465465
});
466466
});

app/components/UI/Predict/components/PredictActionButtons/PredictActionButtons.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ const PredictActionButtons: React.FC<PredictActionButtonsProps> = ({
4040
const yesLivePrice = getPrice(yesToken.id);
4141
const noLivePrice = getPrice(noToken.id);
4242

43-
const yesPrice = yesLivePrice?.price ?? yesToken.price;
44-
const noPrice = noLivePrice?.price ?? noToken.price;
43+
const yesPrice = yesLivePrice?.bestAsk ?? yesToken.price;
44+
const noPrice = noLivePrice?.bestAsk ?? noToken.price;
4545

4646
if (isGameMarket && market.game) {
4747
const { awayTeam, homeTeam } = market.game;

app/components/UI/Predict/components/PredictGameChart/PredictGameChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const PredictGameChart: React.FC<PredictGameChartProps> = ({
139139
const lastPoint = existingData[existingData.length - 1];
140140

141141
const newValue = priceUpdate
142-
? Number((priceUpdate.price * 100).toFixed(2))
142+
? Number((priceUpdate.bestAsk * 100).toFixed(2))
143143
: (lastPoint?.value ?? 50);
144144

145145
const newPoint: GameChartDataPoint = {

app/components/UI/Predict/components/PredictGameChart/PredictGameChart.wrapper.test.tsx

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,24 @@ describe('PredictGameChart Wrapper', () => {
385385
});
386386

387387
const pricesMap = new Map([
388-
['token-a', { tokenId: 'token-a', price: 0.55, timestamp: Date.now() }],
389-
['token-b', { tokenId: 'token-b', price: 0.45, timestamp: Date.now() }],
388+
[
389+
'token-a',
390+
{
391+
tokenId: 'token-a',
392+
price: 0.54,
393+
bestAsk: 0.56,
394+
timestamp: Date.now(),
395+
},
396+
],
397+
[
398+
'token-b',
399+
{
400+
tokenId: 'token-b',
401+
price: 0.44,
402+
bestAsk: 0.46,
403+
timestamp: Date.now(),
404+
},
405+
],
390406
]);
391407

392408
mockUseLiveMarketPrices.mockReturnValue({
@@ -424,10 +440,8 @@ describe('PredictGameChart Wrapper', () => {
424440
const dataText = getByTestId('content-data').children[0];
425441
const data = JSON.parse(String(dataText));
426442

427-
// Should still have 1 data point (updated, not added)
428443
expect(data[0].data).toHaveLength(1);
429-
// Value should be updated to new price
430-
expect(data[0].data[0].value).toBe(55);
444+
expect(data[0].data[0].value).toBe(56);
431445
});
432446
});
433447

@@ -469,8 +483,24 @@ describe('PredictGameChart Wrapper', () => {
469483
jest.setSystemTime(new Date(nextMinute));
470484

471485
const pricesMap = new Map([
472-
['token-a', { tokenId: 'token-a', price: 0.55, timestamp: nextMinute }],
473-
['token-b', { tokenId: 'token-b', price: 0.45, timestamp: nextMinute }],
486+
[
487+
'token-a',
488+
{
489+
tokenId: 'token-a',
490+
price: 0.54,
491+
bestAsk: 0.56,
492+
timestamp: nextMinute,
493+
},
494+
],
495+
[
496+
'token-b',
497+
{
498+
tokenId: 'token-b',
499+
price: 0.44,
500+
bestAsk: 0.46,
501+
timestamp: nextMinute,
502+
},
503+
],
474504
]);
475505

476506
mockUseLiveMarketPrices.mockReturnValue({
@@ -560,7 +590,8 @@ describe('PredictGameChart Wrapper', () => {
560590
'token-a',
561591
{
562592
tokenId: 'token-a',
563-
price: 0.55,
593+
price: 0.54,
594+
bestAsk: 0.56,
564595
timestamp: baseTimestamp + 120000,
565596
},
566597
],
@@ -609,7 +640,12 @@ describe('PredictGameChart Wrapper', () => {
609640
const pricesMap = new Map([
610641
[
611642
'token-a',
612-
{ tokenId: 'token-a', price: 0.65, timestamp: baseTimestamp + 30000 },
643+
{
644+
tokenId: 'token-a',
645+
price: 0.64,
646+
bestAsk: 0.66,
647+
timestamp: baseTimestamp + 30000,
648+
},
613649
],
614650
]);
615651

@@ -632,7 +668,7 @@ describe('PredictGameChart Wrapper', () => {
632668
const dataText = getByTestId('content-data').children[0];
633669
const data = JSON.parse(String(dataText));
634670

635-
expect(data[0].data[0].value).toBe(65);
671+
expect(data[0].data[0].value).toBe(66);
636672
expect(data[1].data[0].value).toBe(40);
637673
});
638674
});
@@ -656,11 +692,21 @@ describe('PredictGameChart Wrapper', () => {
656692
const pricesMap = new Map([
657693
[
658694
'token-a',
659-
{ tokenId: 'token-a', price: 0.7, timestamp: baseTimestamp + 30000 },
695+
{
696+
tokenId: 'token-a',
697+
price: 0.69,
698+
bestAsk: 0.71,
699+
timestamp: baseTimestamp + 30000,
700+
},
660701
],
661702
[
662703
'token-b',
663-
{ tokenId: 'token-b', price: 0.3, timestamp: baseTimestamp + 30000 },
704+
{
705+
tokenId: 'token-b',
706+
price: 0.29,
707+
bestAsk: 0.31,
708+
timestamp: baseTimestamp + 30000,
709+
},
664710
],
665711
]);
666712

@@ -682,7 +728,7 @@ describe('PredictGameChart Wrapper', () => {
682728
await waitFor(() => {
683729
const dataText = getByTestId('content-data').children[0];
684730
const data = JSON.parse(String(dataText));
685-
expect(data[0].data[0].value).toBe(70);
731+
expect(data[0].data[0].value).toBe(71);
686732
});
687733

688734
const refetchedHistories = [
@@ -709,8 +755,8 @@ describe('PredictGameChart Wrapper', () => {
709755
const dataText = getByTestId('content-data').children[0];
710756
const data = JSON.parse(String(dataText));
711757

712-
expect(data[0].data[0].value).toBe(70);
713-
expect(data[1].data[0].value).toBe(30);
758+
expect(data[0].data[0].value).toBe(71);
759+
expect(data[1].data[0].value).toBe(31);
714760
});
715761
});
716762
});
@@ -894,7 +940,15 @@ describe('PredictGameChart Wrapper', () => {
894940

895941
// Only provide price for token-a
896942
const pricesMap = new Map([
897-
['token-a', { tokenId: 'token-a', price: 0.55, timestamp: Date.now() }],
943+
[
944+
'token-a',
945+
{
946+
tokenId: 'token-a',
947+
price: 0.54,
948+
bestAsk: 0.56,
949+
timestamp: Date.now(),
950+
},
951+
],
898952
]);
899953

900954
mockUseLiveMarketPrices.mockReturnValue({

0 commit comments

Comments
 (0)