From 34c142972f236a6fc8bbb18456da888c6b94bb34 Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 17 Jan 2022 13:57:50 +0100 Subject: [PATCH 1/2] feat: allow wallet-link on avalanche --- package-lock.json | 82 ++++++------------- package.json | 2 +- src/components/ConnectWalletModal/index.tsx | 4 +- .../NetworkMismatch/index.tsx | 18 ++-- 4 files changed, 36 insertions(+), 70 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2d94b6de..14df87e8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "@web3-react/injected-connector": "^6.0.7", "@web3-react/portis-connector": "^6.1.9", "@web3-react/torus-connector": "^6.1.9", - "@web3-react/walletlink-connector": "^6.2.3", + "@web3-react/walletlink-connector": "^6.2.8", "classnames": "^2.3.1", "d3-array": "^3.1.1", "dayjs": "^1.10.7", @@ -10173,13 +10173,13 @@ "integrity": "sha512-ofGmfDhxmNT1/P/MgVa8IKSkCStFiyvXe+U5tyZurKdrtTDFU+wJ/LxClPDtFerWpczNFPUSrKcuhfPX1sI6+A==" }, "node_modules/@web3-react/walletlink-connector": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/@web3-react/walletlink-connector/-/walletlink-connector-6.2.3.tgz", - "integrity": "sha512-vJsXyC2NWpVrlnfgwsssDuFo3P/xCoKOjvkEjbQyQEig2aucPijwuxc58BG/YzDx4FyeeyzpnkDMLfcXFuI1pg==", + "version": "6.2.8", + "resolved": "https://registry.npmjs.org/@web3-react/walletlink-connector/-/walletlink-connector-6.2.8.tgz", + "integrity": "sha512-pSGufPz5JntSUvy88XcOrn5VN3qmX+ZVQ2lXAeWWb7YS2wTlAStPghZbln8t1li7jr1NUJ0w/gMDVpAwjwq4ZA==", "dependencies": { "@web3-react/abstract-connector": "^6.0.7", "@web3-react/types": "^6.0.7", - "walletlink": "^2.1.6" + "walletlink": "^2.2.6" } }, "node_modules/@webassemblyjs/ast": { @@ -51685,14 +51685,13 @@ } }, "node_modules/walletlink": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/walletlink/-/walletlink-2.1.8.tgz", - "integrity": "sha512-rIjQ0EE1tywiaaSwVF/RGChuYM9v6DQjoBwP4kPYWAxRCtBiOBlorVma/6pM0IOiybZEJvAVLtq1wJ78V7HBxw==", + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/walletlink/-/walletlink-2.4.3.tgz", + "integrity": "sha512-IGZZPhzuDStQtX3bKvVfD2AKb1HoSVBKwuU528+9S5JdzBGb1ZPEAXHh9yzHtamgqyHOpiGSrkop/rZ7NM52SQ==", "dependencies": { "@metamask/safe-event-emitter": "2.0.0", "bind-decorator": "^1.0.11", "bn.js": "^5.1.1", - "buffer": "^6.0.3", "clsx": "^1.1.0", "eth-block-tracker": "4.4.3", "eth-json-rpc-filters": "4.2.2", @@ -51702,8 +51701,7 @@ "keccak": "^3.0.1", "preact": "^10.5.9", "rxjs": "^6.6.3", - "stream-browserify": "^3.0.0", - "util": "^0.12.4" + "stream-browserify": "^3.0.0" }, "engines": { "node": ">= 10.0.0" @@ -51714,29 +51712,6 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz", "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw==" }, - "node_modules/walletlink/node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "node_modules/walletlink/node_modules/eth-block-tracker": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/eth-block-tracker/-/eth-block-tracker-4.4.3.tgz", @@ -51779,9 +51754,9 @@ } }, "node_modules/walletlink/node_modules/preact": { - "version": "10.5.14", - "resolved": "https://registry.npmjs.org/preact/-/preact-10.5.14.tgz", - "integrity": "sha512-KojoltCrshZ099ksUZ2OQKfbH66uquFoxHSbnwKbTJHeQNvx42EmC7wQVWNuDt6vC5s3nudRHFtKbpY4ijKlaQ==", + "version": "10.6.4", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.6.4.tgz", + "integrity": "sha512-WyosM7pxGcndU8hY0OQlLd54tOU+qmG45QXj2dAYrL11HoyU/EzOSTlpJsirbBr1QW7lICxSsVJJmcmUglovHQ==", "funding": { "type": "opencollective", "url": "https://opencollective.com/preact" @@ -62557,13 +62532,13 @@ "integrity": "sha512-ofGmfDhxmNT1/P/MgVa8IKSkCStFiyvXe+U5tyZurKdrtTDFU+wJ/LxClPDtFerWpczNFPUSrKcuhfPX1sI6+A==" }, "@web3-react/walletlink-connector": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/@web3-react/walletlink-connector/-/walletlink-connector-6.2.3.tgz", - "integrity": "sha512-vJsXyC2NWpVrlnfgwsssDuFo3P/xCoKOjvkEjbQyQEig2aucPijwuxc58BG/YzDx4FyeeyzpnkDMLfcXFuI1pg==", + "version": "6.2.8", + "resolved": "https://registry.npmjs.org/@web3-react/walletlink-connector/-/walletlink-connector-6.2.8.tgz", + "integrity": "sha512-pSGufPz5JntSUvy88XcOrn5VN3qmX+ZVQ2lXAeWWb7YS2wTlAStPghZbln8t1li7jr1NUJ0w/gMDVpAwjwq4ZA==", "requires": { "@web3-react/abstract-connector": "^6.0.7", "@web3-react/types": "^6.0.7", - "walletlink": "^2.1.6" + "walletlink": "^2.2.6" } }, "@webassemblyjs/ast": { @@ -95318,14 +95293,13 @@ } }, "walletlink": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/walletlink/-/walletlink-2.1.8.tgz", - "integrity": "sha512-rIjQ0EE1tywiaaSwVF/RGChuYM9v6DQjoBwP4kPYWAxRCtBiOBlorVma/6pM0IOiybZEJvAVLtq1wJ78V7HBxw==", + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/walletlink/-/walletlink-2.4.3.tgz", + "integrity": "sha512-IGZZPhzuDStQtX3bKvVfD2AKb1HoSVBKwuU528+9S5JdzBGb1ZPEAXHh9yzHtamgqyHOpiGSrkop/rZ7NM52SQ==", "requires": { "@metamask/safe-event-emitter": "2.0.0", "bind-decorator": "^1.0.11", "bn.js": "^5.1.1", - "buffer": "^6.0.3", "clsx": "^1.1.0", "eth-block-tracker": "4.4.3", "eth-json-rpc-filters": "4.2.2", @@ -95335,8 +95309,7 @@ "keccak": "^3.0.1", "preact": "^10.5.9", "rxjs": "^6.6.3", - "stream-browserify": "^3.0.0", - "util": "^0.12.4" + "stream-browserify": "^3.0.0" }, "dependencies": { "bn.js": { @@ -95344,15 +95317,6 @@ "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.0.tgz", "integrity": "sha512-D7iWRBvnZE8ecXiLj/9wbxH7Tk79fAh8IHaTNq1RWRixsS02W+5qS+iE9yq6RYl0asXx5tw0bLhmT5pIfbSquw==" }, - "buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "eth-block-tracker": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/eth-block-tracker/-/eth-block-tracker-4.4.3.tgz", @@ -95389,9 +95353,9 @@ "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=" }, "preact": { - "version": "10.5.14", - "resolved": "https://registry.npmjs.org/preact/-/preact-10.5.14.tgz", - "integrity": "sha512-KojoltCrshZ099ksUZ2OQKfbH66uquFoxHSbnwKbTJHeQNvx42EmC7wQVWNuDt6vC5s3nudRHFtKbpY4ijKlaQ==" + "version": "10.6.4", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.6.4.tgz", + "integrity": "sha512-WyosM7pxGcndU8hY0OQlLd54tOU+qmG45QXj2dAYrL11HoyU/EzOSTlpJsirbBr1QW7lICxSsVJJmcmUglovHQ==" } } }, diff --git a/package.json b/package.json index bc4bc7efc..38a888564 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@web3-react/injected-connector": "^6.0.7", "@web3-react/portis-connector": "^6.1.9", "@web3-react/torus-connector": "^6.1.9", - "@web3-react/walletlink-connector": "^6.2.3", + "@web3-react/walletlink-connector": "^6.2.8", "classnames": "^2.3.1", "d3-array": "^3.1.1", "dayjs": "^1.10.7", diff --git a/src/components/ConnectWalletModal/index.tsx b/src/components/ConnectWalletModal/index.tsx index 25c35bf23..778c55e6c 100644 --- a/src/components/ConnectWalletModal/index.tsx +++ b/src/components/ConnectWalletModal/index.tsx @@ -95,7 +95,9 @@ export default function ConnectWalletModal({ title: 'Coinbase', providerName: 'wallet-link', icon: icons.coinbaseIcon, - notSupported: preferredChainId === ChainId.avalanche, + notSupported: ![ChainId.mainnet, ChainId.polygon, ChainId.avalanche].includes( + preferredChainId + ), }, { title: 'Authereum', diff --git a/src/components/TxConfirmationView/NetworkMismatch/index.tsx b/src/components/TxConfirmationView/NetworkMismatch/index.tsx index 4351c7c82..d48d15c3f 100644 --- a/src/components/TxConfirmationView/NetworkMismatch/index.tsx +++ b/src/components/TxConfirmationView/NetworkMismatch/index.tsx @@ -76,8 +76,10 @@ export default function NetworkMismatch({ const { handleNetworkChange } = useUserWalletDataContext(); const config = ADD_CONFIG[neededChainId]; - const isAddableByMetamask = - (global.window as any)?.ethereum?.isMetaMask && currentProviderName === 'browser' && config; + const isAddable = + (global.window as any)?.ethereum?.isMetaMask && + ['browser'].includes(currentProviderName) && + config; const { publicJsonRPCWSUrl, publicJsonRPCUrl } = getNetworkConfig(neededChainId); // const isExternalNetworkUpdateNeeded = @@ -94,7 +96,7 @@ export default function NetworkMismatch({

@@ -116,13 +118,11 @@ export default function NetworkMismatch({ }) : intl.formatMessage(messages.description, { networkName: currentNetworkConfig.name, - additional: !isAddableByMetamask - ? intl.formatMessage(messages.additionalDescription) - : '', + additional: !isAddable ? intl.formatMessage(messages.additionalDescription) : '', })}

- {isAddableByMetamask && config && ( + {isAddable && config && ( { @@ -151,10 +151,10 @@ export default function NetworkMismatch({

- {!isAddableByMetamask && ( + {!isAddable && (
- {isAddableByMetamask && ( + {isAddable && (
{intl.formatMessage(messages.howToChange)}{' '} Date: Mon, 17 Jan 2022 16:33:17 +0100 Subject: [PATCH 2/2] fix: add 3326 support --- .../NetworkMismatch/index.tsx | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/components/TxConfirmationView/NetworkMismatch/index.tsx b/src/components/TxConfirmationView/NetworkMismatch/index.tsx index d48d15c3f..3c6a39b6e 100644 --- a/src/components/TxConfirmationView/NetworkMismatch/index.tsx +++ b/src/components/TxConfirmationView/NetworkMismatch/index.tsx @@ -125,19 +125,32 @@ export default function NetworkMismatch({ {isAddable && config && ( { - (window as any).ethereum?.request({ - method: 'wallet_addEthereumChain', - params: [ - { - chainId: `0x${neededChainId.toString(16)}`, - chainName: config.name, - nativeCurrency: config.nativeCurrency, - rpcUrls: [...publicJsonRPCUrl, publicJsonRPCWSUrl], - blockExplorerUrls: config.explorerUrls, - }, - ], - }); + onClick={async () => { + try { + await (window as any).ethereum?.request({ + method: 'wallet_switchEthereumChain', + params: [{ chainId: `0x${neededChainId.toString(16)}` }], + }); + } catch (switchError) { + if (switchError.code === 4902) { + try { + await (window as any).ethereum?.request({ + method: 'wallet_addEthereumChain', + params: [ + { + chainId: `0x${neededChainId.toString(16)}`, + chainName: config.name, + nativeCurrency: config.nativeCurrency, + rpcUrls: [...publicJsonRPCUrl, publicJsonRPCWSUrl], + blockExplorerUrls: config.explorerUrls, + }, + ], + }); + } catch (addError) { + // TODO: handle error somehow + } + } + } }} /> )}