Unify store-closed messaging when the market is closed or has no quote.

Treat missing quotes as closed across home and products, show only the admin closed_message as hint, and block trading with consistent notices.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-11 12:42:56 +02:00
co-authored by Cursor
parent 1000df5931
commit 0109f3a744
12 changed files with 99 additions and 82 deletions
+56 -33
View File
@@ -128,39 +128,69 @@ export function isStoreClosedBySchedule(now = new Date()): boolean {
return false
}
return isOutsideStoreTradingHours(now, start, end)
}
export function isOutsideStoreTradingHours(
now = new Date(),
start?: string,
end?: string,
): boolean {
const hours = start != null && end != null
? { start, end }
: getEffectiveTradingHours()
const currentSeconds = now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()
const openSeconds = parseTimeToSeconds(start)
const closeSeconds = parseTimeToSeconds(end)
const openSeconds = parseTimeToSeconds(hours.start)
const closeSeconds = parseTimeToSeconds(hours.end)
return currentSeconds < openSeconds || currentSeconds > closeSeconds
}
export function hasLivePriceQuote(): boolean {
const p = lastPrice.value
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0
}
export function isStoreClosed(): boolean {
void productTradingHoursVersion.value
const { closePriceEnabled } = getStoreTradingHours()
if (closePriceEnabled) {
if (lastPrice.value?.closed === true) {
return true
}
return isStoreClosedBySchedule()
if (lastPrice.value?.closed === true) {
return true
}
// وقتی close_price خاموش است، صفر بودن قیمت مرجع به معنی بسته بودن فروشگاه نیست.
return isStoreClosedBySchedule()
}
export function getStoreClosedMessage(): string {
const { start, end } = getEffectiveTradingHours()
const open = formatTradingTimeDisplay(start)
const close = formatTradingTimeDisplay(end)
export const STORE_CLOSED_TITLE = 'فروشگاه بسته است'
if (!open || !close) {
return 'فروشگاه در حال حاضر بسته است.'
export function stripHtmlMessage(message: string): string {
return message.replace(/<[^>]*>/g, '').trim()
}
export function getStoreClosedHint(customMessage?: unknown): string {
const custom = typeof customMessage === 'string' ? customMessage.trim() : ''
if (custom) {
return stripHtmlMessage(custom)
}
return ''
}
return `فروشگاه در حال حاضر بسته است. ساعت کاری از ${open} تا ${close} می‌باشد.`
export function getStoreClosedMessage(): string {
return ''
}
/** برای toast/اعلان: پیام ادمین یا عنوان پیش‌فرض */
export function resolveStoreClosedNotice(customMessage?: unknown): string {
return getStoreClosedHint(customMessage) || STORE_CLOSED_TITLE
}
export function isMarketClosedForDisplay(): boolean {
return getPriceDisplayState() === 'closed'
}
export function shouldBlockStoreTrading(): boolean {
return isMarketClosedForDisplay()
}
export type PriceDisplayState = 'open' | 'closed' | 'no_quote'
@@ -168,34 +198,27 @@ export type PriceDisplayState = 'open' | 'closed' | 'no_quote'
export const NO_QUOTE_MESSAGE = 'مظنه در دسترس نیست'
/**
* وضعیت نمایش قیمت در صفحه اصلی:
* - closed → فروشگاه بسته است (خارج از ساعت کاری close_price یا بازه محصول)
* - no_quote → مظنه در دسترس نیست (قیمت زنده نداریم و show_last_price خاموش است)
* - open → نمایش عادی قیمت
*
* اولویت با status ارسالی از سرور است؛ اگر نبود به منطق سمت کلاینت برمی‌گردیم.
* وضعیت نمایش قیمت:
* - closed → فروشگاه بسته است (ساعت کاری، سیگنال سرور، یا نبود مظنه)
* - open → نمایش عادی قیمت
*/
export function getPriceDisplayState(): PriceDisplayState {
void productTradingHoursVersion.value
const p = lastPrice.value
const status = p?.status
if (status === 'closed') {
if (p?.status === 'closed' || p?.closed === true) {
return 'closed'
}
if (status === 'no_quote') {
return getTradeBuyPrice(p) > 0 ? 'open' : 'no_quote'
}
if (status === 'open') {
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0 ? 'open' : 'no_quote'
}
// سرور status نفرستاده (سازگاری با نسخه قدیمی) → استنتاج سمت کلاینت
if (isStoreClosed()) {
return 'closed'
}
return getTradeBuyPrice(p) > 0 || getTradeSellPrice(p) > 0 ? 'open' : 'no_quote'
if (!hasLivePriceQuote()) {
return 'closed'
}
return 'open'
}
export function getPriceDisplayMessage(state: PriceDisplayState = getPriceDisplayState()): string {