From c5bd0a20df4eb57dccf65a55c2a920f591663349 Mon Sep 17 00:00:00 2001 From: cebgcontract <99630598+cebgcontract@users.noreply.github.com> Date: Wed, 2 Nov 2022 19:58:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8E=E9=93=BE=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E6=96=B9=E6=B3=95=E5=A2=9E=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/allchain.ts | 4 +- src/index.ts | 21 ++++++++++- src/standards/JCStandard.ts | 73 ++++++++++++++++++++++++++++++++++--- 3 files changed, 88 insertions(+), 10 deletions(-) diff --git a/src/data/allchain.ts b/src/data/allchain.ts index e271f61..b524ac7 100644 --- a/src/data/allchain.ts +++ b/src/data/allchain.ts @@ -274,8 +274,8 @@ export const AllChains = [ { name: "Local Testnet", type: "Local", - rpc: "http://192.168.100.22:8545", - id: 1337, + rpc: "https://login-test.kingsome.cn/rpc", + id: 1338, symbol: "ETH", explorerurl: "https://explorer.harmony.one", }, diff --git a/src/index.ts b/src/index.ts index 8a85255..447bc6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -102,10 +102,14 @@ export default class JCWallet { if (this.walletType === WalletType.INTERNAL) { this.prepareInternalWallet(); } - this.init({ chains: [80001], password: this.password }); + this.init({ chains: [chain], password: this.password }); window.jc = { wallet: this }; } + public get isInternal() { + return this.walletType === WalletType.INTERNAL; + } + private prepareInternalWallet() { let token = loadToken(); if (!token) { @@ -167,7 +171,20 @@ export default class JCWallet { this.erc721Standard = new ERC721Standard(this.web3); this.erc1155Standard = new ERC1155Standard(this.web3); this.jcStandard = new JCStandard(this.web3); - resolve && resolve(""); + return this.web3.eth.getChainId(); + }) + .then((chainId: number) => { + if (chainId === this._currentChain.id) { + resolve && resolve(""); + } else { + this.updateCurrentChain(this.currentChain.id) + .then(() => { + resolve && resolve(""); + }) + .catch((err) => { + reject && reject("error change network"); + }); + } }) .catch((err: Error) => { console.log("initThirdPartyWallet error: " + err); diff --git a/src/standards/JCStandard.ts b/src/standards/JCStandard.ts index 0d5caeb..51b0198 100644 --- a/src/standards/JCStandard.ts +++ b/src/standards/JCStandard.ts @@ -21,11 +21,21 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall; - const contract = new this.web3.eth.Contract(abiNftMall, address); + const contract = new this.web3.eth.Contract(abiNftMall, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); //TODO:: increaseAllowance before call let gas = await contract.methods .buy721NFT(addresses, values, signature) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } return contract.methods .buy721NFT(addresses, values, signature) .send({ gas: (gas * 1.1) | 0 }); @@ -45,10 +55,20 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].nftMall; - const contract = new this.web3.eth.Contract(abiNftMall, address); + const contract = new this.web3.eth.Contract(abiNftMall, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); let gas = await contract.methods .buy1155NFT(addresses, values, ids, amounts, signature) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } return contract.methods .buy1155NFT(addresses, values, ids, amounts, signature) .send({ gas: (gas * 1.1) | 0 }); @@ -68,10 +88,20 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory; - const contract = new this.web3.eth.Contract(abiEvolveFactory, address); + const contract = new this.web3.eth.Contract(abiEvolveFactory, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); let gas = await contract.methods .evolve721NFT(nftAddress, tokenIds, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } return contract.methods .evolve721NFT(nftAddress, tokenIds, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); @@ -89,10 +119,20 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].evolveFactory; - const contract = new this.web3.eth.Contract(abiEvolveFactory, address); + const contract = new this.web3.eth.Contract(abiEvolveFactory, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); let gas = await contract.methods .evolveChip(tokenIds, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } return contract.methods .evolveChip(tokenIds, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); @@ -112,10 +152,20 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory; - const contract = new this.web3.eth.Contract(abiMinterFactory, address); + const contract = new this.web3.eth.Contract(abiMinterFactory, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); let gas = await contract.methods .mintShardBatchUser(tokenIds, amounts, startTime, nonce, signature) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } return contract.methods .mintShardBatchUser(tokenIds, amounts, startTime, nonce, signature) .send({ gas: (gas * 1.1) | 0 }); @@ -143,7 +193,10 @@ export class JCStandard { signature: string; }) { let address = JC_CONTRACTS[window.jc.wallet.currentChain.id].minterFactory; - const contract = new this.web3.eth.Contract(abiMinterFactory, address); + const contract = new this.web3.eth.Contract(abiMinterFactory, address, { + //@ts-ignore + from: jc.wallet.currentAccount(), + }); let gas = await contract.methods .shardMixByUser( tokenId, @@ -157,6 +210,14 @@ export class JCStandard { signature ) .estimateGas({ gas: 1000000 }); + //@ts-ignore + if (!jc.wallet.isInternal) { + setTimeout(() => { + // @ts-ignore + jumpToWallet(); + }, 1500); + } + return contract.methods .shardMixByUser( tokenId,