Skip to content

Commit 6c2c5e6

Browse files
committed
fix: eliminate chart blink on lease detail and dashboard pages
- Watch specific lease fields (address, status) instead of whole object to avoid chart teardown+rebuild on every 10s poll - Add STATUS_ORDER guard to WebSocket handler to prevent status regression - Remove duplicate fetch in UnrealizedPnlChart that caused double render
1 parent a7904c4 commit 6c2c5e6

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

src/common/stores/leases/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ export const useLeasesStore = defineStore("leases", () => {
298298
WebSocketClient.subscribeLeases(addr, (wsLease) => {
299299
// Merge with existing data (WebSocket sends partial data, no ETL)
300300
const existing = leaseDetails.value.get(wsLease.address);
301+
302+
// Don't let a stale WebSocket event regress a lease whose status
303+
// has already advanced (same guard as fetchLeaseDetails).
304+
if (existing && (STATUS_ORDER[wsLease.status] ?? 0) < (STATUS_ORDER[existing.status] ?? 0)) {
305+
return;
306+
}
307+
301308
const merged = existing ? { ...existing, ...wsLease } : (wsLease as LeaseInfo);
302309

303310
// Update in main list, or add if not yet present

src/modules/dashboard/components/UnrealizedPnlChart.vue

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,22 @@ const wallet = useWalletStore();
5151
const analyticsStore = useAnalyticsStore();
5252
const chart = ref<typeof Chart>();
5353
54-
// Watch for position/debt data changes from analytics store
54+
// Watch for position/debt data changes from analytics store.
55+
// The store's useWalletWatcher already fetches dashboard data (including
56+
// positionDebtValue) on wallet connect — no need to fetch again here.
57+
// `immediate: true` picks up data that arrived before this component mounted.
58+
let lastResponseRef: unknown = null;
5559
watch(
5660
() => analyticsStore.positionDebtValue,
5761
(response) => {
58-
if (response) {
62+
if (response && response !== lastResponseRef) {
63+
lastResponseRef = response;
5964
processPositionDebtData(response);
6065
}
6166
},
6267
{ immediate: true }
6368
);
6469
65-
// Watch for wallet changes to trigger fetch
66-
watch(
67-
() => wallet.wallet?.address,
68-
() => {
69-
if (wallet.wallet?.address) {
70-
loadData();
71-
}
72-
},
73-
{ immediate: true }
74-
);
75-
7670
function updateChart(plotContainer: HTMLElement, tooltip: Selection<HTMLDivElement, unknown, HTMLElement, unknown>) {
7771
if (!plotContainer) return;
7872
@@ -241,7 +235,10 @@ function processPositionDebtData(response: {
241235
}
242236
243237
async function loadData() {
244-
if (wallet.wallet?.address) {
238+
// The analytics store's useWalletWatcher already fetches positionDebtValue
239+
// as part of fetchDashboardData(). Only fetch here if the store hasn't
240+
// loaded it yet (e.g. component mounted before the store finished).
241+
if (wallet.wallet?.address && !analyticsStore.positionDebtValue) {
245242
await analyticsStore.fetchPositionDebtValue();
246243
}
247244
}

src/modules/leases/components/single-lease/PnlOverTimeChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function setData() {
9393
}
9494
9595
watch(
96-
() => [props.lease, chartTimeRange.value],
96+
() => [props.lease?.address, props.lease?.status, chartTimeRange.value],
9797
() => {
9898
setData();
9999
}

src/modules/leases/components/single-lease/PriceOverTimeChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const likert = {
7777
};
7878
7979
watch(
80-
() => [props.lease, props.interval],
80+
() => [props.lease?.address, props.lease?.status, props.interval],
8181
() => {
8282
setData();
8383
}

0 commit comments

Comments
 (0)