fix(price): hide stored fallback when last-price display is off

Treat only live quote sources as open; a leftover database price should not stay on screen after the admin switch is turned off.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 03:01:10 +03:30
co-authored by Cursor
parent ea71591557
commit 2238a34c53
2 changed files with 30 additions and 15 deletions
+4
View File
@@ -31,4 +31,8 @@ export interface Price {
time?: string
main_product?: number
montzar?: number
zaarbox?: number
/** montzar | zaarbox | main_product | store = مظنه زنده، database_last = آخرین قیمت ذخیره‌شده */
price_source?: string | null
last_historical?: number
}
+26 -15
View File
@@ -266,36 +266,47 @@ export function shouldShowLastSavedPrice(): boolean {
return useSettingsStore().isSettingTruthy('show_last_price')
}
/** فقط این منابع «آخرین قیمت ذخیره‌شده» هستند؛ باقی price_source مظنهٔ زنده است */
const STORED_PRICE_SOURCES = ['database_last']
function hasShowableHomePrice(p = lastPrice.value): boolean {
if (!p) return false
if (Number(p.buy) > 0 || Number(p.sell) > 0 || Number(p.price_last) > 0 || Number(p.price) > 0) {
return true
}
if (shouldShowLastSavedPrice() && Number((p as { last_historical?: number }).last_historical ?? 0) > 0) {
return true
}
return false
return Number(p.buy) > 0 || Number(p.sell) > 0 || Number(p.price_last) > 0 || Number(p.price) > 0
}
/** قیمت از مرجع زنده آمده یا از آخرین ردیف ذخیره‌شده */
function hasLiveQuote(p = lastPrice.value): boolean {
if (!hasShowableHomePrice(p)) return false
const source = String((p as { price_source?: string })?.price_source ?? '').trim().toLowerCase()
if (source) return !STORED_PRICE_SOURCES.includes(source)
return (
Number(p?.montzar ?? 0) > 0
|| Number((p as { zaarbox?: number })?.zaarbox ?? 0) > 0
|| Number(p?.main_product ?? 0) > 0
)
}
/**
* وضعیت نمایش قیمت در صفحه اصلی — همان منطق بک‌اند:
* close_price خاموش / داخل ساعت → قیمت هست open، وگرنه no_quote
* close_price روشن و خارج ساعت → show_home_price_when_closed روشن: آخرین قیمت؛ خاموش: closed
* خارج از ساعت کاری (close_price روشن) → show_home_price_when_closed روشن: آخرین قیمت؛ خاموش: closed
* داخل ساعت کاری → مظنه زنده: open ؛ وگرنه فقط با show_last_price آخرین قیمت؛ وگرنه no_quote
*/
export function getPriceDisplayState(): PriceDisplayState {
void productTradingHoursVersion.value
void useSettingsStore().settingsRevision
const p = lastPrice.value
const hasPrice = hasShowableHomePrice(p)
if (isOutsideGlobalStoreHours()) {
if (shouldShowHomePriceWhenClosed()) {
return hasPrice ? 'open' : 'no_quote'
}
return 'closed'
if (!shouldShowHomePriceWhenClosed()) return 'closed'
return hasShowableHomePrice(p) ? 'open' : 'no_quote'
}
return hasPrice ? 'open' : 'no_quote'
if (hasLiveQuote(p)) return 'open'
if (shouldShowLastSavedPrice() && hasShowableHomePrice(p)) return 'open'
return 'no_quote'
}
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {