Skip to content

Commit

Permalink
type account store (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof authored Aug 6, 2024
1 parent 0c3e3e0 commit 2e0afd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/lib/ConnectMassaWallets/store/accountStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Provider } from '@massalabs/massa-web3';
import { create } from 'zustand';

import { SUPPORTED_MASSA_WALLETS } from '../../massa-react/const';
import { Wallet } from '@massalabs/wallet-provider';

Expand Down Expand Up @@ -41,10 +43,7 @@ export interface AccountStoreState {
setConnectedAccount: (account?: Provider) => void;
}

const accountStore = (
set: (params: Partial<AccountStoreState>) => void,
get: () => AccountStoreState,
) => ({
export const useAccountStore = create<AccountStoreState>((set, get) => ({
accounts: undefined,
connectedAccount: undefined,
accountObserver: undefined,
Expand Down Expand Up @@ -157,6 +156,4 @@ const accountStore = (
setConnectedAccount: async (connectedAccount?: Provider) => {
set({ connectedAccount });
},
});

export default accountStore;
}));
11 changes: 3 additions & 8 deletions src/lib/ConnectMassaWallets/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { WalletsListener } from '@massalabs/wallet-provider';
import { create } from 'zustand';
import { useAccountStore } from './accountStore';
export { useAccountStore } from './accountStore';

import accountStore, { AccountStoreState } from './accountStore';

export const useAccountStore = create<AccountStoreState>((set, get) => ({
...accountStore(set, get),
}));

async function initAccountStore() {
export async function initAccountStore() {
new WalletsListener(4_000).subscribe((wallets) => {
useAccountStore.getState().setWallets(wallets);
});
Expand Down

0 comments on commit 2e0afd7

Please sign in to comment.