Skip to content

Commit

Permalink
avoid frequent reinitialization of new Paseo apis
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed May 4, 2024
1 parent cdafec7 commit 02d59d5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/Header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const fetchIncogniteeBalance = async () => {
});
}
let api: ApiPromise | null = null
watch(
accountStore,
async () => {
Expand All @@ -123,14 +125,20 @@ watch(
console.log("skipping api init. no address")
return
}
if (api?.isReady ) {
console.log("skipping api init. I seems the Paseo api is already subscribed to balance changes")
return
}
console.log("trying to init api")
const wsProvider = new WsProvider('wss://rpc.ibp.network/paseo');
const api = await ApiPromise.create({provider: wsProvider});
api = await ApiPromise.create({provider: wsProvider});
api.query.system.account(accountStore.account.address, ({data: {free: currentFree}}) => {
console.log("paseo balance:" + currentFree)
accountStore.paseoBalance = Number(currentFree)
isFetchingPaseoBalance.value = false;
});
// for quicker responsiveness we dont wait until the next regular poll, but trigger the balance fetch here
fetchIncogniteeBalance().then(() => console.log("fetched incognitee balance"))
}
)
Expand Down

0 comments on commit 02d59d5

Please sign in to comment.