From 02d59d51958725eac280e2c846b2e30ffc7c7660 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sat, 4 May 2024 10:36:15 +0200 Subject: [PATCH] avoid frequent reinitialization of new Paseo apis --- components/Header/index.vue | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/Header/index.vue b/components/Header/index.vue index f2046cc..901fe3b 100644 --- a/components/Header/index.vue +++ b/components/Header/index.vue @@ -115,6 +115,8 @@ const fetchIncogniteeBalance = async () => { }); } +let api: ApiPromise | null = null + watch( accountStore, async () => { @@ -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")) } )