fix kashkool

This commit is contained in:
2026-06-29 22:43:28 +03:30
parent be17631109
commit 8b855e5ee4
150 changed files with 11974 additions and 4445 deletions
+25 -6
View File
@@ -20,14 +20,28 @@ export const olderPrice = ref<number | undefined>(0)
let lastPriceSourceAt = 0
let consecutivePriceFetchFailures = 0
/** buy/sell نمایش و معامله — همان buy/sell/price_last از /api/price/last */
export function getTradeBuyPrice(p?: Price | null) {
return p?.buy ?? p?.price_last ?? p?.up?.buy ?? 0
}
export function getTradeSellPrice(p?: Price | null) {
return p?.sell ?? p?.up?.sell ?? 0
}
/** up جدا نگه داشته می‌شود؛ buy/sell/price_last از lastPrice سرور دست‌نخورده می‌ماند */
export function normalizePriceResponse(data: Price): Price {
return data
}
function hasValidPricePayload(data?: Price | null): boolean {
if (!data) {
return false
}
return (
Number(data.buy ?? data.up?.buy ?? 0) > 0
|| Number(data.sell ?? data.up?.sell ?? 0) > 0
getTradeBuyPrice(data) > 0
|| getTradeSellPrice(data) > 0
|| Number(data.price_last ?? data.price ?? 0) > 0
)
}
@@ -147,13 +161,18 @@ export async function getLastPrices(): Promise<boolean> {
}
export function applyLastPricePayload(dataLast: Price) {
if (lastPrice.value?.price_last != dataLast.price_last) {
const normalized = normalizePriceResponse(dataLast)
if (lastPrice.value?.price_last != normalized.price_last) {
olderPrice.value = lastPrice.value?.price_last
}
lastPrice.value = dataLast
price.value = dataLast
lastPrice.value = normalized
price.value = {
...normalized,
buy: getTradeBuyPrice(normalized),
sell: getTradeSellPrice(normalized),
}
if (hasValidPricePayload(dataLast)) {
if (hasValidPricePayload(normalized)) {
markPriceSourceReceived()
}
}