fix some bugs
This commit is contained in:
@@ -209,7 +209,7 @@ function formatRialNumber(value: number): string {
|
||||
return usePriceWithoutType(Math.round(value))
|
||||
}
|
||||
|
||||
function formatBoursecuProfitLossLine(profitLoss?: number): BoursecuAssetPopupLine {
|
||||
function formatBoursecuProfitLossLine(profitLoss?: number | null): BoursecuAssetPopupLine {
|
||||
const amount = Number(profitLoss ?? 0)
|
||||
|
||||
if (amount > 0) {
|
||||
@@ -398,14 +398,66 @@ export function formatMetalAssetsInfoText(metal: WalletMetalTotal): string {
|
||||
return `${metal.label}: مجموع کیف محصولات (${metal.product_weight} ${unit}) + موجودی کیف اصلی (${metal.melted_weight} ${unit})`
|
||||
}
|
||||
|
||||
/** نمایش سود/زیان برای داشبورد */
|
||||
export function formatPortfolioProfitLabel(profitRial?: number | null): 'profit' | 'loss' | 'neutral' {
|
||||
const amount = Number(profitRial ?? 0)
|
||||
if (amount > 0) return 'profit'
|
||||
if (amount < 0) return 'loss'
|
||||
return 'neutral'
|
||||
}
|
||||
|
||||
export function formatPortfolioProfitText(profitRial?: number | null): string {
|
||||
const amount = Number(profitRial ?? 0)
|
||||
if (amount > 0) {
|
||||
return `+${formatRialNumber(amount)} ریال سود`
|
||||
}
|
||||
if (amount < 0) {
|
||||
return `${formatRialNumber(Math.abs(amount))} ریال زیان`
|
||||
}
|
||||
return `${formatRialNumber(0)} ریال`
|
||||
}
|
||||
|
||||
export function formatPortfolioProfitPercent(percent?: number | null): string {
|
||||
if (percent == null || Number.isNaN(Number(percent))) {
|
||||
return ''
|
||||
}
|
||||
const value = Number(percent)
|
||||
const sign = value > 0 ? '+' : ''
|
||||
return `${sign}${value.toFixed(2)}٪`
|
||||
}
|
||||
|
||||
/** متن توضیح مودال دارایی ریالی */
|
||||
export function formatRialAssetsInfoText(cashWallet: number, metalRialValue: number): string {
|
||||
export function formatRialAssetsInfoText(
|
||||
cashWallet: number,
|
||||
metalRialValue: number,
|
||||
portfolio?: {
|
||||
unrealized_profit_rial?: number | null
|
||||
unrealized_profit_percent?: number | null
|
||||
average_buy_price?: number | null
|
||||
cost_basis_rial?: number | null
|
||||
} | null
|
||||
): string {
|
||||
const total = cashWallet + metalRialValue
|
||||
return [
|
||||
const lines = [
|
||||
`کیف پول ریالی: ${formatRialNumber(cashWallet)} ریال`,
|
||||
`ارزش ریالی طلا (وزن × قیمت زنده): ${formatRialNumber(metalRialValue)} ریال`,
|
||||
`مجموع: ${formatRialNumber(total)} ریال`,
|
||||
].join('\n')
|
||||
`مجموع کل دارایی: ${formatRialNumber(total)} ریال`,
|
||||
]
|
||||
|
||||
if (portfolio?.average_buy_price != null && portfolio.average_buy_price > 0) {
|
||||
lines.push(`میانگین قیمت خرید شما: ${formatRialNumber(portfolio.average_buy_price)} ریال`)
|
||||
}
|
||||
if (portfolio?.cost_basis_rial != null && portfolio.cost_basis_rial > 0) {
|
||||
lines.push(`بهای تمامشده طلا: ${formatRialNumber(portfolio.cost_basis_rial)} ریال`)
|
||||
}
|
||||
if (portfolio?.unrealized_profit_rial != null) {
|
||||
const pct = formatPortfolioProfitPercent(portfolio.unrealized_profit_percent)
|
||||
lines.push(
|
||||
`سود/زیان تحققنیافته: ${formatPortfolioProfitText(portfolio.unrealized_profit_rial)}${pct ? ` (${pct})` : ''}`
|
||||
)
|
||||
}
|
||||
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
/** ارزش ریالی فلزات از وزن × قیمت زنده — fallback کلاینت قبل از deploy بکاند */
|
||||
|
||||
Reference in New Issue
Block a user