fix(okx): cache options balances and stop SSE from hammering exchange API
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -206,11 +206,14 @@
|
||||
function preloadAllTabs() {
|
||||
const tabs = Object.keys(TAB_PATH);
|
||||
const current = getTab();
|
||||
const heavyLast = new Set(["options", "records", "stats"]);
|
||||
const ordered = tabs.filter((t) => t !== current && !heavyLast.has(t))
|
||||
.concat(tabs.filter((t) => heavyLast.has(t) && t !== current));
|
||||
let idx = 0;
|
||||
function step() {
|
||||
if (idx >= tabs.length) return;
|
||||
const tab = tabs[idx++];
|
||||
if (tab === current || tabPanes.has(tab)) {
|
||||
if (idx >= ordered.length) return;
|
||||
const tab = ordered[idx++];
|
||||
if (tabPanes.has(tab)) {
|
||||
step();
|
||||
return;
|
||||
}
|
||||
@@ -220,11 +223,11 @@
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
setTimeout(step, 120);
|
||||
setTimeout(step, heavyLast.has(tab) ? 400 : 180);
|
||||
});
|
||||
}
|
||||
const ric = global.requestIdleCallback || function (fn) {
|
||||
setTimeout(fn, 1200);
|
||||
setTimeout(fn, 2000);
|
||||
};
|
||||
ric(step);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
let liveReconnectTimer = null;
|
||||
let localLiveVersion = -1;
|
||||
let sseConnected = false;
|
||||
let refreshTimer = null;
|
||||
|
||||
function isEmbedShell() {
|
||||
return document.body && document.body.getAttribute("data-embed-shell") === "1";
|
||||
@@ -21,7 +22,7 @@
|
||||
function refreshTabData(tab, opts) {
|
||||
const options = opts || {};
|
||||
if (typeof global.refreshAccountSnapshot === "function") {
|
||||
global.refreshAccountSnapshot();
|
||||
global.refreshAccountSnapshot(options);
|
||||
}
|
||||
if (typeof global.refreshPriceSnapshotConditional === "function") {
|
||||
global.refreshPriceSnapshotConditional();
|
||||
@@ -31,6 +32,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleRefresh() {
|
||||
if (refreshTimer) return;
|
||||
refreshTimer = setTimeout(function () {
|
||||
refreshTimer = null;
|
||||
if (document.hidden) return;
|
||||
refreshTabData(currentTab(), { silent: true });
|
||||
}, 80);
|
||||
}
|
||||
|
||||
function onLiveEvent(data) {
|
||||
const reason = data && data.reason;
|
||||
const ver = Number(data && data.live_version) || 0;
|
||||
@@ -41,7 +51,7 @@
|
||||
}
|
||||
if (ver === localLiveVersion) return;
|
||||
localLiveVersion = ver;
|
||||
refreshTabData(currentTab(), { silent: true });
|
||||
scheduleRefresh();
|
||||
}
|
||||
|
||||
function closeLiveStream() {
|
||||
|
||||
Reference in New Issue
Block a user