Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Feb 2, 2025
2 parents 13de36d + a1d535b commit 178643f
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 33 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "yarn lint:eslint && yarn lint:prettier",
"lint:eslint": "eslint .",
"lint:prettier": "prettier . --check",
"lintfix": "eslint . --fix && prettier --write --list-different ."
"lintfix": "prettier --write --list-different ."
},
"devDependencies": {
"@egoist/tailwindcss-icons": "^1.0.0",
Expand Down Expand Up @@ -44,8 +44,8 @@
"vue-router": "^4.3.2"
},
"dependencies": {
"@encointer/util": "^0.18.0",
"@encointer/worker-api": "^0.18.0",
"@encointer/util": "^0.18.2",
"@encointer/worker-api": "^0.18.2",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@headlessui/tailwindcss": "^0.2.1",
"@headlessui/vue": "^1.7.22",
Expand Down
137 changes: 134 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ const fetchIncogniteeBalance = async () => {
return;
}
if (!incogniteeStore.api?.isConnected) {
await incogniteeStore.api?.reconnect();
}
isUpdatingIncogniteeBalance.value = true;
const injector = accountStore.hasInjector ? accountStore.injector : null;
Expand Down Expand Up @@ -302,6 +306,9 @@ const storeSessionProxies = (proxies) => {
const fetchNetworkStatus = async () => {
const promises = [];
if (shieldingTargetApi.value?.isReady) {
// If the browser tab was open, but inactive for a long time,
// it could be that we need to reconnect (ready is a bad indicator here).
await reconnectShieldingTargetIfNecessary();
const p = shieldingTargetApi.value.rpc.chain
.getFinalizedHead()
.then((head) => {
Expand All @@ -314,6 +321,9 @@ const fetchNetworkStatus = async () => {
promises.push(p);
}
if (!incogniteeStore.apiReady) return;
if (!incogniteeStore.api?.isConnected) {
await incogniteeStore.api?.reconnect();
}
console.debug("fetch network status info");
const getter = incogniteeStore.api.parentchainsInfoGetter(
incogniteeShard.value,
Expand Down Expand Up @@ -364,6 +374,10 @@ const updateNotes = async () => {
};
const fetchNoteBucketsInfo = async () => {
if (!incogniteeStore.apiReady) return;
if (!incogniteeStore.api?.isConnected) {
await incogniteeStore.api?.reconnect();
}
console.log("fetch note buckets info");
const getter = incogniteeStore.api.noteBucketsInfoGetter(
incogniteeStore.shard,
Expand Down Expand Up @@ -425,6 +439,11 @@ const fetchIncogniteeNotes = async (
);
return;
}
if (!incogniteeStore.api?.isConnected) {
await incogniteeStore.api?.reconnect();
}
const bucketIndex = maybeBucketIndex ? maybeBucketIndex : 0;
const mapKey = `notesFor:${accountStore.account}:${bucketIndex}`;
const sessionProxy = accountStore.sessionProxyForRole(
Expand Down Expand Up @@ -676,8 +695,22 @@ const fetchIncogniteeNotes = async (
}
};
const pollCounter = useInterval(2000);
watch(pollCounter, async () => {
async function fetchWorkerData() {
if (!incogniteeStore.api?.isReady) {
return;
}
if (!incogniteeStore.api?.isConnected) {
await incogniteeStore.api?.reconnect();
}
console.debug(
`[IntegriteeWorker]: connections stats: ${JSON.stringify(incogniteeStore?.api?.wsStats)}`,
);
console.debug(
`[IntegriteeWorker]: endpoint stats: ${JSON.stringify(incogniteeStore?.api?.endpointStats)}`,
);
await fetchIncogniteeBalance();
await fetchNetworkStatus();
// autofetch history slowly
Expand All @@ -694,13 +727,105 @@ watch(pollCounter, async () => {
} catch (error) {
console.warn("error auto-fetching older incognitee note buckets: " + error);
}
});
}
const pollingInterval = 2000; // 2 seconds
let pollingTimeout: any = null;
const isPolling = ref(true);
// After 20 seconds in background, we will stop some services,
// which can be resumed upon coming into foreground again.
const inactivityTimeoutPeriod = 20000; // 20 seconds
let disconnectWsTimeout: any = null;
async function pollWorker() {
if (!incogniteeStore.api?.isReady) {
// Schedule the next polling.
pollingTimeout = setTimeout(pollWorker, pollingInterval);
return;
}
await fetchWorkerData();
if (isPolling.value) {
// Schedule the next polling.
pollingTimeout = setTimeout(pollWorker, pollingInterval);
}
}
function handleVisibilityChange() {
if (document.visibilityState === "visible") {
console.debug("[Polling] Tab became visible");
onVisible();
} else {
console.debug("[Polling] Tab became invisible");
onBackground();
}
}
async function onVisible() {
isPolling.value = true;
clearInterval(disconnectWsTimeout);
if (!incogniteeStore.api?.isConnected) {
console.debug("[onVisible] Reconnecting to the worker api");
await incogniteeStore.api?.reconnect();
}
// avoid spamming polls due to visibility changes
clearInterval(pollingTimeout);
await pollWorker();
}
async function onBackground() {
isPolling.value = false;
clearTimeout(pollingTimeout);
// otherwise we will see errors in the log that
// the websocket unexpectedly closed after a while.
// prevent scheduling multiple closes
clearInterval(disconnectWsTimeout);
disconnectWsTimeout = setTimeout(closeWs, inactivityTimeoutPeriod);
}
async function closeWs() {
console.debug("closing websocket");
if (incogniteeStore.api?.isConnected) {
// not sure why, but sometimes the websocket is already
// closed here.
await incogniteeStore.api?.closeWs();
console.debug("closed websocket");
} else {
console.debug("websocket was closed already");
}
}
watch(
() => accountStore.getAddress,
async () => await subscribeWhatsReady(),
);
async function reconnectShieldingTargetIfNecessary() {
if (!shieldingTargetApi.value?.isConnected) {
const wsProvider = new WsProvider(chainConfigs[shieldingTarget.value].api);
console.log(
"re-initializing api at " + chainConfigs[shieldingTarget.value].api,
);
shieldingTargetApi.value = await ApiPromise.create({
provider: wsProvider,
});
await shieldingTargetApi.value.isReady;
// await is quick as we only subscribe
await shieldingTargetApi.value.rpc.chain.subscribeNewHeads((lastHeader) => {
systemHealth.observeShieldingTargetBlockNumber(
lastHeader.number.toNumber(),
);
});
}
}
const subscribeWhatsReady = async () => {
//todo! only reinitialize if account changes
if (shieldingTargetApi.value?.isReady) {
Expand Down Expand Up @@ -862,6 +987,7 @@ const switchToFaq = () => {
onMounted(async () => {
checkIfMobile();
window.addEventListener("resize", checkIfMobile);
document.addEventListener("visibilitychange", handleVisibilityChange);
await loadEnv(props.envFile);
await incogniteeStore.initializeApi(
chainConfigs[incogniteeSidechain.value].api,
Expand Down Expand Up @@ -914,11 +1040,16 @@ onMounted(async () => {
// if we move back from TEERdays, the account may already be selected and the subscription watcher won't trigger
await subscribeWhatsReady();
}
// start polling the worker
await pollWorker();
});
onUnmounted(() => {
eventBus.off("addressClicked", openChooseWalletOverlay);
window.removeEventListener("resize", checkIfMobile);
clearTimeout(pollingTimeout);
document.removeEventListener("visibilitychange", handleVisibilityChange);
});
const dropSubscriptions = () => {
Expand Down
4 changes: 1 addition & 3 deletions pages/referral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,13 @@
</a>
</div>
</div>
<div class="footer__column">
</div>
<div class="footer__column"></div>
</div>
</div>
<div class="footer__bottom">
<span class="paragraph_medium"
>©{{ new Date().getFullYear() }} Integritee, Inc.</span
>

</div>
</div>
</footer>
Expand Down
3 changes: 1 addition & 2 deletions pages/referraltc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@
</a>
</div>
</div>
<div class="footer__column">
</div>
<div class="footer__column"></div>
</div>
</div>
<div class="footer__bottom">
Expand Down
44 changes: 22 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -497,50 +497,50 @@ __metadata:
languageName: node
linkType: hard

"@encointer/node-api@npm:^0.18.0":
version: 0.18.0
resolution: "@encointer/node-api@npm:0.18.0"
"@encointer/node-api@npm:^0.18.2":
version: 0.18.2
resolution: "@encointer/node-api@npm:0.18.2"
dependencies:
"@encointer/types": "npm:^0.18.0"
"@encointer/types": "npm:^0.18.2"
"@polkadot/api": "npm:^11.2.1"
tslib: "npm:^2.6.2"
checksum: 10c0/e9cbf01b15a622b5d4a5c1b30e0257ce3d5aaeb5decf9aee05f6cc9c178c36b3efe1bf454422becf0150f86eedbc4f12948387e01e3e6e0a7489d8e3eb9c50e9
checksum: 10c0/5e673535cf156ac5d2571adc6da4f7973d62a481a78995fbc09690cd9d95dac7206bb59de3dfbbea33b2f9ea8115b9a651cb1fd20dd2a624719ec1ffcbf5f23d
languageName: node
linkType: hard

"@encointer/types@npm:^0.18.0":
version: 0.18.0
resolution: "@encointer/types@npm:0.18.0"
"@encointer/types@npm:^0.18.2":
version: 0.18.2
resolution: "@encointer/types@npm:0.18.2"
dependencies:
"@polkadot/api": "npm:^11.2.1"
"@polkadot/types": "npm:^11.2.1"
"@polkadot/types-codec": "npm:^11.2.1"
"@polkadot/util": "npm:^12.6.2"
checksum: 10c0/6001f1c4f76e55013e685c3b0ecb3da5cede271450e115974fbe2df68ccd868f9b2b67947e3bb38a8072e4666020c9cb394c9887f15be28fae6ec1b9b44add90
checksum: 10c0/958d95ad350ae40dab69119aef335970f73d81e790a42963997da8dcd808a3fd0a7922e5fe9af34f6bc19246008be2ea3f8ab9ff773b6ff516731d063fb2e633
languageName: node
linkType: hard

"@encointer/util@npm:^0.18.0":
version: 0.18.0
resolution: "@encointer/util@npm:0.18.0"
"@encointer/util@npm:^0.18.2":
version: 0.18.2
resolution: "@encointer/util@npm:0.18.2"
dependencies:
"@babel/runtime": "npm:^7.18.9"
"@polkadot/util": "npm:^12.6.2"
"@polkadot/util-crypto": "npm:^12.6.2"
"@types/bn.js": "npm:^5.1.5"
assert: "npm:^2.0.0"
bn.js: "npm:^5.2.1"
checksum: 10c0/ad51ce72bb6acca6313f18fd02b33fc6365806b779c8acc653dc784ee9d6661a90d332aac0188e7afc0c0076daaf36ca7fde4ba9b917bfa09c8cdf376925a1cc
checksum: 10c0/432de262dc3f80955f2b29f55ba546e19e1aa6306b23e8d11710436c5e774e4b758c8886fc1f52ea5ab45edd4f4098d625a3b76a792482e271d3be043373789c
languageName: node
linkType: hard

"@encointer/worker-api@npm:^0.18.0":
version: 0.18.0
resolution: "@encointer/worker-api@npm:0.18.0"
"@encointer/worker-api@npm:^0.18.2":
version: 0.18.2
resolution: "@encointer/worker-api@npm:0.18.2"
dependencies:
"@encointer/node-api": "npm:^0.18.0"
"@encointer/types": "npm:^0.18.0"
"@encointer/util": "npm:^0.18.0"
"@encointer/node-api": "npm:^0.18.2"
"@encointer/types": "npm:^0.18.2"
"@encointer/util": "npm:^0.18.2"
"@peculiar/webcrypto": "npm:^1.4.6"
"@polkadot/api": "npm:^11.2.1"
"@polkadot/keyring": "npm:^12.6.2"
Expand All @@ -555,7 +555,7 @@ __metadata:
tslib: "npm:^2.6.2"
peerDependencies:
"@polkadot/x-randomvalues": ^12.3.2
checksum: 10c0/0c0332ff48f3e11b47817d6eff9e8b1bf75ec1c014e350f65733390a72fe92da6c750a1d43a3ddc2c6f87bc2a7f2403feaf0dd3fcd70a72a6ef44c5f41a3c1ee
checksum: 10c0/ee8d0435a5a6d7f96184ae3e7cdcefd508fa4ca72baf03b35326d2897144dac4214bb12dff2d7634ad2e6db2adf3316bfa9b75ba94846db0b45894e0f2d486e1
languageName: node
linkType: hard

Expand Down Expand Up @@ -9655,8 +9655,8 @@ __metadata:
resolution: "nuxt-app@workspace:."
dependencies:
"@egoist/tailwindcss-icons": "npm:^1.0.0"
"@encointer/util": "npm:^0.18.0"
"@encointer/worker-api": "npm:^0.18.0"
"@encointer/util": "npm:^0.18.2"
"@encointer/worker-api": "npm:^0.18.2"
"@esbuild-plugins/node-globals-polyfill": "npm:^0.2.3"
"@headlessui/tailwindcss": "npm:^0.2.1"
"@headlessui/vue": "npm:^1.7.22"
Expand Down

0 comments on commit 178643f

Please sign in to comment.