fix(assets): resolve accurate copper assets and profit during closed market and normalize ton pricing
This commit is contained in:
@@ -240,14 +240,32 @@ const { assetsSummary, loadWalletAssets } = useWalletAssets()
|
||||
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||
const effectiveClosingPrice = computed(() => {
|
||||
const p = lastPrice.value as any
|
||||
const buy = getTradeBuyPrice(p)
|
||||
if (buy > 0) return buy > 500_000_000 ? buy / 1000 : buy
|
||||
const kilo = Number(p?.copper_kilo ?? 0)
|
||||
if (kilo > 0) return kilo > 500_000_000 ? kilo / 1000 : kilo
|
||||
const ton = Number(p?.copper_ton ?? 0)
|
||||
if (ton > 500_000_000) return ton / 1000
|
||||
const price = Number(p?.price_last ?? p?.price ?? 0)
|
||||
if (price > 500_000_000) return price / 1000
|
||||
return price > 0 ? price : 0
|
||||
})
|
||||
|
||||
const metalRialValue = computed(() => {
|
||||
const fromSummary = Number(assetsSummary.value?.assets_rial_value ?? 0)
|
||||
if (fromSummary > 0) return fromSummary
|
||||
return resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||
return resolveAssetsRialValue(assetsSummary.value, effectiveClosingPrice.value)
|
||||
})
|
||||
const totalRialValue = computed(() => {
|
||||
const fromSummary = Number(assetsSummary.value?.total_rial_value ?? 0)
|
||||
if (fromSummary > 0) return fromSummary
|
||||
let fromSummary = Number(assetsSummary.value?.total_rial_value ?? 0)
|
||||
const copper = metalTotals.value.find((m) => Number(m.metal_id ?? 0) === 3 || Number(m.metal_id ?? 0) === 0)
|
||||
const copperWeight = Number(copper?.total_weight ?? 0)
|
||||
if (copperWeight > 0 && fromSummary / copperWeight > 500_000_000) {
|
||||
fromSummary = fromSummary / 1000
|
||||
}
|
||||
if (fromSummary > 0 && Math.abs(fromSummary - (cashWallet.value + metalRialValue.value)) < 1000) {
|
||||
return fromSummary
|
||||
}
|
||||
return cashWallet.value + metalRialValue.value
|
||||
})
|
||||
|
||||
@@ -264,15 +282,37 @@ const {
|
||||
} = useAssetsPortfolioChart(cashWallet, metalRialValue)
|
||||
const portfolioInsight = computed(() => assetsSummary.value?.portfolio)
|
||||
|
||||
const profitSheetLabel = computed(() => {
|
||||
const safeUnrealizedProfitRial = computed(() => {
|
||||
const profit = portfolioInsight.value?.unrealized_profit_rial
|
||||
if (profit == null) return null
|
||||
if (Math.abs(profit) > 100_000_000_000 && Number(portfolioInsight.value?.cost_basis_rial ?? 0) < 10_000_000_000) {
|
||||
return Math.round(profit / 1000)
|
||||
}
|
||||
return profit
|
||||
})
|
||||
|
||||
const safeUnrealizedProfitPercent = computed(() => {
|
||||
const pct = portfolioInsight.value?.unrealized_profit_percent
|
||||
if (pct == null) return null
|
||||
if (Math.abs(pct) > 1000) {
|
||||
const costBasis = Number(portfolioInsight.value?.cost_basis_rial ?? 0)
|
||||
const profit = safeUnrealizedProfitRial.value
|
||||
if (costBasis > 0 && profit != null) {
|
||||
return Math.round((profit / costBasis) * 10000) / 100
|
||||
}
|
||||
}
|
||||
return pct
|
||||
})
|
||||
|
||||
const profitSheetLabel = computed(() => {
|
||||
const profit = safeUnrealizedProfitRial.value
|
||||
if (profit == null) return '—'
|
||||
const pct = formatPortfolioProfitPercent(portfolioInsight.value?.unrealized_profit_percent)
|
||||
const pct = formatPortfolioProfitPercent(safeUnrealizedProfitPercent.value)
|
||||
return `${formatPortfolioProfitText(profit)}${pct ? ` (${pct})` : ''}`
|
||||
})
|
||||
|
||||
const profitClass = computed(() => {
|
||||
const profit = portfolioInsight.value?.unrealized_profit_rial
|
||||
const profit = safeUnrealizedProfitRial.value
|
||||
if (profit == null || profit === 0) return ''
|
||||
return profit > 0 ? 'is-profit' : 'is-loss'
|
||||
})
|
||||
@@ -290,17 +330,19 @@ const summaryItems = computed(() => {
|
||||
{ label: 'ارزش ریالی مس', value: usePrice(metalRialValue.value) },
|
||||
)
|
||||
if (portfolioInsight.value?.average_buy_price != null) {
|
||||
let avg = Number(portfolioInsight.value.average_buy_price ?? 0)
|
||||
if (avg > 500_000_000) avg = Math.round(avg / 1000)
|
||||
items.push({
|
||||
label: 'میانگین خرید',
|
||||
value: usePrice(portfolioInsight.value.average_buy_price ?? 0),
|
||||
value: usePrice(avg),
|
||||
})
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
||||
const assetRows = computed(() => {
|
||||
const pct = formatPortfolioProfitPercent(portfolioInsight.value?.unrealized_profit_percent)
|
||||
const profit = portfolioInsight.value?.unrealized_profit_rial
|
||||
const pct = formatPortfolioProfitPercent(safeUnrealizedProfitPercent.value)
|
||||
const profit = safeUnrealizedProfitRial.value
|
||||
const changeClass = profit == null || profit === 0 ? '' : profit > 0 ? 'is-profit' : 'is-loss'
|
||||
const rows = metalTotals.value.flatMap((metal) => {
|
||||
const unit = metal.metal_id === 3 ? resolveBoursecuCopperUnit(metal.unit) : (metal.unit || 'کیلوگرم')
|
||||
|
||||
@@ -66,8 +66,21 @@ const { assetsSummary } = useWalletAssets()
|
||||
const rootRef = ref<HTMLElement | null>(null)
|
||||
const openRowId = ref<BoursecuHomeAssetRowId | null>(null)
|
||||
|
||||
const effectiveClosingPrice = computed(() => {
|
||||
const p = lastPrice.value as any
|
||||
const buy = getTradeBuyPrice(p)
|
||||
if (buy > 0) return buy > 500_000_000 ? buy / 1000 : buy
|
||||
const kilo = Number(p?.copper_kilo ?? 0)
|
||||
if (kilo > 0) return kilo > 500_000_000 ? kilo / 1000 : kilo
|
||||
const ton = Number(p?.copper_ton ?? 0)
|
||||
if (ton > 500_000_000) return ton / 1000
|
||||
const price = Number(p?.price_last ?? p?.price ?? 0)
|
||||
if (price > 500_000_000) return price / 1000
|
||||
return price > 0 ? price : 0
|
||||
})
|
||||
|
||||
const rows = computed(() =>
|
||||
buildBoursecuHomeAssetRows(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||
buildBoursecuHomeAssetRows(assetsSummary.value, effectiveClosingPrice.value)
|
||||
)
|
||||
|
||||
function toggleRow(rowId: BoursecuHomeAssetRowId) {
|
||||
|
||||
Reference in New Issue
Block a user