From a56011d394c0a448a4f193e766c60997c0f83258 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Sat, 29 Jun 2024 13:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=3D=E5=8E=9F=E4=BB=B7+=E5=90=84=E7=A7=8D=E6=89=8B=E7=BB=AD?= =?UTF-8?q?=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Dialogs/buyDialog.vue | 4 ++-- src/components/cart/index.vue | 6 +++--- src/components/chain/utils.js | 12 ++++++++++-- src/components/common/card.vue | 8 +++++--- src/views/DetailView.vue | 8 +++++--- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/components/Dialogs/buyDialog.vue b/src/components/Dialogs/buyDialog.vue index fdfd735..75b6f65 100644 --- a/src/components/Dialogs/buyDialog.vue +++ b/src/components/Dialogs/buyDialog.vue @@ -34,7 +34,7 @@
{{ item.nft.token_id }}
-
{{ priceCalculated(item.event.data.buy[0].amount) }}
+
{{ priceCalculated(item.amount) }}
@@ -75,7 +75,7 @@ const props = defineProps({ const totalPrice = computed(() => { let total = 0n; props.buyDataArr.forEach((item) => { - total += BigInt(item.event.data.buy[0].amount); + total += item.amount; }); return priceCalculated(total); }); diff --git a/src/components/cart/index.vue b/src/components/cart/index.vue index d406c76..8d715b4 100644 --- a/src/components/cart/index.vue +++ b/src/components/cart/index.vue @@ -17,7 +17,7 @@
-
{{ priceCalculated(item.event.data.buy[0].amount) }}
+
{{ priceCalculated(item.amount) }}
@@ -121,8 +121,8 @@ const getCartList = async () => { console.log(res) if (res.data && res.data.length > 0) { for (let sub of res.data) { - if (sub.event?.data?.buy && sub.event.data.buy.length > 0) { - const _data = formatPrice(sub.event.data.buy[0]) + if (sub.event?.data) { + const _data = formatPrice(sub.event.data) sub.icon = _data.icon sub.usd = _data.usd sub.currencyName = _data.currencyName diff --git a/src/components/chain/utils.js b/src/components/chain/utils.js index d0cfc00..d866089 100644 --- a/src/components/chain/utils.js +++ b/src/components/chain/utils.js @@ -204,11 +204,19 @@ export const switchEthereumChain = async (provider, targetChainId) => { return deferred.promise } -export const formatPrice = (data) => { +export const formatPrice = (nftData) => { + const data = nftData.buy[0] + const feeList = nftData.fees || [] const marketplaceList = useMarketplaceStore() const type = data.item_type let address; let icon, price, usd, currencyName; + let amountBn = BigInt(data.amount) + if (feeList.length > 0) { + feeList.forEach(fee => { + amountBn = amountBn + BigInt(fee.amount) + }) + } const tokenAmount = priceCalculated(data.amount) const amount = parseFloat(ethers.utils.formatUnits(data.amount, 18)) if (type == 'NATIVE') { @@ -232,5 +240,5 @@ export const formatPrice = (data) => { usd = (amount * price.price).toFixed(2) } } - return {icon, price, usd, tokenAmount, currencyName, amount: BigInt(data.amount)} + return {icon, price, usd, tokenAmount, currencyName, amount: amountBn} } \ No newline at end of file diff --git a/src/components/common/card.vue b/src/components/common/card.vue index 0751d5f..072b57d 100644 --- a/src/components/common/card.vue +++ b/src/components/common/card.vue @@ -11,7 +11,7 @@
- {{ priceCalculated(nftData.event.data.buy[0].amount) }} + {{ price }} 图片
@@ -53,6 +53,7 @@ const emit = defineEmits(['renewNft']) import { useRouter } from "vue-router"; const router = useRouter(); const icon = ref('') +const price = ref('-') const { proxy } = getCurrentInstance(); const props = defineProps({ nftData: { @@ -132,9 +133,10 @@ const cardLogin = async () => { onMounted(() => { // console.log(JSON.parse(JSON.stringify(props.nftData)), "-=-=-"); - if (props.nftData?.event?.data?.buy && props.nftData?.event?.data?.buy.length > 0) { - const data = formatPrice(props.nftData?.event?.data?.buy[0]) + if (props.nftData?.event?.data) { + const data = formatPrice(props.nftData?.event?.data) icon.value = data.icon + price.value = priceCalculated(data.amount.toString()) } }); diff --git a/src/views/DetailView.vue b/src/views/DetailView.vue index e5be773..c4a572a 100644 --- a/src/views/DetailView.vue +++ b/src/views/DetailView.vue @@ -25,7 +25,7 @@
  • - {{ priceCalculated(detailData.event.data.buy[0].amount) }}  + {{ price }}  ICON ( $ {{ usd }} )
    @@ -164,6 +164,7 @@ const myAddress = localWalletStore.address const nftAbilities = ref() const icon = ref('') const usd = ref('') +const price = ref('') // 购买 const buyNow = async () => { @@ -291,10 +292,11 @@ const getDetail = async () => { nftData.event = data.event nftAbilities.value = data.nft.detail detailData.value = data - if (data.event?.data?.buy && data.event?.data?.buy.length > 0) { - const _data = formatPrice(data.event?.data?.buy[0]) + if (data.event?.data) { + const _data = formatPrice(data.event?.data) icon.value = _data.icon usd.value = _data.usd + price.value = priceCalculated(_data.amount.toString()) } console.log(data,'----') }