Skip to content

Commit 1e75dbb

Browse files
committed
feat: add persistent settings
1 parent 22833c7 commit 1e75dbb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/store/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { LazyStore } from "@tauri-apps/plugin-store";
12
import { create } from "zustand";
23
import { combine } from "zustand/middleware";
34

5+
const store = new LazyStore("settings.json");
6+
47
export const useStore = create(
58
combine(
69
{
@@ -29,8 +32,22 @@ export const useStore = create(
2932
set({ networkConnected }),
3033
setNetworks: (networks: string[]) => set({ networks }),
3134
setPlatformArch: (platformArch: string) => set({ platformArch }),
32-
setWalletshieldListenAddress: (walletshieldListenAddress: string) =>
33-
set({ walletshieldListenAddress }),
35+
36+
setWalletshieldListenAddress: async (
37+
walletshieldListenAddress: string,
38+
) => {
39+
set({ walletshieldListenAddress });
40+
await store.set("walletshieldListenAddress", walletshieldListenAddress);
41+
await store.save();
42+
},
43+
44+
loadPersistedSettings: async () => {
45+
const wla = await store.get<string>("walletshieldListenAddress");
46+
if (wla) set({ walletshieldListenAddress: wla });
47+
},
3448
}),
3549
),
3650
);
51+
52+
// Load persisted settings on app start
53+
useStore.getState().loadPersistedSettings();

0 commit comments

Comments
 (0)