Keep gold quotes live from last and apply SSE catalog list so cards refresh without a page reload.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-20 18:20:06 +03:30
co-authored by Cursor
parent c623a32bb5
commit 3b83eac099
4 changed files with 105 additions and 103 deletions
+27 -2
View File
@@ -467,13 +467,38 @@ function handleSettingsPayload(payload: unknown) {
void applySettingsFromStream(payload)
}
function coerceStreamProductList(payload: unknown): Product[] {
if (Array.isArray(payload)) {
return payload as Product[]
}
if (!payload || typeof payload !== 'object') {
return []
}
const root = payload as Record<string, unknown>
if (Array.isArray(root.data)) return root.data as Product[]
if (Array.isArray(root.products)) return root.products as Product[]
if (Array.isArray(root.items)) return root.items as Product[]
if (root.id != null && ('price' in root || 'title' in root || 'group_type' in root)) {
return [payload as Product]
}
const values = Object.values(root)
if (
values.length > 0 &&
values.every((item) => item && typeof item === 'object' && 'id' in (item as object))
) {
return values as Product[]
}
return []
}
function handleListPayload(payload: unknown) {
if (!Array.isArray(payload) || !payload.length) {
const products = coerceStreamProductList(payload)
if (!products.length) {
return
}
touchStreamActivity()
applyProductsListFromStream(payload as Product[])
applyProductsListFromStream(products)
}
function handleAppNotificationPayload(payload: unknown) {
+6 -32
View File
@@ -101,26 +101,13 @@ export function getProductBaseBuyPrice(product?: Product | null): number {
}
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
const apiPrice = Number(product.price ?? 0)
const useLast = productUsesLastPriceIfZero(product)
if (!useLast) {
const liveBuy = getTradeBuyPrice(lastPrice.value)
if (liveBuy > 0) {
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
}
return 0
}
if (apiPrice > 0) {
return apiPrice
}
const liveBuy = getTradeBuyPrice(lastPrice.value)
if (liveBuy > 0) {
return applyPriceOffsetPercent(liveBuy, product.price_offset_percent)
}
if (productUsesLastPriceIfZero(product) && Number(product.price ?? 0) > 0) {
return Number(product.price ?? 0)
}
return 0
}
@@ -195,26 +182,13 @@ export function getProductBaseSellPrice(product?: Product | null): number {
}
if (isMeltedProductUsingAppPrice(product) || isAppPriceProduct(product)) {
const apiPrice = Number(product.price ?? 0)
const useLast = productUsesLastPriceIfZero(product)
if (!useLast) {
const liveSell = getTradeSellPrice(lastPrice.value)
if (liveSell > 0) {
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
}
return 0
}
if (apiPrice > 0) {
return apiPrice
}
const liveSell = getTradeSellPrice(lastPrice.value)
if (liveSell > 0) {
return applyPriceOffsetPercent(liveSell, product.price_offset_percent)
}
if (productUsesLastPriceIfZero(product) && Number(product.price ?? 0) > 0) {
return Number(product.price ?? 0)
}
return 0
}