Skip to content

Commit

Permalink
(fix) Invalid network error (#154)
Browse files Browse the repository at this point in the history
* fix invalid netwrok error

* (remove) console statement

Co-authored-by: Gabriel Rodriguez Alsina <gabriel.rodriguez@altoros.com>
  • Loading branch information
0xslipk and gabitoesmiapodo authored Mar 10, 2021
1 parent 1ef295a commit 80b5159
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/layout/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useENSName from '../../../hooks/useENSName'
import { useWalletModalToggle } from '../../../state/application/hooks'
import { useAllTransactions } from '../../../state/transactions/hooks'
import { TransactionDetails } from '../../../state/transactions/reducer'
import { useNetworkCheck } from '../../Web3Status'
import { ButtonConnect } from '../../buttons/ButtonConnect'
import { ButtonMenu } from '../../buttons/ButtonMenu'
import { Logo } from '../../common/Logo'
Expand Down Expand Up @@ -118,9 +119,11 @@ const Error = styled.span`

export const Header: React.FC = (props) => {
const { account, error } = useWeb3React()
const { errorWrongNetwork } = useNetworkCheck()
const isConnected = !!account
const [mobileMenuVisible, setMobileMenuVisible] = useState(false)
const wrongNetwork = error instanceof UnsupportedChainIdError
const wrongNetwork = error instanceof UnsupportedChainIdError || errorWrongNetwork !== undefined

const toggleWalletModal = useWalletModalToggle()
const allTransactions = useAllTransactions()
const ENSName = useENSName(account)
Expand All @@ -145,6 +148,16 @@ export const Header: React.FC = (props) => {
setMobileMenuVisible(!mobileMenuVisible)
}

let web3Status = <ButtonConnectStyled onClick={toggleWalletModal} />

if (isConnected) {
web3Status = <UserDropdownStyled />
}

if (wrongNetwork) {
web3Status = <Error>Invalid network</Error>
}

return (
<>
<Wrapper className="siteHeader" {...props}>
Expand All @@ -155,13 +168,7 @@ export const Header: React.FC = (props) => {
<Logo />
</LogoLink>
<Menu />
{isConnected ? (
<UserDropdownStyled />
) : wrongNetwork ? (
<Error>Invalid network</Error>
) : (
<ButtonConnectStyled onClick={toggleWalletModal} />
)}
{web3Status}
</Inner>
</Wrapper>
<WalletModal
Expand Down

0 comments on commit 80b5159

Please sign in to comment.