From 6389c426a7a4115e2af4595fd331824f2c892352 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:15:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bug=20fix:=20=E4=B8=8A=E9=93=BE=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/wallet.js | 1 + src/wallet/index.js | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/store/modules/wallet.js b/src/store/modules/wallet.js index 8c2527c..81f4e6d 100644 --- a/src/store/modules/wallet.js +++ b/src/store/modules/wallet.js @@ -34,6 +34,7 @@ const mutations = { updateAddress(state, _address) { console.log('update address: ', _address); state.address = _address; + state.connected = true; }, updateChain(state, _chainId) { console.log('update chain: ', _chainId); diff --git a/src/wallet/index.js b/src/wallet/index.js index bf29852..deb69c4 100644 --- a/src/wallet/index.js +++ b/src/wallet/index.js @@ -78,6 +78,11 @@ export class Wallet { } else if (this.walletName == 'connect') { this.provider = await connectWc(); } + let res = await this.provider.request({ method: 'eth_chainId' }); + if (res) { + this.chainId = parseInt(res); + store.commit('wallet/updateChain', this.chainId) + } this.subscribeToEvents(); } @@ -131,6 +136,10 @@ export class Wallet { async changeChain(){ const chainId = chainData.id + debugger + if (store.state.wallet.chainId === chainId) { + return + } const hexChainId = toHexChainId(chainId) return new Promise((resolve, reject) => { const onChainChange = (chainId) => { @@ -251,7 +260,7 @@ export class Wallet { async sendScription(address, dataStr){ const data = Web3.utils.utf8ToHex(dataStr) - const provider = new Web3(window.ethereum); + const provider = new Web3(this.provider); let gasPrice = await provider.eth.getGasPrice() gasPrice = gasPrice * 2n // const gasPrice = 100000000n; @@ -259,7 +268,7 @@ export class Wallet { // return let sendObj = { from: address, - to: targetAddress, + to: process.env.VUE_APP_SCRIPTION_ADDRESS, value: '0x0', data } From 63aa346c8f496be75d3e2fcc6767cd034a4b23bb Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:16:31 +0800 Subject: [PATCH 2/2] remove debugger --- src/wallet/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/index.js b/src/wallet/index.js index deb69c4..7f8d16d 100644 --- a/src/wallet/index.js +++ b/src/wallet/index.js @@ -136,7 +136,6 @@ export class Wallet { async changeChain(){ const chainId = chainData.id - debugger if (store.state.wallet.chainId === chainId) { return }