-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockFetch.js
More file actions
96 lines (91 loc) · 1.91 KB
/
Copy pathmockFetch.js
File metadata and controls
96 lines (91 loc) · 1.91 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
// Mock data for trending pools
export const mockTrendingPoolsData = {
data: [
{
id: 'pool1',
type: 'pool',
attributes: {
volume_usd: { h24: '1000000' },
base_token_price_usd: 1.23,
price_change_percentage: { h24: 5.67 },
market_cap_usd: 1000000000
},
relationships: {
base_token: {
data: { id: 'token1' }
}
}
}
],
included: [
{
id: 'token1',
type: 'token',
attributes: {
symbol: 'TEST',
image_url: 'https://example.com/test.png',
address: 'tokenAddress123'
}
}
]
};
// Mock data for multi-token endpoint
export const mockMultiTokenData = {
data: [
{
id: 'token1',
type: 'token',
attributes: {
symbol: 'TEST',
image_url: 'https://example.com/test.png',
price_usd: '1.23',
market_cap_usd: '1000000000',
volume_usd: { h24: '1000000' },
address: 'tokenAddress123'
}
}
],
included: [
{
type: 'pool',
attributes: {
price_change_percentage: { h24: 5.67 }
},
relationships: {
base_token: {
data: { id: 'token1' }
}
}
}
]
};
export const mockFetch = async (url) => {
// Mock trending pools endpoint
if (url.includes('/trending_pools')) {
return {
ok: true,
json: async () => mockTrendingPoolsData
};
}
// Mock multi-token endpoint
if (url.includes('/tokens/multi/')) {
return {
ok: true,
json: async () => mockMultiTokenData
};
}
// Mock error response for unknown endpoints
return {
ok: false,
status: 404,
json: async () => ({ error: 'Not found' })
};
};
// Helper function to simulate failed requests
export const mockFailedFetch = async () => {
return {
ok: false,
status: 500,
json: async () => ({ error: 'Internal server error' })
};
};