-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_network_detection.html
More file actions
268 lines (237 loc) · 9.45 KB
/
debug_network_detection.html
File metadata and controls
268 lines (237 loc) · 9.45 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网络识别测试</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
border-radius: 12px;
padding: 24px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.test-item {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 16px;
margin-bottom: 16px;
background: #fafafa;
}
.test-item.success {
border-color: #4caf50;
background: #f1f8e9;
}
.test-item.error {
border-color: #f44336;
background: #ffebee;
}
.network-tag {
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 12px;
font-weight: 500;
margin-left: 8px;
}
.network-eth { background: #e3f2fd; color: #1976d2; }
.network-bsc { background: #fff3e0; color: #f57c00; }
.network-sol { background: #f3e5f5; color: #7b1fa2; }
.network-crypto { background: #f5f5f5; color: #616161; }
button {
background: #2196f3;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
margin-right: 12px;
margin-bottom: 12px;
}
button:hover {
background: #1976d2;
}
.loading {
color: #666;
font-style: italic;
}
pre {
background: #f5f5f5;
padding: 12px;
border-radius: 4px;
overflow-x: auto;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<h1>🔍 网络识别系统测试</h1>
<p>测试智能网络识别功能,验证各种代币的网络检测是否正确。</p>
<button onclick="testSpecificTokens()">测试特定代币</button>
<button onclick="testPlatformDetection()">测试平台检测</button>
<button onclick="clearResults()">清空结果</button>
</div>
<div class="container">
<h2>📊 测试结果</h2>
<div id="results"></div>
</div>
<script>
const API_KEY = 'CG-your-api-key-here'; // 请替换为实际的API密钥
const BASE_URL = 'https://api.coingecko.com/api/v3';
// 测试特定代币
async function testSpecificTokens() {
const testTokens = [
'world-liberty-financial-wlfi',
'pump-fun-token',
'v2ex',
'bitcoin',
'ethereum',
'binancecoin',
'solana',
'chainlink',
'uniswap'
];
addResult('开始测试特定代币...', 'info');
for (const tokenId of testTokens) {
try {
addResult(`正在测试: ${tokenId}`, 'loading');
// 获取代币详细信息
const details = await fetchCoinDetails(tokenId);
if (details) {
const networkInfo = detectNetwork(details);
addResult(
`✅ ${tokenId}: ${details.name} (${details.symbol.toUpperCase()})`,
'success',
networkInfo,
details.platforms
);
} else {
addResult(`❌ ${tokenId}: 未找到代币信息`, 'error');
}
} catch (error) {
addResult(`❌ ${tokenId}: ${error.message}`, 'error');
}
// 避免API限制
await sleep(200);
}
}
// 获取代币详细信息
async function fetchCoinDetails(coinId) {
const url = `${BASE_URL}/coins/${coinId}?localization=false&tickers=false&market_data=false&community_data=false&developer_data=false&sparkline=false&x_cg_demo_api_key=${API_KEY}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return await response.json();
}
// 网络检测逻辑(复制自组件)
function detectNetwork(crypto) {
// 1. 优先检查 CoinGecko 平台信息
if (crypto.platforms && typeof crypto.platforms === 'object') {
const platforms = crypto.platforms;
if (platforms['ethereum'] || platforms['ethereum-classic']) {
return { network: 'ETH', networkName: 'Ethereum', class: 'network-eth' };
}
if (platforms['binance-smart-chain'] || platforms['bsc']) {
return { network: 'BSC', networkName: 'BNB Chain', class: 'network-bsc' };
}
if (platforms['solana']) {
return { network: 'SOL', networkName: 'Solana', class: 'network-sol' };
}
if (platforms['polygon-pos']) {
return { network: 'MATIC', networkName: 'Polygon', class: 'network-sol' };
}
if (platforms['avalanche']) {
return { network: 'AVAX', networkName: 'Avalanche', class: 'network-eth' };
}
}
// 2. 原生区块链代币
const nativeTokens = {
'bitcoin': { network: 'BTC', networkName: 'Bitcoin', class: 'network-crypto' },
'ethereum': { network: 'ETH', networkName: 'Ethereum', class: 'network-eth' },
'binancecoin': { network: 'BNB', networkName: 'BNB Chain', class: 'network-bsc' },
'solana': { network: 'SOL', networkName: 'Solana', class: 'network-sol' },
};
if (nativeTokens[crypto.id]) {
return nativeTokens[crypto.id];
}
// 3. 默认
return { network: 'CRYPTO', networkName: 'Cryptocurrency', class: 'network-crypto' };
}
// 添加测试结果
function addResult(message, type, networkInfo = null, platforms = null) {
const results = document.getElementById('results');
const item = document.createElement('div');
item.className = `test-item ${type}`;
let content = `<div>${message}`;
if (networkInfo) {
content += `<span class="network-tag ${networkInfo.class}">${networkInfo.network}</span>`;
}
content += '</div>';
if (platforms) {
content += '<pre>' + JSON.stringify(platforms, null, 2) + '</pre>';
}
item.innerHTML = content;
results.appendChild(item);
// 滚动到底部
item.scrollIntoView({ behavior: 'smooth' });
}
// 测试平台检测
async function testPlatformDetection() {
addResult('开始测试平台检测功能...', 'info');
// 测试一些已知的多链代币
const multiChainTokens = [
'tether', // USDT - 多链
'usd-coin', // USDC - 多链
'chainlink', // LINK - ETH
'uniswap', // UNI - ETH
'pancakeswap-token', // CAKE - BSC
];
for (const tokenId of multiChainTokens) {
try {
const details = await fetchCoinDetails(tokenId);
if (details && details.platforms) {
const platformCount = Object.keys(details.platforms).length;
const networkInfo = detectNetwork(details);
addResult(
`📊 ${tokenId}: 支持 ${platformCount} 个平台`,
platformCount > 1 ? 'success' : 'info',
networkInfo,
details.platforms
);
}
} catch (error) {
addResult(`❌ ${tokenId}: ${error.message}`, 'error');
}
await sleep(200);
}
}
// 清空结果
function clearResults() {
document.getElementById('results').innerHTML = '';
}
// 延迟函数
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// 页面加载完成后的提示
window.onload = function() {
if (API_KEY === 'CG-your-api-key-here') {
addResult('⚠️ 请先在代码中设置正确的 CoinGecko API 密钥', 'error');
} else {
addResult('✅ 网络识别测试工具已就绪', 'success');
}
};
</script>
</body>
</html>