Skip to content

Commit aeb5c4e

Browse files
committed
refactor: extract utility functions to module
1 parent d753ea5 commit aeb5c4e

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/App.tsx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,12 @@ import { arch, platform } from "@tauri-apps/plugin-os";
66
import { download } from "@tauri-apps/plugin-upload";
77
import { fetch } from "@tauri-apps/plugin-http";
88
import { Child, Command } from "@tauri-apps/plugin-shell";
9-
import { mkdir, exists, readDir, BaseDirectory } from "@tauri-apps/plugin-fs";
9+
import { mkdir, exists } from "@tauri-apps/plugin-fs";
1010
import { Footer } from "./components";
1111
import { useStore } from "./store";
12+
import { getNetworks, getPlatformArch, urlNetwork } from "./utils";
1213
import "./App.css";
1314

14-
const urlNetwork = "https://test.net.zknet.io";
15-
16-
// Map the os platform and architecture to a supported ZKN format
17-
const getPlatformArch = (): string => {
18-
const platArch = `${platform()}-${arch()}`;
19-
switch (platArch) {
20-
case "linux-aarch64":
21-
return "linux-arm64";
22-
case "linux-x86_64":
23-
return "linux-x64";
24-
case "macos-aarch64":
25-
case "macos-x86_64":
26-
return "macos";
27-
case "windows-x86_64":
28-
return "windows-x64";
29-
default:
30-
throw new Error(`Unsupported Operating System: ${platArch}`);
31-
}
32-
};
33-
34-
// Get networks with previously downloaded assets
35-
const getNetworks = async () => {
36-
const entries = await readDir("networks", {
37-
baseDir: BaseDirectory.AppLocalData,
38-
});
39-
return entries.filter((i) => i.isDirectory).map((i) => i.name);
40-
};
41-
4215
function App() {
4316
const [msg, setMsg] = useState("");
4417
const [msgType, setMsgType] = useState(""); // error, info, success

src/utils/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BaseDirectory, readDir } from "@tauri-apps/plugin-fs";
2+
import { arch, platform } from "@tauri-apps/plugin-os";
3+
4+
export const urlNetwork = "https://test.net.zknet.io";
5+
6+
// Map the os platform and architecture to a supported ZKN format
7+
export const getPlatformArch = (): string => {
8+
const platArch = `${platform()}-${arch()}`;
9+
switch (platArch) {
10+
case "linux-aarch64":
11+
return "linux-arm64";
12+
case "linux-x86_64":
13+
return "linux-x64";
14+
case "macos-aarch64":
15+
case "macos-x86_64":
16+
return "macos";
17+
case "windows-x86_64":
18+
return "windows-x64";
19+
default:
20+
throw new Error(`Unsupported Operating System: ${platArch}`);
21+
}
22+
};
23+
24+
// Get networks with previously downloaded assets
25+
export const getNetworks = async () => {
26+
const entries = await readDir("networks", {
27+
baseDir: BaseDirectory.AppLocalData,
28+
});
29+
return entries.filter((i) => i.isDirectory).map((i) => i.name);
30+
};

0 commit comments

Comments
 (0)