-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathNetworkResources.tsx
More file actions
362 lines (348 loc) · 11.6 KB
/
NetworkResources.tsx
File metadata and controls
362 lines (348 loc) · 11.6 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import React, { useState, useEffect } from "react";
import Link from "next/link";
import { BlockCopyButton } from "./ui/block-copy-button";
import {
FlaskConical,
WalletMinimal,
Waypoints,
SendToBack,
} from "lucide-react";
import WalletTable from "./WalletTable";
import EvmToSubstrateConverter from "./EvmToSubstrateConverter";
type NetworkDetail = {
property: string;
value:
| string
| {
type: string;
url: string;
text?: string;
};
};
const NETWORK_DATA = {
mainnet: [
{ property: "Interfaces and Apps", value: "" },
{
property: "Tangle DApp",
value: {
type: "link",
url: "https://app.tangle.tools",
text: "app.tangle.tools",
},
},
{
property: "PolkadotJS Apps",
value: {
type: "link",
url: "https://polkadot.js.org/apps/?rpc=wss://rpc.tangle.tools#/explorer",
text: "polkadot.js.org/apps/?rpc=wss://rpc.tangle.tools",
},
},
{ property: "Block Explorers", value: "" },
{
property: "EVM Explorer",
value: {
type: "link",
url: "https://explorer.tangle.tools",
text: "explorer.tangle.tools",
},
},
{
property: "Substrate Block Explorer",
value: {
type: "link",
url: "https://tangle.statescan.io/",
text: "tangle.statescan.io",
},
},
{ property: "Asset Details", value: "" },
{ property: "Native Asset Symbol", value: "TNT" },
{ property: "Native Asset Decimals", value: "18" },
{ property: "Developer Resources", value: "" },
{ property: "Address Prefix", value: { type: "wss", url: "tg" } },
{ property: "Network Type", value: "Substrate aka Polkadot SDK with EVM" },
{ property: "Chain ID", value: { type: "wss", url: "5845" } },
{ property: "Standard Account", value: "*25519" },
{
property: "Public RPC URL",
value: { type: "wss", url: "https://rpc.tangle.tools" },
},
{
property: "Public WSS URL",
value: { type: "wss", url: "wss://rpc.tangle.tools" },
},
{
property: "Public WSS URL by Dwellir",
value: { type: "wss", url: "wss://tangle-mainnet-rpc.n.dwellir.com" },
},
{
property: "Runtime Types",
value: {
type: "link",
url: "https://www.npmjs.com/package/@tangle-network/tangle-substrate-types",
text: "@tangle-network/tangle-substrate-types",
},
},
{
property: "Telemetry",
value: {
type: "link",
url: "https://telemetry.polkadot.io/#list/0x44f68476df71ebf765b630bf08dc1e0fedb2bf614a1aa0563b3f74f20e47b3e0",
text: "Telemetry",
},
},
{
property: "GitHub Repo",
value: {
type: "link",
url: "https://github.com/tangle-network/tangle",
text: "github.com/tangle-network/tangle",
},
},
] satisfies NetworkDetail[],
testnet: [
{ property: "Interfaces and Apps", value: "" },
{
property: "Tangle dApp",
value: {
type: "link",
url: "https://app.tangle.tools",
text: "app.tangle.tools",
},
},
{
property: "PolkadotJS Apps",
value: {
type: "link",
url: "https://polkadot.js.org/apps/?rpc=wss://testnet-rpc.tangle.tools#/explorer",
text: "polkadot.js.org/apps/?rpc=wss://testnet-rpc.tangle.tools",
},
},
{ property: "Block Explorers", value: "" },
{
property: "EVM Explorers",
value: {
type: "link",
url: "https://testnet-explorer.tangle.tools",
text: "testnet-explorer.tangle.tools",
},
},
{
property: "Substrate Explorer",
value: {
type: "link",
url: "https://polkadot.js.org/apps/?rpc=wss://testnet-rpc.tangle.tools#/explorer",
text: "polkadot.js.org/apps/?rpc=wss://testnet-rpc.tangle.tools",
},
},
{ property: "Asset Details", value: "" },
{ property: "Native Asset Symbol", value: "tTNT" },
{ property: "Native Asset Decimals", value: "18" },
{ property: "Developer Resources", value: "" },
{ property: "Address Prefix", value: "tg" },
{ property: "Network Type", value: "Substrate aka Polkadot SDK with EVM" },
{ property: "Chain ID", value: "3799" },
{ property: "Address Prefix", value: "tg" },
{ property: "Standard Account", value: "*25519" },
{
property: "Public RPC URL",
value: { type: "wss", url: "https://testnet-rpc.tangle.tools" },
},
{
property: "Public WSS URL",
value: { type: "wss", url: "wss://testnet-rpc.tangle.tools" },
},
{
property: "Runtime Types",
value: {
type: "link",
url: "https://www.npmjs.com/package/@tangle-network/tangle-substrate-types",
text: "@tangle-network/tangle-substrate-types",
},
},
{
property: "Telemetry",
value: {
type: "link",
url: "https://telemetry.polkadot.io/#list/0x3d22af97d919611e03bbcbda96f65988758865423e89b2d99547a6bb61452db3",
text: "Polkadot Telemetry",
},
},
{
property: "GitHub Repo",
value: {
type: "link",
url: "https://github.com/tangle-network/tangle",
text: "github.com/tangle-network/tangle",
},
},
] satisfies NetworkDetail[],
} as const;
const NetworkTabs = () => {
const [activeTab, setActiveTab] = useState("mainnet");
// Set initial tab based on URL hash when component mounts
useEffect(() => {
// Get hash from URL (remove the # character)
const hash = window.location.hash.substring(1);
// If hash matches one of our tabs, set it as active
if (["mainnet", "testnet", "wallets", "evmToSubstrate"].includes(hash)) {
setActiveTab(hash);
} else {
// Explicitly set to mainnet if no valid hash is present
setActiveTab("mainnet");
// If URL has no hash, we don't need to update it
if (hash && hash !== "mainnet") {
window.location.hash = "mainnet";
}
}
}, []);
const handleTabClick = (tab: string) => {
setActiveTab(tab);
// Update URL hash when tab changes
window.location.hash = tab;
};
const renderValue = (value: NetworkDetail["value"]) => {
if (typeof value === "string") {
return <span>{value}</span>;
}
switch (value.type) {
case "wss":
return (
<div className="flex items-center">
<span className="px-3 py-1 mr-2 font-mono text-sm bg-slate-200 dark:bg-black dark:text-white">
{value.url}
</span>
<BlockCopyButton name={value.url} code={value.url} />
</div>
);
case "link":
return (
<Link
href={value.url}
className="font-semibold underline underline-offset-1 dark:text-blue-200 text-linkBlue"
target="_blank"
rel="noopener noreferrer"
>
{value.text || value.url}
</Link>
);
default:
return <span>{value.toString()}</span>;
}
};
const renderTable = (data: NetworkDetail[]) => {
const sections: Record<string, typeof data> = {};
data.forEach((item) => {
if (item.value === "") {
const key = item.property;
sections[key] = [];
} else {
const lastSection = Object.keys(sections).pop();
if (lastSection) {
sections[lastSection].push(item);
}
}
});
return (
<>
{Object.entries(sections).map(([section, items]) => (
<div key={section} className="mb-8">
<h3 className="mb-2 text-xl font-semibold">{section}</h3>
<table className="w-full text-gray-800 bg-white border-collapse dark:bg-gray-800 dark:text-gray-300">
<tbody>
{items.map((item, index) => (
<tr
className={`${index % 2 === 0 ? "bg-gray-50 dark:bg-gray-700" : ""} border-b`}
key={index}
>
<td className="px-4 py-2 border border-gray-300 whitespace-nowrap bg-slate-100 dark:bg-gray-600 dark:border-gray-700">
{item.property}
</td>
<td className="px-4 py-2 truncate border border-gray-300 text-ellipsis dark:border-gray-700">
{renderValue(item.value)}
</td>
</tr>
))}
</tbody>
</table>
</div>
))}
</>
);
};
return (
<div className="mt-10">
<ul className="flex flex-wrap mb-8 text-sm font-medium text-center text-gray-500 border-b-2 dark:text-gray-400">
<li className="inline-flex items-center justify-center px-4 pt-8 text-xl border-b-2 border-transparent rounded-t-lg group">
<a
href="#"
onClick={() => handleTabClick("mainnet")}
className={`inline-block p-4 rounded-t-lg ${
activeTab === "mainnet"
? "text-blue-600 bg-gray-100 active dark:bg-gray-800 dark:text-blue-500"
: "hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300"
}`}
>
<Waypoints className="inline w-4 h-4 text-blue-600 me-2 dark:text-blue-500" />
Mainnet
</a>
</li>
<li className="inline-flex items-center justify-center px-4 pt-8 text-xl border-b-2 border-transparent rounded-t-lg group">
{" "}
<a
href="#"
onClick={() => handleTabClick("testnet")}
className={`inline-block p-4 rounded-t-lg ${
activeTab === "testnet"
? "text-blue-600 bg-gray-100 active dark:bg-gray-800 dark:text-blue-500"
: "hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300"
}`}
>
<FlaskConical className="inline w-4 h-4 text-blue-600 me-2 dark:text-blue-500" />
Testnet
</a>
</li>
<li className="inline-flex items-center justify-center px-4 pt-8 text-xl border-b-2 border-transparent rounded-t-lg group">
{" "}
<a
href="#"
onClick={() => handleTabClick("wallets")}
className={`inline-block p-4 rounded-t-lg ${
activeTab === "wallets"
? "text-blue-600 bg-gray-100 active dark:bg-gray-800 dark:text-blue-500"
: "hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300"
}`}
>
<WalletMinimal className="inline w-4 h-4 text-blue-600 me-2 dark:text-blue-500" />
Wallets
</a>
</li>
<li className="inline-flex items-center justify-center px-4 pt-8 text-xl border-b-2 border-transparent rounded-t-lg group">
{" "}
<a
href="#"
onClick={() => handleTabClick("evmToSubstrate")}
className={`inline-block p-4 rounded-t-lg ${
activeTab === "evmToSubstrate"
? "text-blue-600 bg-gray-100 active dark:bg-gray-800 dark:text-blue-500"
: "hover:text-gray-600 hover:bg-gray-50 dark:hover:bg-gray-800 dark:hover:text-gray-300"
}`}
>
<SendToBack className="inline w-4 h-4 text-blue-600 me-2 dark:text-blue-500" />
Address Converter
</a>
</li>
</ul>
<div className="w-full table-auto">
{activeTab === "wallets" ? (
<WalletTable />
) : activeTab === "evmToSubstrate" ? (
<EvmToSubstrateConverter />
) : activeTab === "mainnet" || activeTab === "testnet" ? (
renderTable(NETWORK_DATA[activeTab])
) : null}
</div>
</div>
);
};
export default NetworkTabs;