update
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
export type ProductCashFeeSource = {
|
||||
cash_fee_buy?: number | null
|
||||
cash_fee_sell?: number | null
|
||||
cash_fee_buy_is_percent?: boolean | null
|
||||
cash_fee_sell_is_percent?: boolean | null
|
||||
}
|
||||
|
||||
/** 0.5 => 0.5% ، 5 => 5% */
|
||||
export function resolveCashFeePercentRatio(percentValue?: number | null) {
|
||||
const offset = Number(percentValue ?? 0)
|
||||
if (!offset || !Number.isFinite(offset)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return offset / 100
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeRial(
|
||||
feeValue: number | null | undefined,
|
||||
isPercent: boolean | null | undefined,
|
||||
basePriceRial: number,
|
||||
) {
|
||||
const raw = Number(feeValue ?? 0)
|
||||
if (!raw || !Number.isFinite(raw)) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (!isPercent) {
|
||||
return Math.round(raw)
|
||||
}
|
||||
|
||||
const base = Number(basePriceRial)
|
||||
if (!base || base <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
return Math.round(Math.abs(base * resolveCashFeePercentRatio(raw)))
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeBuyRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
return resolveProductCashFeeRial(
|
||||
product.cash_fee_buy,
|
||||
product.cash_fee_buy_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
}
|
||||
|
||||
export function resolveProductCashFeeSellRial(product: ProductCashFeeSource, basePriceRial: number) {
|
||||
return resolveProductCashFeeRial(
|
||||
product.cash_fee_sell,
|
||||
product.cash_fee_sell_is_percent,
|
||||
basePriceRial,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user