wallet handling
This commit is contained in:
@@ -93,9 +93,47 @@ function formatRialNumber(value: number): string {
|
||||
return Math.round(value).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
}
|
||||
|
||||
/** متن توضیح مودال دارایی ریالی — cash_wallet + assets_rial_value */
|
||||
export function formatRialAssetsInfoText(cashWallet: number, assetsRialValue: number): string {
|
||||
return `مجموع کیف پول ریالی (${formatRialNumber(cashWallet)} ریال) + معادل ریالی محصولات (${formatRialNumber(assetsRialValue)} ریال)`
|
||||
/** متن توضیح مودال دارایی ریالی */
|
||||
export function formatRialAssetsInfoText(cashWallet: number, metalRialValue: number): string {
|
||||
const total = cashWallet + metalRialValue
|
||||
return [
|
||||
`کیف پول ریالی: ${formatRialNumber(cashWallet)} ریال`,
|
||||
`ارزش ریالی طلا (وزن × قیمت زنده): ${formatRialNumber(metalRialValue)} ریال`,
|
||||
`مجموع: ${formatRialNumber(total)} ریال`,
|
||||
].join('\n')
|
||||
}
|
||||
|
||||
/** ارزش ریالی فلزات از وزن × قیمت زنده — fallback کلاینت قبل از deploy بکاند */
|
||||
export function computeMetalRialValue(
|
||||
metalTotals: Array<{ metal_id?: number; total_weight?: number }>,
|
||||
liveGoldPrice: number,
|
||||
livePricesByMetal?: Partial<Record<number, number>>
|
||||
): number {
|
||||
return metalTotals.reduce((sum, metal) => {
|
||||
const weight = Number(metal.total_weight ?? 0)
|
||||
if (weight <= 0) {
|
||||
return sum
|
||||
}
|
||||
|
||||
const metalId = Number(metal.metal_id ?? 0)
|
||||
const unitPrice =
|
||||
livePricesByMetal?.[metalId] ??
|
||||
(metalId === METAL_GOLD ? liveGoldPrice : 0)
|
||||
|
||||
return sum + weight * unitPrice
|
||||
}, 0)
|
||||
}
|
||||
|
||||
export function resolveAssetsRialValue(
|
||||
summary: { assets_rial_value?: number; metal_totals?: Array<{ metal_id?: number; total_weight?: number }> } | null | undefined,
|
||||
liveGoldPrice: number
|
||||
): number {
|
||||
const fromServer = Number(summary?.assets_rial_value ?? 0)
|
||||
if (fromServer > 0) {
|
||||
return fromServer
|
||||
}
|
||||
|
||||
return computeMetalRialValue(summary?.metal_totals ?? [], liveGoldPrice)
|
||||
}
|
||||
|
||||
export function formatInventoryCardValue(card: {
|
||||
|
||||
@@ -61,8 +61,8 @@
|
||||
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(cashWallet) }}ریال</div>
|
||||
</div>
|
||||
<div class="flex justify-center mt-2 w-full z-20">
|
||||
معادل ریالی مجموع دارایی ها:
|
||||
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(totalRialValue) }}ریال</div>
|
||||
مجموع دارایی ریالی:
|
||||
<div class="text-l mr-4 font-bold">{{ usePriceWithoutType(cashWallet + metalRialValue) }}ریال</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -108,8 +108,9 @@ import { usePriceWithoutType } from '@/utils/usePrice'
|
||||
import { useConfigStore } from '@/store/configStore'
|
||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||
import { resolveSummaryMetalWeight, fundPageInventoryCards } from '@/utils/productAssets'
|
||||
import { resolveSummaryMetalWeight, fundPageInventoryCards, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||
import { useWalletStore } from '@/store/walletStore'
|
||||
import { getTradeBuyPrice, lastPrice } from '@/utils/price'
|
||||
import {
|
||||
getProjectFundEmptyImage,
|
||||
getProjectFundEmptyText,
|
||||
@@ -129,7 +130,9 @@ const inventoryCards = computed(() => fundPageInventoryCards(assetsSummary.value
|
||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
||||
const metalRialValue = computed(() =>
|
||||
resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||
)
|
||||
const countBasedInventory = computed(() =>
|
||||
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
||||
)
|
||||
@@ -137,7 +140,7 @@ const countBasedInventory = computed(() =>
|
||||
onMounted(async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
const tasks = [loadWalletAssets(true)]
|
||||
const tasks = [loadWalletAssets(true), getLastPrices()]
|
||||
if (isBazretalaProject()) {
|
||||
tasks.push(walletStore.getMyWallet())
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</template>
|
||||
<div class="flex mt-2 justify-center text-tertiary w-full z-20">
|
||||
دارایی ریالی:
|
||||
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(totalRialValue) }} ریال</div>
|
||||
<div class="text-l mr-2 font-bold">{{ usePriceWithoutType(cashWallet) }} ریال</div>
|
||||
<BasicIcon @click="$emit('openRialModal')" icon="vuesax-linear:info-circle" size="18" color="tertiary" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -59,7 +59,7 @@ defineEmits<{
|
||||
const meta = computed(() => assetsSummary.value?.meta)
|
||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||
const primaryMetalTotal = computed(() => metalTotals.value[0])
|
||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
||||
const countBasedInventory = computed(() =>
|
||||
(assetsSummary.value?.count_products ?? []).reduce((sum, item) => sum + Number(item.quantity ?? 0), 0)
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
<a-divider class="!my-1" />
|
||||
<BasicInfoItem
|
||||
class="flex justify-between"
|
||||
title="معادل ریالی محصولات"
|
||||
title="ارزش ریالی طلا (وزن × قیمت زنده)"
|
||||
is-line
|
||||
:value="usePrice(assetsRialValue)"
|
||||
:value="usePrice(metalRialValue)"
|
||||
/>
|
||||
<a-divider class="!my-1" />
|
||||
<BasicInfoItem
|
||||
@@ -56,7 +56,8 @@ import BasicInfoItem from '@/components/BasicPacks/BasicInfoItem.vue'
|
||||
import { usePrice } from '@/utils/usePrice'
|
||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||
import { formatInventoryCardValue, assetSheetInventoryCards } from '@/utils/productAssets'
|
||||
import { formatInventoryCardValue, assetSheetInventoryCards, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||
import { getTradeBuyPrice, lastPrice } from '@/utils/price'
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean
|
||||
@@ -78,8 +79,10 @@ const visible = computed({
|
||||
const inventoryCards = computed(() => assetsSummary.value?.inventory_cards ?? [])
|
||||
const metalTotals = computed(() => assetsSummary.value?.metal_totals ?? [])
|
||||
const cashWallet = computed(() => assetsSummary.value?.cash_wallet ?? 0)
|
||||
const assetsRialValue = computed(() => assetsSummary.value?.assets_rial_value ?? 0)
|
||||
const totalRialValue = computed(() => assetsSummary.value?.total_rial_value ?? 0)
|
||||
const metalRialValue = computed(() =>
|
||||
resolveAssetsRialValue(assetsSummary.value, getTradeBuyPrice(lastPrice.value))
|
||||
)
|
||||
const totalRialValue = computed(() => cashWallet.value + metalRialValue.value)
|
||||
|
||||
onMounted(() => {
|
||||
void loadWalletAssets()
|
||||
|
||||
@@ -84,11 +84,11 @@ import {useUserStore} from '@/store/userStore'
|
||||
import {useWalletStore} from '@/store/walletStore'
|
||||
import { useWalletAssets } from '@/composables/useWalletAssets'
|
||||
import type { WalletMetalTotal } from '@/models/walletAssets'
|
||||
import { formatMetalAssetsInfoText, formatRialAssetsInfoText } from '@/utils/productAssets'
|
||||
import { formatMetalAssetsInfoText, formatRialAssetsInfoText, resolveAssetsRialValue } from '@/utils/productAssets'
|
||||
import {getLastPrices, getTradeBuyPrice, lastPrice, price, startLastPricePolling, stopLastPricePolling} from '@/utils/price'
|
||||
import {useConfigStore} from '@/store/configStore'
|
||||
import {useFundUserStore} from '@/store/fundStore'
|
||||
import {usePriceWithoutType} from '../../../utils/usePrice'
|
||||
import {getLastPrices, lastPrice, price, startLastPricePolling, stopLastPricePolling} from '@/utils/price'
|
||||
import { getStoreClosedMessage, isStoreClosed } from '@/utils/storeHours'
|
||||
import {getConstByKey} from '@/api/const'
|
||||
import {message, Modal} from 'ant-design-vue'
|
||||
@@ -228,11 +228,11 @@ function openGoldModal(metal: WalletMetalTotal) {
|
||||
|
||||
function openRialModal() {
|
||||
const summary = assetsSummary.value
|
||||
const cash = summary?.cash_wallet ?? 0
|
||||
const metalRial = resolveAssetsRialValue(summary, getTradeBuyPrice(lastPrice.value))
|
||||
Modal.confirm({
|
||||
title: formatRialAssetsInfoText(
|
||||
summary?.cash_wallet ?? 0,
|
||||
summary?.assets_rial_value ?? 0
|
||||
),
|
||||
title: 'دارایی ریالی',
|
||||
content: formatRialAssetsInfoText(cash, metalRial),
|
||||
okText: 'متوجه شدم',
|
||||
centered: true,
|
||||
cancelButtonProps: {style: {display: 'none'}}
|
||||
|
||||
Reference in New Issue
Block a user