diff --git a/src/custom/components/Header/NetworkSelector/NetworkSelectorMod.tsx b/src/custom/components/Header/NetworkSelector/NetworkSelectorMod.tsx index b7fc43cfa8..ca295e6764 100644 --- a/src/custom/components/Header/NetworkSelector/NetworkSelectorMod.tsx +++ b/src/custom/components/Header/NetworkSelector/NetworkSelectorMod.tsx @@ -30,6 +30,9 @@ import { UnsupportedChainIdError, useWeb3React } from 'web3-react-core' import { useAddPopup, useRemovePopup } from 'state/application/hooks' import { useEffect } from 'react' import { getExplorerBaseUrl } from 'utils/explorer' + +import { useWalletInfo } from 'hooks/useWalletInfo' + import { isMobile } from 'utils/userAgent' /* const ActiveRowLinkList = styled.div` @@ -288,8 +291,9 @@ export const getChainNameFromId = (id: string | number) => { } export default function NetworkSelector() { - // mod: add account + // mod: add account & lib const { account, chainId, library } = useActiveWeb3React() + const { isSmartContractWallet } = useWalletInfo() // mod // mod: refactored inner logic into useChangeNetworks hook const { node, open, toggle, info, handleChainSwitch } = useChangeNetworks({ account, chainId, library }) @@ -391,7 +395,7 @@ export default function NetworkSelector() { } }, [chainId, history, urlChainId, urlChain]) */ - if (!chainId || !info || !library || isUnsupportedNetwork) { + if (!chainId || !info || isUnsupportedNetwork || isSmartContractWallet) { return null } diff --git a/src/custom/components/WalletModal/WalletModalMod.tsx b/src/custom/components/WalletModal/WalletModalMod.tsx index 5e524b6f7f..1806207b0a 100644 --- a/src/custom/components/WalletModal/WalletModalMod.tsx +++ b/src/custom/components/WalletModal/WalletModalMod.tsx @@ -30,8 +30,6 @@ import PendingView from 'components/WalletModal/PendingView' // MOD imports import ModalMod from '@src/components/Modal' -import { SupportedChainId } from 'constants/chains' - export const CloseIcon = styled.div` position: absolute; right: 1rem; @@ -241,7 +239,9 @@ export default function WalletModal({ // Fix for this https://github.com/gnosis/cowswap/issues/1930 if (connector instanceof WalletConnectConnector) { const { http, rpc, signer } = connector.walletConnectProvider - const chainId = signer.connection.chainId || SupportedChainId.MAINNET + const chainId = signer.connection.chainId + // don't default to SupportedChainId.Mainnet - throw instead + if (!chainId) throw new Error('[WalletModal::activation error: No chainId') http.connection.url = rpc.custom[chainId] } }) diff --git a/src/custom/hooks/useWalletInfo.ts b/src/custom/hooks/useWalletInfo.ts index af53d97198..6c01c3bd4a 100644 --- a/src/custom/hooks/useWalletInfo.ts +++ b/src/custom/hooks/useWalletInfo.ts @@ -10,6 +10,7 @@ import { getProviderType, WalletProvider } from 'connectors' import { useActiveWeb3Instance } from 'hooks/index' import { getSafeInfo } from 'api/gnosisSafe' import { SafeInfoResponse } from '@gnosis.pm/safe-service-client' +import useIsArgentWallet from 'hooks/useIsArgentWallet' const GNOSIS_SAFE_APP_NAME = 'Gnosis Safe App' const GNOSIS_SAFE_WALLET_NAMES = ['Gnosis Safe Multisig', 'Gnosis Safe', GNOSIS_SAFE_APP_NAME] @@ -21,6 +22,7 @@ export interface ConnectedWalletInfo { account?: string | null activeNetwork: boolean // active default connection provider?: WalletProvider + library?: Web3Provider isSmartContractWallet: boolean walletName?: string ensName?: string @@ -75,6 +77,7 @@ async function getWcPeerMetadata(connector: WalletConnectConnector): Promise<{ w export function useWalletInfo(): ConnectedWalletInfo { const { active, account, connector, chainId } = useWeb3React() const web3Instance = useActiveWeb3Instance() + const isArgentWallet = useIsArgentWallet() const [walletName, setWalletName] = useState() const [icon, setIcon] = useState() const [provider, setProvider] = useState() @@ -108,12 +111,13 @@ export function useWalletInfo(): ConnectedWalletInfo { break } }, [connector]) - useEffect(() => { - if (account && web3Instance) { + if (account && isArgentWallet) { + setIsSmartContractWallet(true) + } else if (account && web3Instance) { checkIsSmartContractWallet(account, web3Instance).then(setIsSmartContractWallet) } - }, [account, web3Instance]) + }, [account, chainId, isArgentWallet, web3Instance]) useEffect(() => { const isGnosisSafe = walletName && GNOSIS_SAFE_WALLET_NAMES.includes(walletName)