market相关功能增加approve

This commit is contained in:
CounterFire2023 2023-06-16 14:19:45 +08:00
parent a1ce68e561
commit 97b7edbe2d

View File

@ -8,6 +8,8 @@ import { abiMarket } from "../abis/abiMarket";
import { abiMall } from "../abis/abiMall";
import { abiGameMarket } from "../abis/abiGameMarket";
import { abiGameMall } from "../abis/abiGameMall";
import { ZError } from "../common/ZError";
import { abiERC20 } from "../abis/abiERC20";
export class JCStandard {
private web3: Web3;
@ -239,9 +241,26 @@ export class JCStandard {
gas = await contract.methods.buy(orderId).estimateGas();
}
gas = (gas * 1.1) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas);
// begin of increase allowance
let orderInfo = await contract.methods.orderInfos(orderId).call();
if (!orderInfo.orderId) {
throw new ZError(100, `order info with id: ${orderId} not found`);
}
const tokenInstance = new this.web3.eth.Contract(
abiERC20,
orderInfo.currency
);
let gasApprove = await tokenInstance.methods
.approve(addressMarket, orderInfo.price)
.estimateGas();
gasApprove = (gasApprove * 1.1) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas + gasApprove);
}
await tokenInstance.methods
.approve(addressMarket, orderInfo.price)
.send({ gas: gasApprove });
let details = [
{
@ -287,9 +306,19 @@ export class JCStandard {
gas = await contract.methods.buyNFT(addresses, values).estimateGas();
}
gas = (gas * 1.1) | 1;
const tokenInstance = new this.web3.eth.Contract(abiERC20, addresses[2]);
let gasApprove = await tokenInstance.methods
.approve(addressMall, values[1])
.estimateGas();
gasApprove = (gasApprove * 1.1) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas);
return jc.wallet.generateGasShow(gas + gasApprove);
}
await tokenInstance.methods
.approve(addressMall, values[1])
.sent({ gas: gasApprove });
let details = [
{
@ -362,8 +391,15 @@ export class JCStandard {
.estimateGas();
}
gas = (gas * 1.1) | 1;
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
let gasApprove = await tokenInstance.methods
.approve(addressGameMarket, price)
.estimateGas();
gasApprove = (gasApprove * 1.1) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas);
return jc.wallet.generateGasShow(gas + gasApprove);
}
let details = [
@ -379,6 +415,9 @@ export class JCStandard {
title: "game_market_buy",
details: details,
};
await tokenInstance.methods
.approve(addressGameMarket, price)
.send({ gas: gasApprove });
return universalChainCb(
logData,
contract.methods
@ -421,8 +460,13 @@ export class JCStandard {
.estimateGas();
}
gas = (gas * 1.1) | 1;
const tokenInstance = new this.web3.eth.Contract(abiERC20, currency);
let gasApprove = await tokenInstance.methods
.approve(addressGameMall, price)
.estimateGas();
gasApprove = (gasApprove * 1.1) | 1;
if (estimate) {
return jc.wallet.generateGasShow(gas);
return jc.wallet.generateGasShow(gas + gasApprove);
}
// TOTO::
let details = [
@ -438,6 +482,9 @@ export class JCStandard {
title: "game_mall_buy",
details: details,
};
await tokenInstance.methods
.approve(addressGameMall, price)
.send({ gas: gasApprove });
return universalChainCb(
logData,
contract.methods