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:
@@ -31,4 +31,8 @@ export interface Price {
|
|||||||
time?: string
|
time?: string
|
||||||
main_product?: number
|
main_product?: number
|
||||||
montzar?: number
|
montzar?: number
|
||||||
|
zaarbox?: number
|
||||||
|
/** montzar | zaarbox | main_product | store = مظنه زنده، database_last = آخرین قیمت ذخیرهشده */
|
||||||
|
price_source?: string | null
|
||||||
|
last_historical?: number
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-15
@@ -266,36 +266,47 @@ export function shouldShowLastSavedPrice(): boolean {
|
|||||||
return useSettingsStore().isSettingTruthy('show_last_price')
|
return useSettingsStore().isSettingTruthy('show_last_price')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** فقط این منابع «آخرین قیمت ذخیرهشده» هستند؛ باقی price_source مظنهٔ زنده است */
|
||||||
|
const STORED_PRICE_SOURCES = ['database_last']
|
||||||
|
|
||||||
function hasShowableHomePrice(p = lastPrice.value): boolean {
|
function hasShowableHomePrice(p = lastPrice.value): boolean {
|
||||||
if (!p) return false
|
if (!p) return false
|
||||||
if (Number(p.buy) > 0 || Number(p.sell) > 0 || Number(p.price_last) > 0 || Number(p.price) > 0) {
|
return 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
|
function hasLiveQuote(p = lastPrice.value): boolean {
|
||||||
}
|
if (!hasShowableHomePrice(p)) return false
|
||||||
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 {
|
export function getPriceDisplayState(): PriceDisplayState {
|
||||||
void productTradingHoursVersion.value
|
void productTradingHoursVersion.value
|
||||||
void useSettingsStore().settingsRevision
|
void useSettingsStore().settingsRevision
|
||||||
const p = lastPrice.value
|
const p = lastPrice.value
|
||||||
const hasPrice = hasShowableHomePrice(p)
|
|
||||||
|
|
||||||
if (isOutsideGlobalStoreHours()) {
|
if (isOutsideGlobalStoreHours()) {
|
||||||
if (shouldShowHomePriceWhenClosed()) {
|
if (!shouldShowHomePriceWhenClosed()) return 'closed'
|
||||||
return hasPrice ? 'open' : 'no_quote'
|
return hasShowableHomePrice(p) ? 'open' : 'no_quote'
|
||||||
}
|
|
||||||
return 'closed'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user