/
layout.js
33 lines (27 loc) 路 894 Bytes
/
layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useEffect } from "react";
import { create as createStore } from 'zustand';
import { Wallet } from "@/wallets/near-wallet";
import { Navigation } from "@/components/navigation";
import { NetworkId, HelloNearContract } from "@/config";
// Store to share wallet and signed account
export const useStore = createStore((set) => ({
wallet: undefined,
signedAccountId: '',
setWallet: (wallet) => set({ wallet }),
setSignedAccountId: (signedAccountId) => set({ signedAccountId })
}))
export default function RootLayout({ children }) {
const { setWallet, setSignedAccountId } = useStore();
useEffect(() => {
// create wallet instance
const wallet = new Wallet({ createAccessKeyFor: HelloNearContract, networkId: NetworkId })
wallet.startUp(setSignedAccountId);
setWallet(wallet);
}, [])
return (
<>
<Navigation />
{children}
</>
);
}