Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[414] remove NetworkSelector on sc wallet session #507

Merged
merged 12 commits into from
May 5, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 })

Expand Down Expand Up @@ -391,7 +395,7 @@ export default function NetworkSelector() {
}
}, [chainId, history, urlChainId, urlChain]) */

if (!chainId || !info || !library || isUnsupportedNetwork) {
if (!chainId || !info || isUnsupportedNetwork || isSmartContractWallet) {
return null
}

Expand Down
6 changes: 3 additions & 3 deletions src/custom/components/WalletModal/WalletModalMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
}
})
Expand Down
10 changes: 7 additions & 3 deletions src/custom/hooks/useWalletInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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<string>()
const [icon, setIcon] = useState<string>()
const [provider, setProvider] = useState<WalletProvider>()
Expand Down Expand Up @@ -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)
Expand Down