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

Warn users when using Test Dapp on Mainnet #134

Merged
merged 2 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/alert-red.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ header {
#encryptMessageInput {
margin-bottom: 1rem;
}

.error-div {
margin-bottom: 12px;
}

.error-message {
min-height: 32px;
border: 1px solid #e88f97;
color: #24292e;
background: #fcf2f3;
border-radius: 8px;
display: flex;
justify-content: flex-start;
align-items: center;
padding: 8px 10px;
}
.error-message-icon {
margin-right: 8px;
flex: 0 0 auto;
}
.error-message-text {
overflow: auto;
}

.warning-invisible {
display:none;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
display:none;
display: none;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanml
Resolved - f7844d1

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we add a newline at the end of the file here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanml
Resolved - f7844d1

12 changes: 11 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ <h1 id="logo-text" class="text-center">
<h3 class="card-title">
Status
</h3>

<div id="warning" class="row justify-content-center error-div">
<div class="error-message justify-content-center col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<img
src="alert-red.svg"
alt=""
class="error-message-icon
"
/>
<div class="error-message-text">You are using Test Dapp on Mainnet</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div class="error-message-text">You are using Test Dapp on Mainnet</div>
<div class="error-message-text">You are on the Ethereum Mainnet.</div>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rekmarks
Resolved - f7844d1

</div>
</div>
<div class="row">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<p class="info-text alert alert-primary">
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const { isMetaMaskInstalled } = MetaMaskOnboarding;
const networkDiv = document.getElementById('network');
const chainIdDiv = document.getElementById('chainId');
const accountsDiv = document.getElementById('accounts');
const warningDiv = document.getElementById('warning');

// Basic Actions Section
const onboardButton = document.getElementById('connectButton');
Expand Down Expand Up @@ -1067,6 +1068,12 @@ const initialize = async () => {

function handleNewNetwork(networkId) {
networkDiv.innerHTML = networkId;

if (networkId === '1') {
warningDiv.classList.remove('warning-invisible');
} else {
warningDiv.classList.add('warning-invisible');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to avoid using the networkId as much as possible. We should move this logic to handleNewChain and check against the chainId instead, which will always be 0x1 for Mainnet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rekmarks
Resolved - f7844d1

}

async function getNetworkAndChainId() {
Expand Down