2026-07-04 22:06:47 +03:30
|
|
|
|
/** پارس مقدار هزینه خرید/فروش (نقدی یا درصدی) قبل از ارسال به API */
|
2026-07-04 22:13:37 +03:30
|
|
|
|
function normalizeDecimalString(value: string) {
|
|
|
|
|
|
const trimmed = value.trim()
|
|
|
|
|
|
if (!trimmed.includes(',') || trimmed.includes('.')) {
|
|
|
|
|
|
return trimmed.replaceAll(',', '')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 0,5 => 0.5
|
|
|
|
|
|
return trimmed.replace(',', '.')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-04 22:06:47 +03:30
|
|
|
|
export function parseCashFeeValue(value: unknown): number {
|
|
|
|
|
|
if (value === undefined || value === null) {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-04 22:13:37 +03:30
|
|
|
|
const raw = normalizeDecimalString(String(value))
|
2026-07-04 22:06:47 +03:30
|
|
|
|
if (raw === '') {
|
|
|
|
|
|
return 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const num = Number(raw)
|
|
|
|
|
|
return Number.isFinite(num) ? num : 0
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function normalizeCashFeeFlags(value: unknown): boolean {
|
|
|
|
|
|
if (value === true || value === 1 || value === '1' || value === 'true') {
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function formatAdminCashFeeLabel(
|
|
|
|
|
|
value: number | null | undefined,
|
|
|
|
|
|
isPercent?: boolean | null,
|
|
|
|
|
|
) {
|
|
|
|
|
|
const raw = Number(value ?? 0)
|
|
|
|
|
|
if (!raw) {
|
|
|
|
|
|
return '۰'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isPercent) {
|
2026-07-04 22:13:37 +03:30
|
|
|
|
const text = Number.isInteger(raw) ? String(raw) : String(parseFloat(raw.toFixed(4)))
|
|
|
|
|
|
return `${text}%`
|
2026-07-04 22:06:47 +03:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return String(raw)
|
|
|
|
|
|
}
|