feat: dynamic assets banner price stats alignment intrinsic value labels and closed store text

This commit is contained in:
2026-11-18 18:26:18 +03:30
parent 21472823b4
commit 1aceafd02d
18 changed files with 384 additions and 73 deletions
@@ -340,6 +340,46 @@ const dayChangeAmountLabel = computed(() => {
return `${delta > 0 ? '+' : '−'}${abs} ریال`
})
function isPointRecordedToday(timeMs: number): boolean {
try {
const tehranFormatter = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Asia/Tehran',
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
return tehranFormatter.format(new Date(timeMs)) === tehranFormatter.format(new Date())
} catch {
return Date.now() - timeMs < 24 * 60 * 60 * 1000
}
}
const todayChartPoints = computed(() => {
const points = chartPoints.value
const todayOnly = points.filter((p) => isPointRecordedToday(p.timeMs))
return todayOnly.length >= 2 ? todayOnly : points
})
const todayChartValues = computed(() =>
todayChartPoints.value.map((p) => p.price).filter((p) => Number.isFinite(p) && p > 0),
)
const dayRange = computed(() => {
const values = todayChartValues.value
const current = Number.isFinite(liveUnitPrice.value) && liveUnitPrice.value > 0 ? liveUnitPrice.value : 0
const allValues = current > 0 ? [...values, current] : values
if (!allValues.length) {
return { high: current, low: current }
}
return {
high: Math.max(...allValues),
low: Math.min(...allValues),
}
})
const dayHighPrice = computed(() => dayRange.value.high)
const dayLowPrice = computed(() => dayRange.value.low)
function resolveHoverFromEvent(
event: PointerEvent,
chart: { samples: ChartPlotSample[]; hasData: boolean },
@@ -439,14 +479,24 @@ function setupLiveChartDraw() {
observer.observe(liveChartPlotEl.value)
}
watch(
selectedChartProduct,
(product) => {
if (product) {
const { setChartMetal } = usePriceChart()
setChartMetal(metalFromProductTitle(product.title))
}
},
{ immediate: true },
)
function setLiveProduct(productId: number) {
if (!chartProductTabs.value.some((product) => product.id === productId)) return
const targetProduct = chartProductTabs.value.find((product) => product.id === productId)
if (!targetProduct) return
activeProductId.value = productId
liveChartHover.value = null
const product = selectedChartProduct.value
if (!product) return
const { setChartMetal } = usePriceChart()
setChartMetal(metalFromProductTitle(product.title))
setChartMetal(metalFromProductTitle(targetProduct.title))
}
async function setLiveChartRange(range: LandingHistoryRange) {
@@ -536,6 +586,9 @@ export function useLandingLiveChart() {
liveChartPlotEl,
liveSectionChart,
formattedLivePrice,
liveUnitPrice,
dayHighPrice,
dayLowPrice,
liveProductLabel,
liveChartRangeLabel,
liveMarketState,