feat: align fee summary, special pricing and support chat with modular
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,7 +5,7 @@ export type ProductCashFeeSource = {
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
}
|
||||
|
||||
/** 0.5 => 0.5% ، 5 => 5% */
|
||||
/** 0.5 => 0.5% ، 5 => 5% — همیشه عدد درصد */
|
||||
export function resolveCashFeePercentRatio(percentValue?: number | null) {
|
||||
const offset = Number(percentValue ?? 0)
|
||||
if (!offset || !Number.isFinite(offset)) {
|
||||
@@ -15,6 +15,11 @@ export function resolveCashFeePercentRatio(percentValue?: number | null) {
|
||||
return offset / 100
|
||||
}
|
||||
|
||||
/** @deprecated از resolveCashFeePercentRatio استفاده کنید */
|
||||
export function resolveFeePercentRatio(percentValue?: number | null) {
|
||||
return resolveCashFeePercentRatio(percentValue)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeRial(
|
||||
feeValue: number | null | undefined,
|
||||
isPercent: boolean | null | undefined,
|
||||
@@ -38,17 +43,38 @@ export function resolveProductCashFeeRial(
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
return resolveProductCashFeeRial(
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_buy,
|
||||
product.cash_fee_buy_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_buy ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
return resolveProductCashFeeRial(
|
||||
const baseFee = resolveProductCashFeeRial(
|
||||
product.cash_fee_sell,
|
||||
product.cash_fee_sell_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
const special = Number((product as any).special_profit_sell ?? 0)
|
||||
return baseFee + (Number.isFinite(special) ? Math.round(special) : 0)
|
||||
}
|
||||
|
||||
export function formatProductCashFeeLabel(
|
||||
feeValue: number | null | undefined,
|
||||
isPercent?: boolean | null,
|
||||
) {
|
||||
const raw = Number(feeValue ?? 0)
|
||||
if (!raw) {
|
||||
return '۰'
|
||||
}
|
||||
|
||||
if (isPercent) {
|
||||
const text = Number.isInteger(raw) ? String(raw) : String(parseFloat(raw.toFixed(4)))
|
||||
return `${text}%`
|
||||
}
|
||||
|
||||
return `${raw} ریال`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user