Skip to content

Commit 076e2dc

Browse files
committed
feat: Add WalletShield page with RPC endpoints
1 parent 12a0b33 commit 076e2dc

File tree

6 files changed

+145
-2
lines changed

6 files changed

+145
-2
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as app from "@tauri-apps/api/app";
44
import * as log from "@tauri-apps/plugin-log";
55
import { arch, platform } from "@tauri-apps/plugin-os";
66
import { Footer, Header, Message } from "./components";
7-
import { Networks, Settings } from "./pages";
7+
import { Networks, Settings, WalletShield } from "./pages";
88
import { useStore } from "./store";
99
import { getNetworks, getPlatformArch } from "./utils";
1010
import "./App.css";
@@ -43,6 +43,7 @@ function App() {
4343
<Routes>
4444
<Route path="/" element={<Networks />} />
4545
<Route path="/settings" element={<Settings />} />
46+
<Route path="/walletshield" element={<WalletShield />} />
4647
</Routes>
4748
<Message />
4849
</main>

src/components/Header.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRef } from "react";
22
import { Link } from "react-router";
3-
import { IconBars3, IconCog, IconGlobe } from ".";
3+
import { IconBars3, IconCog, IconGlobe, IconShieldCheck } from ".";
44
import { useStore } from "../store";
55

66
export function Header() {
@@ -64,6 +64,11 @@ export function Header() {
6464
<ul className="menu bg-base-200 text-base-content min-h-full w-40 p-4">
6565
<NavItem to="/" label="Networks" icon={<IconGlobe />} />
6666
<NavItem to="/settings" label="Settings" icon={<IconCog />} />
67+
<NavItem
68+
to="/walletshield"
69+
label="WalletShield"
70+
icon={<IconShieldCheck />}
71+
/>
6772
</ul>
6873
</div>
6974
</div>

src/components/RPCEndpoints.tsx

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { useState, useMemo, useEffect } from "react";
2+
import { useStore } from "../store";
3+
import * as log from "@tauri-apps/plugin-log";
4+
import {
5+
defaultWalletshieldListenAddress,
6+
NetworkServices,
7+
readNetworkAssetFile,
8+
} from "../utils";
9+
10+
export function RPCEndpoints() {
11+
const [includeTestnets, setIncludeTestnets] = useState(true);
12+
const [search, setSearch] = useState("");
13+
const [services, setServices] = useState<NetworkServices | null>();
14+
15+
const networkConnected = useStore((s) => s.networkConnected);
16+
const setMessage = useStore((s) => s.setMessage);
17+
18+
const walletshieldListenAddress = useStore(
19+
(s) => s.walletshieldListenAddress,
20+
);
21+
const wla = walletshieldListenAddress || defaultWalletshieldListenAddress;
22+
const BASE_URL = `http://localhost${wla}`;
23+
24+
useEffect(() => {
25+
try {
26+
(async () => {
27+
// read services file of the connected network
28+
if (networkConnected) {
29+
const f = await readNetworkAssetFile(
30+
networkConnected,
31+
"services.json",
32+
);
33+
const s = JSON.parse(f) as NetworkServices;
34+
setServices(s);
35+
}
36+
})();
37+
} catch (error: any) {
38+
log.error(`${error}`);
39+
setMessage("error", `${error}`);
40+
}
41+
}, []);
42+
43+
const filtered = useMemo(() => {
44+
if (!services) return [];
45+
const endpoints = services.RPCEndpoints;
46+
return endpoints
47+
.filter((n) => includeTestnets || !n.isTestnet)
48+
.filter((n) => {
49+
const term = search.toLowerCase();
50+
return (
51+
n.chain.toLowerCase().includes(term) ||
52+
n.network.toLowerCase().includes(term)
53+
);
54+
});
55+
}, [includeTestnets, search, services]);
56+
57+
if (!networkConnected) {
58+
return (
59+
<div className="p-4 flex justify-center">
60+
<div className="alert alert-warning shadow-lg">
61+
<span>Connect to a network to see its supported RPC endpoints.</span>
62+
</div>
63+
</div>
64+
);
65+
}
66+
67+
return (
68+
<div className="p-4">
69+
<div className="flex flex-col md:flex-row md:items-center md:justify-between mb-4 space-y-2 md:space-y-0">
70+
<div className="form-control flex flex-row gap-x-4">
71+
<label className="label">
72+
<span className="label-text">Search Networks</span>
73+
</label>
74+
<input
75+
type="text"
76+
placeholder="Search..."
77+
className="input input-bordered"
78+
value={search}
79+
onChange={(e) => setSearch(e.target.value)}
80+
/>
81+
<label className="label cursor-pointer">
82+
<span className="label-text">Include Testnets</span>
83+
<input
84+
type="checkbox"
85+
className="checkbox checkbox-primary"
86+
checked={includeTestnets}
87+
onChange={(e) => setIncludeTestnets(e.target.checked)}
88+
/>
89+
</label>
90+
</div>
91+
</div>
92+
93+
<div className="overflow-x-auto">
94+
<table className="table w-full table-zebra">
95+
<thead>
96+
<tr>
97+
<th>Chain</th>
98+
<th>Network</th>
99+
<th>ChainID</th>
100+
<th>RPC URL</th>
101+
</tr>
102+
</thead>
103+
<tbody>
104+
{filtered.map((n, idx) => (
105+
<tr key={idx}>
106+
<td>{n.chain}</td>
107+
<td>{n.network}</td>
108+
<td>{n.chainId ?? ""}</td>
109+
<td>{`${BASE_URL}${n.rpcPath}`}</td>
110+
</tr>
111+
))}
112+
</tbody>
113+
</table>
114+
</div>
115+
</div>
116+
);
117+
}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { Footer } from "./Footer";
22
export { Header } from "./Header";
33
export { Message } from "./Message";
4+
export { RPCEndpoints } from "./RPCEndpoints";
45

56
export * from "./icons.tsx";

src/pages/WalletShield.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { RPCEndpoints } from "../components";
2+
3+
export function WalletShield() {
4+
return (
5+
<div className="tabs tabs-border">
6+
<input
7+
type="radio"
8+
name="tabs_1"
9+
className="tab"
10+
aria-label="RPC Endpoints"
11+
defaultChecked
12+
/>
13+
<div className="tab-content border-base-300 bg-base-100">
14+
<RPCEndpoints />
15+
</div>
16+
</div>
17+
);
18+
}

src/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { Networks } from "./Networks";
22
export { Settings } from "./Settings";
3+
export { WalletShield } from "./WalletShield";

0 commit comments

Comments
 (0)