Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { useEffect } from "react";
import { Redirect } from "expo-router";
import { View, ActivityIndicator } from "react-native";
import { useWalletStore } from "@/store/walletStore";

export default function Index() {
const { isOnboarded } = useWalletStore();
const { isOnboarded, hydrated, hydrate } = useWalletStore();

useEffect(() => {
if (!hydrated) hydrate();
}, [hydrated, hydrate]);

if (!hydrated) {
return (
<View style={{ flex: 1, backgroundColor: "#0f172a", alignItems: "center", justifyContent: "center" }}>
<ActivityIndicator size="large" color="#3b82f6" />
</View>
);
}

return isOnboarded ? (
<Redirect href="/tabs/home" />
) : (
Expand Down
56 changes: 31 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/store/__tests__/walletStore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
jest.mock("@/services/secureStorage", () => ({
getSecretKey: jest.fn(),
}));

import { getSecretKey } from "@/services/secureStorage";
import { useWalletStore } from "@/store/walletStore";

const mockedGetSecretKey = getSecretKey as jest.Mock;

beforeEach(() => {
useWalletStore.setState({ isOnboarded: false, publicKey: null, balances: {}, hydrated: false });
mockedGetSecretKey.mockReset();
});

describe("walletStore", () => {
it("restores onboarded state when a secret exists in SecureStore", async () => {
mockedGetSecretKey.mockResolvedValue("SBGELNIUVE6A5I43FCPBKX7ZIO3AO63XPWP5WEQBOE4F6NTK6RNKIG3X");
await useWalletStore.getState().hydrate();
const state = useWalletStore.getState();
expect(state.hydrated).toBe(true);
expect(state.isOnboarded).toBe(true);
expect(state.publicKey).toBeTruthy();
expect(state.publicKey).toMatch(/^G[A-Z0-9]{55}$/);
});

it("leaves isOnboarded false when no secret exists", async () => {
mockedGetSecretKey.mockResolvedValue(null);
await useWalletStore.getState().hydrate();
const state = useWalletStore.getState();
expect(state.hydrated).toBe(true);
expect(state.isOnboarded).toBe(false);
expect(state.publicKey).toBeNull();
});
});
Loading