-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathtrending-api-mocks.ts
More file actions
315 lines (309 loc) · 8.71 KB
/
trending-api-mocks.ts
File metadata and controls
315 lines (309 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
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
import { MockEventsObject } from '../../framework';
/**
* Minimal HTML returned for favicon fetch mocks.
* The favicon utility (app/util/favicon/index.ts) makes GET requests to
* site origins to extract <link rel="icon"> tags from the HTML source.
* These mocks prevent unmocked live requests during E2E tests.
*/
const FAVICON_HTML =
'<html><head><link rel="icon" href="/favicon.ico"></head><body></body></html>';
const TRENDING_TOKENS_RESPONSE = [
{
assetId: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
symbol: 'USDC',
name: 'USD Coin',
decimals: 6,
price: '1.00',
aggregatedUsdVolume: 1000000,
marketCap: 1000000000,
priceChangePct: {
h24: '0.01',
},
},
];
export const RWA_STOCK_ASSET_ID =
'eip155:1/erc20:0x96f6ef951840721adbf46ac996b59e0235cb985c';
const RWA_TOKENS_SEARCH_RESPONSE = {
count: 1,
data: [
{
assetId: RWA_STOCK_ASSET_ID,
symbol: 'USDY',
name: 'Ondo US Dollar Yield (Ondo Tokenized)',
decimals: 18,
price: '1.05',
aggregatedUsdVolume: 500000,
marketCap: 200000000,
pricePercentChange1d: '0.12',
rwaData: { type: 'rwa' },
},
],
};
/**
* Geolocation mock returning a non-restricted country (AR) so the RWA/Stocks
* section is visible in CI. useRwaTokens hides Stocks when isGeoRestricted
* (missing or ONDO_RESTRICTED_COUNTRIES). GeolocationController can overwrite
* fixture state; mocking ensures the app always gets AR if it fetches geo.
*/
const TRENDING_GEOLOCATION_MOCKS_GET = [
{
urlEndpoint: 'https://on-ramp.dev-api.cx.metamask.io/geolocation',
responseCode: 200,
response: 'AR',
priority: 1001,
},
{
urlEndpoint: 'https://on-ramp.api.cx.metamask.io/geolocation',
responseCode: 200,
response: 'AR',
priority: 1001,
},
];
export const TRENDING_API_MOCKS: MockEventsObject = {
GET: [
...TRENDING_GEOLOCATION_MOCKS_GET,
{
urlEndpoint:
/https:\/\/price\.api\.cx\.metamask\.io\/v3\/historical-prices.*/,
responseCode: 200,
response: [
[1704067200000, 1.0],
[1704153600000, 1.01],
],
priority: 1000,
},
{
urlEndpoint: /\/v3\/tokens\/trending.*/,
responseCode: 200,
response: TRENDING_TOKENS_RESPONSE,
priority: 1000,
},
{
urlEndpoint: /https:\/\/nft\.api\.cx\.metamask\.io\/explore\/sites.*/,
responseCode: 200,
response: {
dapps: [
{
id: '1',
name: 'Uniswap',
website: 'https://uniswap.org',
logoSrc: 'https://uniswap.org/favicon.ico',
featured: true,
categories: ['DeFi'],
networks: ['1'],
},
],
},
priority: 1000,
},
// Favicon fetch mocks — the useFavicon hook fetches site HTML to extract
// <link rel="icon"> tags. Without these mocks the requests leak to live
// servers and cause "unmocked request" test failures.
{
urlEndpoint: 'https://portfolio.metamask.io/',
responseCode: 200,
response: FAVICON_HTML,
priority: 1000,
},
{
urlEndpoint: 'https://uniswap.org/',
responseCode: 200,
response: FAVICON_HTML,
priority: 1000,
},
{
urlEndpoint: 'https://app.uniswap.org/',
responseCode: 200,
response: FAVICON_HTML,
priority: 1000,
},
{
urlEndpoint: /https:\/\/gamma-api\.polymarket\.com\/events\/pagination.*/,
responseCode: 200,
response: {
data: [
{
id: '1',
title: 'Will Bitcoin hit $100k?',
slug: 'bitcoin-100k',
icon: 'https://polymarket.com/icon.png',
description: 'Bitcoin price prediction',
startDate: '2024-01-01T00:00:00Z',
endDate: '2024-12-31T23:59:59Z',
markets: [
{
conditionId: '123',
question: 'Will Bitcoin hit $100k?',
status: 'open',
outcomes: '["Yes", "No"]',
outcomePrices: '["0.6", "0.4"]',
clobTokenIds: '["1", "2"]',
volumeNum: 1000000,
liquidity: 500000,
orderPriceMinTickSize: 0.01,
active: true,
closed: false,
sportsMarketType: 'moneyline',
groupItemTitle: 'Bitcoin',
},
],
tags: [{ label: 'Crypto', slug: 'crypto' }],
volume: 1000000,
liquidity: 500000,
},
],
},
priority: 1000,
},
{
// Event details fetched when user taps a prediction row in the trending feed.
// Returns the same Bitcoin event payload as /events/pagination so the detail
// screen renders without crashing.
urlEndpoint: /https:\/\/gamma-api\.polymarket\.com\/events\/1(\?.*)?$/,
responseCode: 200,
response: {
id: '1',
title: 'Will Bitcoin hit $100k?',
slug: 'bitcoin-100k',
icon: 'https://polymarket.com/icon.png',
description: 'Bitcoin price prediction',
startDate: '2024-01-01T00:00:00Z',
endDate: '2024-12-31T23:59:59Z',
markets: [
{
conditionId: '123',
question: 'Will Bitcoin hit $100k?',
status: 'open',
outcomes: '["Yes", "No"]',
outcomePrices: '["0.6", "0.4"]',
clobTokenIds: '["1", "2"]',
volumeNum: 1000000,
liquidity: 500000,
orderPriceMinTickSize: 0.01,
active: true,
closed: false,
sportsMarketType: 'moneyline',
groupItemTitle: 'Bitcoin',
},
],
tags: [{ label: 'Crypto', slug: 'crypto' }],
volume: 1000000,
liquidity: 500000,
},
priority: 1000,
},
{
// Prices-history (chart series) fetched on prediction detail render.
// Empty history is safe — consumer (PolymarketProvider) returns [] when
// history is not a non-empty array.
urlEndpoint: /https:\/\/clob\.polymarket\.com\/prices-history.*/,
responseCode: 200,
response: { history: [] },
priority: 1000,
},
{
urlEndpoint: /\/exchange.*/, // Hyperliquid
responseCode: 200,
response: [
{
universe: [
{ name: 'BTC', szDecimals: 3, maxLeverage: 50 },
{ name: 'ETH', szDecimals: 4, maxLeverage: 50 },
],
},
[
{
funding: '0.0001',
openInterest: '1000',
prevDayPx: '49000',
dayNtlVlm: '1000000',
markPx: '50000',
midPx: '50000',
oraclePx: '50000',
},
{
funding: '0.0001',
openInterest: '500',
prevDayPx: '2900',
dayNtlVlm: '500000',
markPx: '3000',
midPx: '3000',
oraclePx: '3000',
},
],
],
priority: 1000,
},
{
urlEndpoint: /\/tokens\/search.*Ondo/,
responseCode: 200,
response: RWA_TOKENS_SEARCH_RESPONSE,
priority: 1001,
},
{
urlEndpoint: /\/tokens\/search.*/,
responseCode: 200,
response: [], // Empty search results by default
priority: 1000,
},
{
urlEndpoint: /https:\/\/dapp-scanning\.api\.cx\.metamask\.io\/v2\/scan.*/,
responseCode: 200,
response: {
recommendedAction: 'NONE',
},
priority: 1000,
},
],
POST: [
{
urlEndpoint: /\/exchange.*/, // Hyperliquid
responseCode: 200,
response: [
{
universe: [
{ name: 'BTC', szDecimals: 3, maxLeverage: 50 },
{ name: 'ETH', szDecimals: 4, maxLeverage: 50 },
],
},
[
{
funding: '0.0001',
openInterest: '1000',
prevDayPx: '49000',
dayNtlVlm: '1000000',
markPx: '50000',
midPx: '50000',
oraclePx: '50000',
},
{
funding: '0.0001',
openInterest: '500',
prevDayPx: '2900',
dayNtlVlm: '500000',
markPx: '3000',
midPx: '3000',
oraclePx: '3000',
},
],
],
priority: 1000,
},
{
urlEndpoint: /\/info.*/, // Hyperliquid /info endpoint
responseCode: 200,
response: {
status: 'ok',
},
priority: 1000,
},
{
// CLOB prices fetched on prediction detail render. Empty object is
// safe for trending-feed which only renders the prediction row.
urlEndpoint: /https:\/\/clob\.polymarket\.com\/prices.*/,
responseCode: 200,
response: {},
priority: 1000,
},
],
};