Merge branch 'new-CounterFire' of http://git.kingsome.cn/huangjinming/CounterFireGames into new-CounterFire
This commit is contained in:
commit
53490821b3
@ -19,7 +19,7 @@
|
||||
<div class="cart-item-right-price">
|
||||
<div>{{ priceCalculated(item.event.data.buy[0].amount) }}</div>
|
||||
<div class="cart-item-right-price-img">
|
||||
<img src="@/assets/img/marketplace/ETHicon.png" alt="">
|
||||
<img :src="item.icon" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="cart-item-right-clear" @click="deleteNft(item)">
|
||||
@ -33,14 +33,17 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="cart-total-price">
|
||||
<div class="top">
|
||||
<div class="left">Total Price</div>
|
||||
<div class="right">{{ completePrice(cartList) }} <img src="@/assets/img/marketplace/ETHicon.png" alt=""></div>
|
||||
<template v-for="(item, index) in priceList" :key="index">
|
||||
<div :class="{'top': index == 0, 'bottom': index > 0}">
|
||||
<div class="left" v-if="index == 0">Total Price</div>
|
||||
<div class="left" v-if="index > 0"></div>
|
||||
<div class="right">{{ priceCalculated(item.amount) }} <img :src="item.icon" alt=""></div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="bottom">
|
||||
<div class="left"></div>
|
||||
<div class="right">
|
||||
<div>≈ {{ 200 }}$</div>
|
||||
<div v-if="priceList.length > 0">≈ {{ usdTotal }}$</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -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
|
||||
|
@ -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() {
|
||||
|
@ -233,6 +233,7 @@ export class ImtblMarket {
|
||||
|
||||
async updateCurrencyPrice() {
|
||||
const ids = ['immutable-x', 'ethereum', 'usd-coin']
|
||||
try {
|
||||
let priceList = await queryTokenPriceCg(ids);
|
||||
priceList = priceList.map((item) => {
|
||||
return {
|
||||
@ -242,5 +243,9 @@ export class ImtblMarket {
|
||||
})
|
||||
this.marketStore.currencyPrice = priceList;
|
||||
return priceList;
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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)}
|
||||
}
|
@ -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 }
|
||||
}
|
||||
|
||||
|
@ -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}`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user