Skip to content

Commit e63b8e1

Browse files
committed
feat: add network services asset retrieval and reading
1 parent 342eb01 commit e63b8e1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/pages/Networks.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ export function Networks() {
7171

7272
async function clientStart() {
7373
const urlClientCfg = `${urlNetwork}/${networkId}/client.toml`;
74+
const urlServices = `${urlNetwork}/${networkId}/services.json`;
7475
const urlWalletshield = `${urlNetwork}/${networkId}/walletshield-${platformArch}`;
7576
const appLocalDataDirPath = await path.appLocalDataDir();
7677
const dirNetworks = await path.join(appLocalDataDirPath, "networks");
7778
const dirNetwork = await path.join(dirNetworks, networkId);
7879
const fileClientCfg = await path.join(dirNetwork, "client.toml");
80+
const fileServices = await path.join(dirNetwork, "services.json");
7981
const fileWalletshield =
8082
(await path.join(dirNetwork, "walletshield")) +
8183
(platform() === "windows" ? ".exe" : "");
@@ -95,13 +97,14 @@ export function Networks() {
9597
}
9698

9799
////////////////////////////////////////////////////////////////////////
98-
// save the network's client.toml in a network-specific directory
100+
// save the network's assets in a network-specific directory
99101
////////////////////////////////////////////////////////////////////////
100102
log.debug(`local network directory: ${dirNetwork}`);
101103
if (!(await exists(dirNetwork)))
102104
await mkdir(dirNetwork, { recursive: true });
103105
await download(urlClientCfg, fileClientCfg);
104-
setMessage("info", "Retrieved network client configuration");
106+
await download(urlServices, fileServices);
107+
setMessage("info", "Retrieved network assets");
105108

106109
////////////////////////////////////////////////////////////////////////
107110
// save the network's walletshield binary

src/utils/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { BaseDirectory, readDir } from "@tauri-apps/plugin-fs";
1+
import { BaseDirectory, readDir, readTextFile } from "@tauri-apps/plugin-fs";
2+
import { path } from "@tauri-apps/api";
23
import { arch, platform } from "@tauri-apps/plugin-os";
34

45
export const defaultWalletshieldListenAddress = ":7070";
@@ -30,3 +31,21 @@ export const getNetworks = async () => {
3031
});
3132
return entries.filter((i) => i.isDirectory).map((i) => i.name);
3233
};
34+
35+
export const readNetworkAssetFile = async (
36+
networkId: string,
37+
asset: string,
38+
) => {
39+
const filePath = await path.join("networks", networkId, asset);
40+
return await readTextFile(filePath, { baseDir: BaseDirectory.AppLocalData });
41+
};
42+
43+
export type NetworkServices = {
44+
RPCEndpoints: {
45+
chain: string;
46+
network: string;
47+
chainId: number | null;
48+
rpcPath: string;
49+
isTestnet: boolean;
50+
}[];
51+
};

0 commit comments

Comments
 (0)