Skip to content

Commit

Permalink
fix update balance
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4tim committed Oct 9, 2024
1 parent 5c26bf3 commit 4a37677
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/hooks/useBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ export const useBalance = (account) => {
const balance = ref(null);
const { isReady, getInstance } = useRobonomics();
let unsubscribe;
watch([account, isReady], async () => {
if (unsubscribe) {
unsubscribe();
}
if (!isReady.value) {
return;
}
const robonomics = getInstance();
unsubscribe = await robonomics.account.getBalance(account.value, (r) => {
balance.value = r.free.sub(r.frozen).toNumber();
});
});
watch(
[account, isReady],
async () => {
if (unsubscribe) {
unsubscribe();
}
if (!isReady.value || !account.value) {
return;
}
const robonomics = getInstance();
unsubscribe = await robonomics.account.getBalance(account.value, (r) => {
balance.value = r.free.sub(r.frozen).toNumber();
});
},
{ immediate: true }
);
return { balance, unsubscribe };
};

0 comments on commit 4a37677

Please sign in to comment.