widthdraw and deposit

This commit is contained in:
2026-06-09 21:04:22 +03:30
parent 95516ee2d8
commit 689c51c27d
26 changed files with 1228 additions and 522 deletions
+49
View File
@@ -0,0 +1,49 @@
import { computed, ref } from 'vue'
import { getProducts } from '@/api/products'
import type { Product } from '@/models/products'
import {
catalogHasCountBasedProducts,
catalogHasMeltedProducts,
getCatalogMetalIds,
isSingleMetalCatalog,
} from '@/utils/productAssets'
const catalogProducts = ref<Product[]>([])
let catalogPromise: Promise<Product[]> | null = null
export function useProductCatalog() {
async function loadCatalog(force = false) {
if (!force && catalogProducts.value.length) {
return catalogProducts.value
}
if (!force && catalogPromise) {
return catalogPromise
}
catalogPromise = getProducts()
.then((products) => {
catalogProducts.value = products ?? []
return catalogProducts.value
})
.finally(() => {
catalogPromise = null
})
return catalogPromise
}
const catalogMetalIds = computed(() => getCatalogMetalIds(catalogProducts.value))
const hasCountBasedProducts = computed(() => catalogHasCountBasedProducts(catalogProducts.value))
const hasMeltedProducts = computed(() => catalogHasMeltedProducts(catalogProducts.value))
const isSingleMetal = computed(() => isSingleMetalCatalog(catalogMetalIds.value))
return {
catalogProducts,
catalogMetalIds,
hasCountBasedProducts,
hasMeltedProducts,
isSingleMetal,
loadCatalog,
}
}
+46
View File
@@ -0,0 +1,46 @@
import { ref } from 'vue'
import { getWalletAssets } from '@/api/wallet'
import { getProducts } from '@/api/products'
import type { WalletAssetsSummary } from '@/models/walletAssets'
import { enrichInventoryCardsWithCatalog } from '@/utils/productAssets'
const assetsSummary = ref<WalletAssetsSummary | null>(null)
let assetsPromise: Promise<WalletAssetsSummary> | null = null
export function useWalletAssets() {
async function loadWalletAssets(force = false) {
if (!force && assetsSummary.value) {
return assetsSummary.value
}
if (!force && assetsPromise) {
return assetsPromise
}
assetsPromise = Promise.all([getWalletAssets(), getProducts()])
.then(([data, catalog]) => {
assetsSummary.value = {
...data,
inventory_cards: enrichInventoryCardsWithCatalog(data.inventory_cards ?? [], catalog ?? []),
count_products: enrichInventoryCardsWithCatalog(data.count_products ?? [], catalog ?? []),
}
return assetsSummary.value
})
.finally(() => {
assetsPromise = null
})
return assetsPromise
}
function clearWalletAssets() {
assetsSummary.value = null
assetsPromise = null
}
return {
assetsSummary,
loadWalletAssets,
clearWalletAssets,
}
}