修改钱包逻辑

This commit is contained in:
CounterFire2023 2024-06-24 20:21:51 +08:00
parent da75ada612
commit 0aff913c1a
7 changed files with 26 additions and 32 deletions

View File

@ -50,7 +50,7 @@
<script setup>
import { ref, toRaw, defineEmits } from "vue";
import {priceCalculated} from "@/configs/priceCalculate.js"
import {PassportWallet} from "@/wallet/passPort.js"
import { BlockChain } from "@/components/chain/BlockChain"
// const passProd = ref(new PassportWallet())
const props = defineProps({
buyDialogVisible: {
@ -71,13 +71,12 @@ const handleOk = (e) => {
const buyConfirm = async () => {
const pass = new PassportWallet()
const bc = new BlockChain()
const lists = toRaw(props.buyDataArr)
const ids = lists.map(item => item.event.data.id)
try {
await pass.batchBuy(ids)
await bc.market.batchBuy(ids)
console.log('buy success ')
} catch (err) {
console.log('buy fail', err.message)

View File

@ -14,7 +14,7 @@
</template>
<script setup>
import { ref, toRaw, defineEmits } from "vue";
import {PassportWallet} from "@/wallet/passPort.js"
import { BlockChain } from "@/components/chain/BlockChain"
// const passProd = ref(new PassportWallet())
const props = defineProps({
loadingDialogVisible: {
@ -35,13 +35,12 @@ emit('handleClose')
const buyConfirm = async () => {
const pass = new PassportWallet()
const bc = new BlockChain()
let ids = []
ids.push(toRaw(props.buyDataArr)[0].nft.token_id)
// console.log(ids)
// return
let res = await pass.beginBuy(toRaw(props.buyDataArr)[0].nft.token_id)
let res = await bc.market.beginBuy(toRaw(props.buyDataArr)[0].nft.token_id)
console.log('购买', res)
}

View File

@ -31,13 +31,13 @@
<script setup>
import { ref, toRaw, onMounted, getCurrentInstance } from "vue"
// import BuyDialog from "@/components/Dialogs/buyDialog.vue"
import {PassportWallet} from "@/wallet/passPort.js"
import { useDetailStore } from "@/store/detail"
import {
apiAddCartList
} from "@/utils/marketplace"
const detailData = useDetailStore()
import { useRouter } from "vue-router";
import { BlockChain } from "@/components/chain/BlockChain"
const router = useRouter();
const { proxy } = getCurrentInstance();
const props = defineProps({
@ -61,8 +61,8 @@ const sellNft = async (val) => {
}
// buyDataArr.value.push(val)
// buyDialogVisible.value = true
const pass = new PassportWallet()
let res = await pass.beginSellERC721(data)
const bc = new BlockChain()
let res = await bc.market.beginSellERC721(data)
console.log('售NFT', res)
}

View File

@ -21,8 +21,9 @@ export class BlockChain {
this.store = walletStore();
this.store.$hydrate({runHooks: false});
this.initWallet();
BlockChain.instance = this;
this.market = new ImtblMarket()
BlockChain.instance = this;
}
initWallet() {
@ -51,10 +52,14 @@ export class BlockChain {
async connect() {
// if this only one provider configed, use it directly
if (ALL_PROVIDERS.length === 1) {
this.wallet = new allProviders[ALL_PROVIDERS[0].id]();
const { provider } = await this.wallet.web3Provider();
const walletType = ALL_PROVIDERS[0].id
this.wallet = new allProviders[walletType]();
const { provider, accounts } = await this.wallet.web3Provider();
this.provider = provider
this.market.updateProvider(provider);
this.store.walletType = walletType;
this.store.address = accounts[0];
this.store.$persist();
return
}
const rewardModal = createModal(WalletSelectModel, {});

View File

@ -68,18 +68,13 @@ import { hasMetamask } from "@/utils/chain.util";
import { useRouter, useRoute } from "vue-router";
import ChainModel from "@/components/home/ChainModel.vue";
import { useCopyToClipboard } from "./../../hooks/useCopyToClipboard";
import { PassportWallet } from "@/wallet/passPort"
import { useImmutableStore } from "@/store/immutable"
import { useMarketplaceStore } from "@/store/marketplace"
import WalletSelectModel from "@/components/chain/WalletSelectModel.vue"
import { createModal } from "@/utils/model.util"
import Cart from "@/components/cart/index.vue"
import { BlockChain } from "../chain/BlockChain";
import { BlockChain } from "@/components/chain/BlockChain"
import {walletStore} from "@/store/wallet";
const localWalletStore = walletStore()
const immutableStore = useImmutableStore()
const marketplaceStore = useMarketplaceStore()
const AppModule = useAppStore();
const router = useRouter();
@ -233,10 +228,6 @@ watchEffect(() => {
// --------------------------------
const immuTableLogin = async () => {
// let rewardModal = createModal(WalletSelectModel, {})
// let result = await rewardModal.show()
// console.log(`select result : ${result.errcode}`)
await new BlockChain().connect()
// try{
// const walletLogin = await new PassportWallet().connect()
@ -278,7 +269,7 @@ const immuTableLogout = async () => {
//
const myCart = async () => {
if(immutableStore.accessToken) {
if(localWalletStore.address) {
cartShow.value = true
} else {
immuTableLogin()
@ -294,9 +285,9 @@ watch(() => route.path,(newPath, oldPath) => {
})
onMounted( async () => {
if( immutableStore.accessToken) {
await new PassportWallet().connect()
}
// if( immutableStore.accessToken) {
// await new PassportWallet().connect()
// }
})
</script>

View File

@ -39,7 +39,7 @@ const httpGet = async (url, data) => {
// 获取市场所有
export const apiMarketplaceState = async (data) => {
const url = `${API_BASE}/api/market/product/list/${net_id}`;
return httpPost(url, {data})
return httpPost(url, data)
}
// 获取我拥有得资产
@ -75,7 +75,7 @@ export const apiGetCartList = async () => {
// 添加购物车
export const apiAddCartList = async (data) => {
const url = `/api/shopcart/add`
return httpPost(url, {data})
return httpPost(url, data)
}
// 删除购物车

View File

@ -144,7 +144,7 @@ import { apiDetail } from "@/utils/marketplace"
import { useDetailStore } from "@/store/detail"
const detailData = useDetailStore()
console.log(toRaw(detailData.nftData))
import { PassportWallet } from "@/wallet/passPort"
import { BlockChain } from "@/components/chain/BlockChain"
// const nftData = ref()
const myAddress = localStorage.getItem("assessAddress")
const nftAbilities = ref(detailData.nftData.nft.detail)
@ -177,7 +177,7 @@ const buyNow = async () => {
tokenIds.push(detailData.nftData.nft.token_id)
console.log(tokenIds)
console.log(await new PassportWallet().batchBuy(tokenIds))
console.log(await new BlockChain().market.batchBuy(tokenIds))
return
try {
let res = await batchBuy(tokenIds)