Skip to content

Commit

Permalink
improve alert on network mismatch; suggest logout from metamask
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinu Barbu authored and Dinu Barbu committed Dec 7, 2021
1 parent 13a7922 commit f8b869e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function App(props) {
localChainId={localChainId}
selectedChainId={selectedChainId}
targetNetwork={targetNetwork}
logoutOfWeb3Modal={logoutOfWeb3Modal}
/>
<Menu style={{ textAlign: "center" }} selectedKeys={[location.pathname]} mode="horizontal">
<Menu.Item key="/">
Expand Down
12 changes: 11 additions & 1 deletion packages/react-app/src/components/NetworkDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { NETWORK } from "../constants";
import { Alert, Button } from "antd";

function NetworkDisplay({ NETWORKCHECK, localChainId, selectedChainId, targetNetwork }) {
function NetworkDisplay({ NETWORKCHECK, localChainId, selectedChainId, targetNetwork, logoutOfWeb3Modal }) {
let networkDisplay = "";
if (NETWORKCHECK && localChainId && selectedChainId && localChainId !== selectedChainId) {
const networkSelected = NETWORK(selectedChainId);
Expand All @@ -25,11 +25,21 @@ function NetworkDisplay({ NETWORKCHECK, localChainId, selectedChainId, targetNet
</div>
);
} else {
const showLogout = networkSelected && networkSelected.name !== "localhost";
networkDisplay = (
<div style={{ zIndex: 2, position: "absolute", right: 0, top: 60, padding: 16 }}>
<Alert
message="⚠️ Wrong Network"
description={
showLogout
? <div>
You are <b>logged in</b> via Metamask to an external network.
<br/>For local development it is recommended to{" "}
<Button onClick={
logoutOfWeb3Modal
}>logout</Button>
</div>
:
<div>
You have <b>{networkSelected && networkSelected.name}</b> selected and you need to be on{" "}
<Button
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8718,10 +8718,10 @@ eth-gas-reporter@^0.2.20:
sha1 "^1.1.1"
sync-request "^6.0.0"

eth-hooks@2.3.8:
version "2.3.8"
resolved "https://registry.yarnpkg.com/eth-hooks/-/eth-hooks-2.3.8.tgz#419246a1f37efd8822813b0f7298399c16f4bba1"
integrity sha512-MnmW2LDaUWjdQbHoR1wEHAMu6L9vaRse2Ofs6O43Wu27tn6fZuNPAZVlYSC6D4aD9JYxKZXR7Uz/bkCczJO0pQ==
eth-hooks@2.3.14:
version "2.3.14"
resolved "https://registry.yarnpkg.com/eth-hooks/-/eth-hooks-2.3.14.tgz#b1cc495fc36410f67b4b661b5396da4877c50410"
integrity sha512-TXADvpC+IwOYy3hQIoeoi8Pxf1Uodqiuz3MCjI06mJcxXrOx8a72mUmaX/XnX+DiuFGbajnlNkbtYj4dZeDa/g==
dependencies:
"@ethersproject/address" "^5.4.0"
"@ethersproject/bignumber" "^5.4.0"
Expand Down

0 comments on commit f8b869e

Please sign in to comment.