Force-refresh header balances after transfers and balance SSE events.
Invalidate balance caches on mutation, push SSE balance tick, and bypass 60s cache when refreshing funds. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,12 +32,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
function scheduleRefresh() {
|
||||
function scheduleRefresh(opts) {
|
||||
if (refreshTimer) return;
|
||||
const options = opts || {};
|
||||
refreshTimer = setTimeout(function () {
|
||||
refreshTimer = null;
|
||||
if (document.hidden) return;
|
||||
refreshTabData(currentTab(), { silent: true });
|
||||
refreshTabData(currentTab(), { silent: true, force: !!options.force });
|
||||
}, 80);
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@
|
||||
}
|
||||
if (ver === localLiveVersion) return;
|
||||
localLiveVersion = ver;
|
||||
scheduleRefresh();
|
||||
scheduleRefresh({ force: reason === "balance" });
|
||||
}
|
||||
|
||||
function closeLiveStream() {
|
||||
|
||||
@@ -9,6 +9,14 @@
|
||||
return r.json();
|
||||
}
|
||||
|
||||
function refreshFundsAfterMutation() {
|
||||
if (typeof refreshAccountSnapshot !== "function") return;
|
||||
refreshAccountSnapshot({ force: true });
|
||||
setTimeout(function () {
|
||||
refreshAccountSnapshot({ force: true, silent: true });
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
function setMsg(id, text, isErr) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) return;
|
||||
@@ -50,7 +58,7 @@
|
||||
}),
|
||||
});
|
||||
setMsg("opt-set-swap-msg", d.ok ? "兑换单已提交" : (d.msg || "失败"), !d.ok);
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshAccountSnapshot();
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshFundsAfterMutation();
|
||||
}
|
||||
|
||||
const swapBtn = document.getElementById("opt-set-swap-btn");
|
||||
@@ -96,7 +104,7 @@
|
||||
}),
|
||||
});
|
||||
setMsg("opt-set-int-msg", d.ok ? "划转成功" : (d.msg || "失败"), !d.ok);
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshAccountSnapshot();
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshFundsAfterMutation();
|
||||
}
|
||||
|
||||
const intBtn = document.getElementById("opt-set-int-btn");
|
||||
@@ -143,7 +151,7 @@
|
||||
}),
|
||||
});
|
||||
setMsg("opt-set-cross-msg", d.ok ? "划转成功" : (d.msg || "失败"), !d.ok);
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshAccountSnapshot();
|
||||
if (d.ok && typeof refreshAccountSnapshot === "function") refreshFundsAfterMutation();
|
||||
}
|
||||
|
||||
const crossBtn = document.getElementById("opt-set-cross-btn");
|
||||
|
||||
Reference in New Issue
Block a user