Skip to content

Commit 84d90f3

Browse files
committed
feat: add settings page to config walletshield listen address
1 parent 1d3ced1 commit 84d90f3

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { MemoryRouter, Route, Routes } from "react-router";
33
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";
6-
import { Networks } from "./pages";
76
import { Footer, Header, Message } from "./components";
7+
import { Networks, Settings } from "./pages";
88
import { useStore } from "./store";
99
import { getNetworks, getPlatformArch } from "./utils";
1010
import "./App.css";
@@ -42,6 +42,7 @@ function App() {
4242
<main className="flex-grow mt-10">
4343
<Routes>
4444
<Route path="/" element={<Networks />} />
45+
<Route path="/settings" element={<Settings />} />
4546
</Routes>
4647
</main>
4748
<Message />

src/components/Header.tsx

Lines changed: 2 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, IconGlobe } from ".";
3+
import { IconBars3, IconCog, IconGlobe } from ".";
44
import { useStore } from "../store";
55

66
export function Header() {
@@ -63,6 +63,7 @@ export function Header() {
6363
></label>
6464
<ul className="menu bg-base-200 text-base-content min-h-full w-40 p-4">
6565
<NavItem to="/" label="Networks" icon={<IconGlobe />} />
66+
<NavItem to="/settings" label="Settings" icon={<IconCog />} />
6667
</ul>
6768
</div>
6869
</div>

src/pages/Networks.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export function Networks() {
1919
const networkConnected = useStore((s) => s.networkConnected);
2020
const networks = useStore((s) => s.networks);
2121
const platformArch = useStore((s) => s.platformArch);
22+
const walletshieldListenAddress = useStore(
23+
(s) => s.walletshieldListenAddress,
24+
);
2225

2326
const setClientPid = useStore((s) => s.setClientPid);
2427
const setIsConnected = useStore((s) => s.setIsConnected);
@@ -141,7 +144,8 @@ export function Networks() {
141144
////////////////////////////////////////////////////////////////////////
142145
setMessage("info", "Starting network client...");
143146
const cmd = "walletshield";
144-
const args = ["-listen", ":7070", "-config", "client.toml"];
147+
const listen = walletshieldListenAddress ?? ":7070";
148+
const args = ["-listen", listen, "-config", "client.toml"];
145149
const command = Command.create("walletshield-listen", args, {
146150
cwd: dirNetwork,
147151
env: {

src/pages/Settings.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { useEffect, useState } from "react";
2+
import { useStore } from "../store";
3+
4+
export function Settings() {
5+
const [listenAddress, setListenAddress] = useState("");
6+
7+
const walletshieldListenAddress = useStore(
8+
(s) => s.walletshieldListenAddress,
9+
);
10+
11+
const setMessage = useStore((s) => s.setMessage);
12+
const setWalletshieldListenAddress = useStore(
13+
(s) => s.setWalletshieldListenAddress,
14+
);
15+
16+
useEffect(() => {
17+
setListenAddress(walletshieldListenAddress);
18+
}, []);
19+
20+
const handleReset = () => {
21+
setListenAddress("");
22+
setWalletshieldListenAddress("");
23+
setMessage("success", "Settings reset to default.");
24+
};
25+
26+
const handleApply = () => {
27+
setWalletshieldListenAddress(listenAddress);
28+
setMessage("success", "Settings saved.");
29+
};
30+
31+
return (
32+
<div className="flex flex-col items-center h-full">
33+
<form
34+
onSubmit={(e) => {
35+
e.preventDefault();
36+
handleApply();
37+
}}
38+
>
39+
<fieldset className="fieldset w-xs bg-base-200 border border-base-300 p-4 rounded-box">
40+
<legend className="fieldset-legend">Walletshield</legend>
41+
42+
<label className="fieldset-label">Listen Address &amp; Port</label>
43+
<input
44+
type="text"
45+
className="input validator"
46+
placeholder=":7070"
47+
value={listenAddress}
48+
onChange={(e) => setListenAddress(e.target.value)}
49+
pattern="^((\d{1,3}\.){3}\d{1,3}|[a-zA-Z0-9.-]+)?:(\d{1,5})$"
50+
required
51+
/>
52+
<p className="fieldset-label">
53+
Where the Walletshield listens for connections.
54+
</p>
55+
</fieldset>
56+
<div className="flex w-full h-full gap-4 p-4">
57+
<div className="tooltip flex-1" data-tip="Restore Defaults">
58+
<button
59+
type="button"
60+
className="btn btn-secondary w-full"
61+
onClick={handleReset}
62+
>
63+
Reset
64+
</button>
65+
</div>
66+
<div className="tooltip flex-1" data-tip="Save Settings">
67+
<button type="submit" className="btn btn-primary w-full">
68+
Apply
69+
</button>
70+
</div>
71+
</div>
72+
</form>
73+
</div>
74+
);
75+
}

src/pages/index.ts

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

src/store/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const useStore = create(
1313
networkConnected: "",
1414
networks: [] as string[],
1515
platformArch: "",
16+
walletshieldListenAddress: "",
1617
},
1718
(set) => ({
1819
setAppVersion: (appVersion: string) => set({ appVersion }),
@@ -28,6 +29,8 @@ export const useStore = create(
2829
set({ networkConnected }),
2930
setNetworks: (networks: string[]) => set({ networks }),
3031
setPlatformArch: (platformArch: string) => set({ platformArch }),
32+
setWalletshieldListenAddress: (walletshieldListenAddress: string) =>
33+
set({ walletshieldListenAddress }),
3134
}),
3235
),
3336
);

0 commit comments

Comments
 (0)