修改钱包逻辑

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,7 @@ const httpGet = async (url, data) => {
// 获取市场所有 // 获取市场所有
export const apiMarketplaceState = async (data) => { export const apiMarketplaceState = async (data) => {
const url = `${API_BASE}/api/market/product/list/${net_id}`; 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) => { export const apiAddCartList = async (data) => {
const url = `/api/shopcart/add` 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" import { useDetailStore } from "@/store/detail"
const detailData = useDetailStore() const detailData = useDetailStore()
console.log(toRaw(detailData.nftData)) console.log(toRaw(detailData.nftData))
import { PassportWallet } from "@/wallet/passPort" import { BlockChain } from "@/components/chain/BlockChain"
// const nftData = ref() // const nftData = ref()
const myAddress = localStorage.getItem("assessAddress") const myAddress = localStorage.getItem("assessAddress")
const nftAbilities = ref(detailData.nftData.nft.detail) const nftAbilities = ref(detailData.nftData.nft.detail)
@ -177,7 +177,7 @@ const buyNow = async () => {
tokenIds.push(detailData.nftData.nft.token_id) tokenIds.push(detailData.nftData.nft.token_id)
console.log(tokenIds) console.log(tokenIds)
console.log(await new PassportWallet().batchBuy(tokenIds)) console.log(await new BlockChain().market.batchBuy(tokenIds))
return return
try { try {
let res = await batchBuy(tokenIds) let res = await batchBuy(tokenIds)