From 41cabfb0aa03b895fb605dff305a3bc2ecda807d Mon Sep 17 00:00:00 2001 From: Mor Sela Date: Sun, 16 Jan 2022 15:35:02 -0800 Subject: [PATCH 1/2] Incorporated Support for wallet_switchEthereumChain --- components/chain/chain.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/components/chain/chain.js b/components/chain/chain.js index 71fdbe40e..012a93fe7 100644 --- a/components/chain/chain.js +++ b/components/chain/chain.js @@ -35,6 +35,7 @@ export default function Chain({ chain }) { return () => { stores.emitter.removeListener(ACCOUNT_CONFIGURED, accountConfigure) } + }, []) const toHex = (num) => { @@ -61,16 +62,21 @@ export default function Chain({ chain }) { window.web3.eth.getAccounts((error, accounts) => { window.ethereum.request({ - method: 'wallet_addEthereumChain', - params: [params, accounts[0]], - }) - .then((result) => { - console.log(result) + method: 'wallet_switchEthereumChain', + params: [{ chainId: params.chainId }], + }).catch((error) => { + window.ethereum.request({ + method: 'wallet_addEthereumChain', + params: [params, accounts[0]], + }) + .then((result) => { + console.log(result) + }) + .catch((error) => { + stores.emitter.emit(ERROR, error.message ? error.message : error) + console.log(error) + }); }) - .catch((error) => { - stores.emitter.emit(ERROR, error.message ? error.message : error) - console.log(error) - }); }) } From 75686455fab4765e0e6b927bf0499913f92acf6b Mon Sep 17 00:00:00 2001 From: Mor Sela Date: Sun, 16 Jan 2022 15:36:33 -0800 Subject: [PATCH 2/2] cleanup --- components/chain/chain.js | 1 - 1 file changed, 1 deletion(-) diff --git a/components/chain/chain.js b/components/chain/chain.js index 012a93fe7..5cfd8cdd6 100644 --- a/components/chain/chain.js +++ b/components/chain/chain.js @@ -35,7 +35,6 @@ export default function Chain({ chain }) { return () => { stores.emitter.removeListener(ACCOUNT_CONFIGURED, accountConfigure) } - }, []) const toHex = (num) => {