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:
+26
-15
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user