Skip to content

Commit 542ef95

Browse files
runway-github[bot]n3psmetamask-ci[bot]sleepytanya
authored
release(runway): cherry-pick fix(cashtag): skip when no market cap data (#47934)
- fix(cashtag): skip when no market cap data cp-13.58.0 (#47914) ## **Description** The X widget still rendered when every matching token had a missing or zero market cap. Those tickers now produce no result, so no pill or popover are rendered. ## **Changelog** CHANGELOG entry: Hide the X widget when none of the matching tokens have a market cap <!-- ## **Related issues** Fixes: --> ## **Manual testing steps** 1. Enable the X widget feature flag and setting. 2. On x.com, open a cashtag whose matches all have no market cap or a market cap of 0. 3. Confirm no MetaMask pill or widget appears. 4. Open a cashtag such as `$ETH` that has a market cap. 5. Confirm the widget still appears. <!-- ## **Screenshots/Recordings** ### **Before** ### **After** --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/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] > **Low Risk** > Localized cashtag lookup guard with unit tests; no auth or payment paths affected. > > **Overview** > **`resolveTicker`** now returns **`null`** when the highest market-cap match has a missing or zero market cap, so the X cashtag widget does not render for tokens without usable cap data. Matches that include at least one asset with cap **> 0** behave as before, with zero/null-cap entries still listed as similar options. > > Tests cover the all-invalid-cap case and the mixed list where a priced asset remains the primary. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 58a23cc. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> [416e0ec](416e0ec) --------- Co-authored-by: Francis Nepomuceno <n3ps@users.noreply.github.com> Co-authored-by: metamask-ci[bot] <271559518+metamask-ci[bot]@users.noreply.github.com> Co-authored-by: sleepytanya <104780023+sleepytanya@users.noreply.github.com>
1 parent e49060a commit 542ef95

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎app/scripts/cashtag/lib/data.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,57 @@ describe('resolveTicker', () => {
142142
});
143143
});
144144

145+
it('returns null when every match has no market cap', async () => {
146+
fetchMock.mockResolvedValue({
147+
ok: true,
148+
json: async () => ({
149+
data: [
150+
{
151+
assetId: 'eip155:1/erc20:0xnone',
152+
symbol: 'QQQ',
153+
name: 'No cap',
154+
marketCap: null,
155+
},
156+
{
157+
assetId: 'eip155:1/erc20:0xzero',
158+
symbol: 'QQQ',
159+
name: 'Zero cap',
160+
marketCap: 0,
161+
},
162+
],
163+
}),
164+
} as Response);
165+
166+
await expect(resolveTicker('QQQ')).resolves.toBeNull();
167+
});
168+
169+
it('keeps a match when another resource has no market cap', async () => {
170+
fetchMock.mockResolvedValue({
171+
ok: true,
172+
json: async () => ({
173+
data: [
174+
{
175+
assetId: 'eip155:1/erc20:0xzero',
176+
symbol: 'QQQ',
177+
name: 'Zero cap',
178+
marketCap: 0,
179+
},
180+
{
181+
assetId: 'eip155:1/erc20:0xpriced',
182+
symbol: 'QQQ',
183+
name: 'Priced',
184+
marketCap: 5,
185+
},
186+
],
187+
}),
188+
} as Response);
189+
190+
await expect(resolveTicker('QQQ')).resolves.toMatchObject({
191+
primary: { name: 'Priced', marketCap: 5 },
192+
similar: [expect.objectContaining({ name: 'Zero cap', marketCap: 0 })],
193+
});
194+
});
195+
145196
it('returns null for an empty ticker or an unsuccessful search', async () => {
146197
await expect(resolveTicker(' ')).resolves.toBeNull();
147198
expect(fetchMock).not.toHaveBeenCalled();

‎app/scripts/cashtag/lib/data.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ export async function resolveTicker(
144144
}
145145

146146
const assets = symbolMatches.map(toAssetData).toSorted(byMarketCap);
147+
148+
// Since assets are sorted by market cap descending, checking the first one is enough
149+
if ((assets[0].marketCap ?? 0) <= 0) {
150+
return null;
151+
}
152+
147153
return {
148154
primary: assets[0],
149155
similar: assets.slice(1),

0 commit comments

Comments
 (0)