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,