Skip to content

Commit

Permalink
Refactor balance fetching logic in account store to use setBalance fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
Ben-Rey committed Jan 20, 2025
1 parent f773acf commit a96a11c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/ConnectMassaWallets/store/accountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export const useAccountStore = create<AccountStoreState>((set, get) => ({
setConnectedAccount: async (connectedAccount?: Provider) => {
set({ connectedAccount });
if (!connectedAccount) return;
const balance = await connectedAccount.balance(false);
set({ balance });
setBalance(connectedAccount, false, set);
},

setCurrentNetwork: (network: Network) => {
Expand All @@ -106,11 +105,19 @@ export const useAccountStore = create<AccountStoreState>((set, get) => ({
refreshBalance: async (final: boolean) => {
const { connectedAccount } = get();
if (!connectedAccount) return;
const balance = await connectedAccount.balance(final);
set({ balance });
setBalance(connectedAccount, final, set);
},
}));

async function setBalance(
provider: Provider,
final: boolean,
set: (partial: Partial<AccountStoreState>) => void,
) {
const balance = await provider.balance(final);
set({ balance });
}

function resetObservers(
get: () => AccountStoreState,
set: (partial: Partial<AccountStoreState>) => void,
Expand Down

0 comments on commit a96a11c

Please sign in to comment.