price calulator changed 5

This commit is contained in:
2026-07-02 20:58:29 +03:30
parent 148acafdc0
commit 7381baca0d
5 changed files with 70 additions and 11 deletions
+15 -3
View File
@@ -90,6 +90,17 @@ export function calcGramFromLockedRial(rialAmount: number, unitPriceRial: number
return parseFloat((rial / (unit * (1 - fee))).toFixed(6))
}
/** مبلغ ریالی قفل‌شده توسط کاربر — برای ارسال به سرور */
export function calcTradeTargetCash(
goldCash?: number | null,
inputLock?: TradeInputLock,
): number | undefined {
if (inputLock !== 'rial') return undefined
const cash = Number(goldCash ?? 0)
if (cash <= 0) return undefined
return Math.round(cash)
}
/** مبلغ نهایی قابل پرداخت (خرید) یا دریافت (فروش) به ریال */
export function calcPayablePriceRial(
finalPriceRial: number,
@@ -97,10 +108,11 @@ export function calcPayablePriceRial(
isBuy: boolean,
targetRialCash?: number | null
) {
if (targetRialCash != null && Number(targetRialCash) > 0) {
return Number(targetRialCash)
}
if (feeDeductFromGold.value) {
if (targetRialCash != null && Number(targetRialCash) > 0) {
return Number(targetRialCash)
}
if (isBuy) return finalPriceRial + feeInRial
return finalPriceRial
}
+42
View File
@@ -54,7 +54,21 @@ type TransactionPriceSource = {
price?: number | null
total_price?: number | null
amount?: number | null
sts?: number | null
sts_str?: string | number | null
payment_sts?: number | null
} | null
withdraw?: {
sts?: number | null
sts_str?: string | number | null
} | null
order_id?: number | null
}
const ORDER_STATUS_LABELS: Record<number, string> = {
1: 'باز',
2: 'موفق',
3: 'ناموفق',
}
export function getTransactionTradePrice(item: TransactionPriceSource): number {
@@ -79,6 +93,34 @@ export function getTransactionTradePrice(item: TransactionPriceSource): number {
return 0
}
export function resolveTransactionStatusLabel(item?: TransactionPriceSource | null): string {
if (!item) return ''
const raw = item.order?.sts_str ?? item.withdraw?.sts_str
if (typeof raw === 'string') {
const trimmed = raw.trim()
if (trimmed && trimmed !== 'بدون مقدار') {
return trimmed
}
}
if (typeof raw === 'number' || (typeof raw === 'string' && /^\d+$/.test(String(raw).trim()))) {
const mapped = ORDER_STATUS_LABELS[Number(raw)]
if (mapped) return mapped
}
const sts = item.order?.sts ?? item.withdraw?.sts
if (sts != null && ORDER_STATUS_LABELS[Number(sts)]) {
return ORDER_STATUS_LABELS[Number(sts)]
}
if (item.order_id && Number(item.order?.payment_sts) === 4) {
return 'موفق'
}
return ''
}
export function getTransactionGoldAmount(item: TransactionPriceSource): number {
const gold = Number(item.gold) || 0
if (Math.abs(gold) > 0) {