Skip to content

Commit

Permalink
Refactor account store to remove fetchBalance method and directly use…
Browse files Browse the repository at this point in the history
… connectedAccount's balance method
  • Loading branch information
Ben-Rey committed Jan 20, 2025
1 parent 58fe079 commit f773acf
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/lib/ConnectMassaWallets/store/accountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface AccountStoreState {
setWallets: (wallets: Wallet[]) => void;
setConnectedAccount: (account?: Provider) => void;
setCurrentNetwork: (network: Network) => void;
fetchBalance: (provider: Provider, final: boolean) => Promise<void>;
refreshBalance: (final: boolean) => void;
}

Expand Down Expand Up @@ -95,23 +94,20 @@ export const useAccountStore = create<AccountStoreState>((set, get) => ({
setConnectedAccount: async (connectedAccount?: Provider) => {
set({ connectedAccount });
if (!connectedAccount) return;
get().fetchBalance(connectedAccount, false);
const balance = await connectedAccount.balance(false);
set({ balance });
},

setCurrentNetwork: (network: Network) => {
if (network === get().network) return;
set({ network });
},

fetchBalance: async (provider: Provider) => {
const balance = await provider.balance(false);
set({ balance });
},

refreshBalance: async (final: boolean) => {
const { connectedAccount } = get();
if (!connectedAccount) return;
get().fetchBalance(connectedAccount, final);
const balance = await connectedAccount.balance(final);
set({ balance });
},
}));

Expand Down

0 comments on commit f773acf

Please sign in to comment.