diff --git a/src/components/cart/index.vue b/src/components/cart/index.vue
index f71e4cf..d406c76 100644
--- a/src/components/cart/index.vue
+++ b/src/components/cart/index.vue
@@ -19,7 +19,7 @@
-
-
Total Price
-
{{ completePrice(cartList) }}

+
+
+
Total Price
+
+
{{ priceCalculated(item.amount) }}
![]()
+
-
≈ {{ 200 }}$
+
≈ {{ usdTotal }}$
@@ -58,11 +61,13 @@ import { useRouter } from "vue-router";
import { useMarketplaceStore } from "@/store/marketplace"
import {priceCalculated, completePrice} from "@/configs/priceCalculate.js"
import {createModal} from "@/utils/model.util";
+import {formatPrice} from "@/components/chain/utils"
const marketplaceList = useMarketplaceStore()
import {
apiDelCartList,
apiClearCartList,
} from "@/utils/marketplace"
+import { computed } from "vue";
const router = useRouter();
const emit = defineEmits(['clickStatusChild'])
@@ -77,6 +82,33 @@ const toMarketplace = () => {
router.push('/marketplace');
}
+const priceList = computed(() => {
+ let map = new Map()
+ for (let item of cartList.value) {
+ if (!map.has(item.currencyName)) {
+ map.set(item.currencyName, {
+ icon: item.icon,
+ amount: 0n,
+ })
+ }
+ let data = map.get(item.currencyName)
+ data.amount += item.amount
+ map.set(item.currencyName, data)
+ }
+ let result = []
+ for (let [key, value] of map) {
+ result.push(value)
+ }
+ return result
+});
+
+const usdTotal = computed(() => {
+ let total = 0
+ for (let item of cartList.value) {
+ total += Number(item.usd)
+ }
+ return total.toFixed(2)
+})
@@ -86,6 +118,19 @@ const getCartList = async () => {
// if(token) {
try {
let res = await marketplaceList.getCartListState()
+ 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])
+ sub.icon = _data.icon
+ sub.usd = _data.usd
+ sub.currencyName = _data.currencyName
+ sub.amount = _data.amount
+ }
+ }
+ }
+
console.log(res)
cartList.value = res.data
marketplaceList.getCartList = res
diff --git a/src/components/chain/BlockChain.js b/src/components/chain/BlockChain.js
index 54052b6..7644b72 100644
--- a/src/components/chain/BlockChain.js
+++ b/src/components/chain/BlockChain.js
@@ -100,9 +100,15 @@ export class BlockChain {
}
}
- get token() {
+ async token() {
const suffix = (this.store.walletType == 2 || this.store.walletType == 1) ? '.cf' : ''
- return this.store.token+suffix
+ let token = this.store.token;
+ if (!suffix) {
+ const res = await this.wallet.getAccessToken();
+ token = res.token
+ }
+
+ return token+suffix
}
async logout() {
diff --git a/src/components/chain/Market.js b/src/components/chain/Market.js
index 477e117..609b4c4 100644
--- a/src/components/chain/Market.js
+++ b/src/components/chain/Market.js
@@ -233,14 +233,19 @@ export class ImtblMarket {
async updateCurrencyPrice() {
const ids = ['immutable-x', 'ethereum', 'usd-coin']
- let priceList = await queryTokenPriceCg(ids);
- priceList = priceList.map((item) => {
- return {
- id: item.id,
- price: item.current_price
- }
- })
- this.marketStore.currencyPrice = priceList;
- return priceList;
+ try {
+ let priceList = await queryTokenPriceCg(ids);
+ priceList = priceList.map((item) => {
+ return {
+ id: item.id,
+ price: item.current_price
+ }
+ })
+ this.marketStore.currencyPrice = priceList;
+ return priceList;
+ } catch (err) {
+
+ }
+
}
}
diff --git a/src/components/chain/utils.js b/src/components/chain/utils.js
index 66532f0..d0cfc00 100644
--- a/src/components/chain/utils.js
+++ b/src/components/chain/utils.js
@@ -208,8 +208,8 @@ export const formatPrice = (data) => {
const marketplaceList = useMarketplaceStore()
const type = data.item_type
let address;
- let icon, price, usd
- const tokenAmount = priceCalculated(data.amount, 3)
+ let icon, price, usd, currencyName;
+ const tokenAmount = priceCalculated(data.amount)
const amount = parseFloat(ethers.utils.formatUnits(data.amount, 18))
if (type == 'NATIVE') {
address = 'NATIVE'
@@ -224,6 +224,7 @@ export const formatPrice = (data) => {
}
if (address) {
const currencyData = currencyMap[address]
+ currencyName = currencyData.name
if (currencyData) {
const currencyPrice = marketplaceList.priceDatas
icon = currencyData.icon
@@ -231,5 +232,5 @@ export const formatPrice = (data) => {
usd = (amount * price.price).toFixed(2)
}
}
- return {icon, price, usd, tokenAmount}
+ return {icon, price, usd, tokenAmount, currencyName, amount: BigInt(data.amount)}
}
\ No newline at end of file
diff --git a/src/components/chain/wallet/PassportWallet.js b/src/components/chain/wallet/PassportWallet.js
index cd75308..34ce607 100644
--- a/src/components/chain/wallet/PassportWallet.js
+++ b/src/components/chain/wallet/PassportWallet.js
@@ -64,13 +64,13 @@ export class PassportWallet {
const passportProvider = this.passportInstance.connectEvm();
const accounts = await passportProvider.request({ method: "eth_requestAccounts" });
const provider = new providers.Web3Provider(passportProvider);
- const token = await this.passportInstance.getAccessToken()
+ const token = await this.passportInstance.getIdToken()
return { provider, accounts, token };
}
async getAccessToken() {
- const token = await this.passportInstance.getAccessToken();
+ const token = await this.passportInstance.getIdToken();
return { token }
}
diff --git a/src/utils/marketplace.js b/src/utils/marketplace.js
index 33a9a54..3b76aae 100644
--- a/src/utils/marketplace.js
+++ b/src/utils/marketplace.js
@@ -8,7 +8,7 @@ const net_id = import.meta.env.VUE_APP_NET_ID
const toJson = res => res.json();
const httpPost = async (url, data) => {
- const token = new BlockChain().token;
+ const token = await new BlockChain().token();
let headers = {"Content-Type": "application/json"};
// let token = token;
if (token) {
@@ -23,7 +23,7 @@ const httpPost = async (url, data) => {
const httpGet = async (url, data) => {
- const token = new BlockChain().token;
+ const token = await new BlockChain().token();
let headers = {"Content-Type": "application/json"};
if (token) {
headers['Authorization'] = `Bearer ${token}`;