add method for begin buy and cancel order

This commit is contained in:
CounterFire2023 2024-06-25 13:16:42 +08:00
parent 715ec01110
commit 35dd72e093
2 changed files with 42 additions and 6 deletions

View File

@ -33,7 +33,7 @@ export class ImtblMarket {
* 准备一个ERC721的挂单 * 准备一个ERC721的挂单
* @returns * @returns
*/ */
async _prepareERC721Listing({ contractAddress, tokenId, type = 'ERC721', currencyAddress, currencyAmount}){ async _prepareERC721Listing({ contractAddress, tokenId, type = 'ERC721', currencyAddress, currencyAmount, orderExpiry}){
const offerer = await this.signer.getAddress(); const offerer = await this.signer.getAddress();
const buyData = { const buyData = {
amount: currencyAmount, amount: currencyAmount,
@ -52,6 +52,7 @@ export class ImtblMarket {
tokenId, tokenId,
type, type,
}, },
orderExpiry
}); });
let orderSignature = '' let orderSignature = ''
@ -112,9 +113,9 @@ export class ImtblMarket {
* @param {string} currencyAddress NATIVE 或者 ERC20的合约地址 * @param {string} currencyAddress NATIVE 或者 ERC20的合约地址
* @param {string} currencyAmount 出售价格, 单位 wei * @param {string} currencyAmount 出售价格, 单位 wei
*/ */
async beginSellERC721({contractAddress, tokenId, currencyAddress, currencyAmount}) { async beginSellERC721({contractAddress, tokenId, currencyAddress, currencyAmount, orderExpiry}) {
const { preparedListing, orderSignature } = const { preparedListing, orderSignature } =
await this._prepareERC721Listing({contractAddress, tokenId, currencyAddress, currencyAmount}); await this._prepareERC721Listing({contractAddress, tokenId, currencyAddress, currencyAmount, orderExpiry});
const order = await this._createListing(preparedListing, orderSignature, currencyAmount); const order = await this._createListing(preparedListing, orderSignature, currencyAmount);
return order return order
} }

View File

@ -5,7 +5,7 @@
<div class="content"> <div class="content">
<div class="top-left"> <div class="top-left">
<div class="top-left-img"> <div class="top-left-img">
<img src="@/assets/img/marketplace/GenesisHeroes_NFT.png" alt=""> <img :src="detailData.image" alt="">
</div> </div>
</div> </div>
<div class="top-right"> <div class="top-right">
@ -58,8 +58,8 @@
3使用 3使用
--> -->
<div v-else> <div v-else>
<div class="sell" v-if="!detailData.event">上架</div> <div class="sell" @click="beginSell" v-if="!detailData.event">上架</div>
<div class="cancel" v-if="detailData.event">下架</div> <div class="cancel" @click="cancelSell" v-if="detailData.event">下架</div>
<div class="redeem" @click="lockToGame">使用</div> <div class="redeem" @click="lockToGame">使用</div>
</div> </div>
</div> </div>
@ -173,6 +173,41 @@ const lockToGame = async() => {
} }
const beginSell = async() => {
if (detailData.event) return
try {
//TODO::
const sellData = {
contractAddress: detailData.contract_address,
tokenId: detailData.token_id,
currencyAddress: import.meta.env.VUE_APP_MARKET_CURRENCY,
currencyAmount: '1000000000000000000',
orderExpiry: null
}
await new BlockChain().market.beginSellERC721(sellData)
console.log('beginSell success')
} catch (e) {
console.log('beginSell fail', e.message)
}
}
const cancelSell = async() => {
if (!detailData.event) return
try {
await new BlockChain().market.cancelOrder([detailData.event.data.id])
console.log('cancelSell success')
} catch (e) {
try {
await new BlockChain().market.cancelOrdersOnChain([detailData.event.data.id])
console.log('cancelSell success')
} catch (e2) {
console.log('cancelSell fail', e.message)
}
console.log('cancelSell fail', e.message)
}
}
// //
const sliceAddress = (address) => { const sliceAddress = (address) => {
if (!address) return "-"; if (!address) return "-";