fix(price): apply live trading-hours settings without refresh
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -399,13 +399,40 @@ async function applyLastFromStream(last: Price) {
|
||||
applyLastPricePayload(last)
|
||||
}
|
||||
|
||||
async function applySettingsFromStream(payload: unknown) {
|
||||
const items = Array.isArray(payload)
|
||||
? payload
|
||||
: payload && typeof payload === 'object' && Array.isArray((payload as { items?: unknown }).items)
|
||||
? (payload as { items: unknown[] }).items
|
||||
: null
|
||||
if (!items?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { useSettingsStore } = await import('@/store/settingsStore')
|
||||
const { touchStoreHoursSettings } = await import('@/utils/storeHours')
|
||||
useSettingsStore().mergeSettings(items as Array<{ key?: string; value?: unknown }>)
|
||||
touchStoreHoursSettings()
|
||||
} catch (error) {
|
||||
console.warn('Settings SSE apply failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
function handleLastPayload(payload: unknown) {
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
const last = applyBoardSpecialToLastPayload(payload as Price)
|
||||
if (last.price_last == null && last.price == null && last.buy == null) {
|
||||
const raw = payload as Price & { settings_patch?: unknown }
|
||||
const last = applyBoardSpecialToLastPayload(raw)
|
||||
const hasQuote = last.price_last != null || last.price != null || last.buy != null
|
||||
const hasStatus = last.status != null || typeof last.closed === 'boolean'
|
||||
if (!hasQuote && !hasStatus) {
|
||||
if (Array.isArray(raw.settings_patch) && raw.settings_patch.length) {
|
||||
touchStreamActivity()
|
||||
void applySettingsFromStream(raw.settings_patch)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -413,6 +440,11 @@ function handleLastPayload(payload: unknown) {
|
||||
void applyLastFromStream(last)
|
||||
}
|
||||
|
||||
function handleSettingsPayload(payload: unknown) {
|
||||
touchStreamActivity()
|
||||
void applySettingsFromStream(payload)
|
||||
}
|
||||
|
||||
function handleListPayload(payload: unknown) {
|
||||
if (!Array.isArray(payload) || !payload.length) {
|
||||
return
|
||||
@@ -467,6 +499,14 @@ function bindStreamEvents(source: AuthPriceStream) {
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('settings', (event) => {
|
||||
try {
|
||||
handleSettingsPayload(JSON.parse(event.data))
|
||||
} catch (error) {
|
||||
console.warn('Price SSE settings parse failed', error)
|
||||
}
|
||||
})
|
||||
|
||||
source.addEventListener('list', (event) => {
|
||||
try {
|
||||
handleListPayload(JSON.parse(event.data))
|
||||
|
||||
Reference in New Issue
Block a user