fix(trade): use stream closed and trade_open instead of device clock

Changing the phone time can no longer open a product that the server has closed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-05 12:58:19 +03:30
co-authored by Cursor
parent 2d3c590c71
commit bc2acc3eb6
11 changed files with 86 additions and 24 deletions
+13
View File
@@ -24,6 +24,19 @@ export function isProductTradeOpen(product: TradeOpenProduct, isBuy: boolean) {
return isBuy ? isProductBuyOpen(product) : isProductSellOpen(product)
}
/** ساعت کاری محصول از استریم (trade_open) — نه ساعت دستگاه */
export function isProductTradingHoursOpen(
product?: { show?: boolean; trade_open?: boolean } | null,
) {
if (!product) return false
if (typeof product.trade_open === 'boolean') return product.trade_open
return product.show === true
}
export function productHoursClosedMessage() {
return 'این محصول در حال حاضر خارج از ساعت کاری است.'
}
/** تب اولیه با توجه به query و وضعیت باز/بسته خرید و فروش */
export function resolveProductTradeIsBuy(product: TradeOpenProduct, routeState?: string | null) {
const wantSell = routeState === 'sell'
+5 -14
View File
@@ -225,20 +225,11 @@ export function isStoreClosedBySchedule(now = new Date()): boolean {
return isOutsideTimeWindow(now, start, end)
}
/** باز/بسته بودن فروشگاه فقط از استریم last.closed — نه ساعت دستگاه کاربر */
export function isStoreClosed(): boolean {
void productTradingHoursVersion.value
const { closePriceEnabled } = getStoreTradingHours()
if (closePriceEnabled) {
if (lastPrice.value?.closed === true) {
return true
}
return isStoreClosedBySchedule()
}
// وقتی close_price خاموش است، صفر بودن قیمت مرجع به معنی بسته بودن فروشگاه نیست.
return isStoreClosedBySchedule()
void lastPriceReady.value
void lastPrice.value
return lastPrice.value?.closed === true
}
export function getStoreClosedMessage(): string {
@@ -306,7 +297,7 @@ export function getPriceDisplayState(): PriceDisplayState {
return serverStatus
}
if (isOutsideGlobalStoreHours()) {
if (p?.closed === true) {
if (!shouldShowHomePriceWhenClosed()) return 'closed'
return hasShowableHomePrice(p) ? 'open' : 'no_quote'
}