-
Notifications
You must be signed in to change notification settings - Fork 235
Network-aware LoadingContainer #9
base: develop
Are you sure you want to change the base?
Network-aware LoadingContainer #9
Conversation
@SeanJCasey, when you have time, please update the README and the test-apps to reflect/document this feature. I am excited to try this out! Thanks! |
32eeeef
to
31fe5d9
Compare
Update the test app for the react context api with a |
31fe5d9
to
d23391a
Compare
@SeanJCasey I'm having trouble running this on the test-UI apps. I have:
I'm getting the following error on both React apps (legacy context AND new context) instead of the nice warning message: |
@adrianmcli Did you set |
@SeanJCasey Can you add that to the test-UI app then? |
@adrianmcli Sure, I can add a |
@SeanJCasey I think the goal is to make sure that the repo's test apps are actually able to test the features in our packages. Do you have any thoughts on what the defaults should be? |
@adrianmcli How about |
Actually I'm confused. Why is a network whitelist needed? I thought the purpose of this PR is to make it such that the dapp will try to detect the contract on the current network, and if it isn't there then it'll show a friendly message in the UI. |
The purpose of this PR is to allow the LoadingContainer to work with the Good question re: explicitly defining a |
Right, but if it doesn't support it, it should display a message instead of throwing an error in the console right? |
Yes, but the idea was to separate out functionality and UI/UX. Rather than assuming UI/UX, we just provide a developer with the |
@SeanJCasey Ok sounds good. So let's just put in the |
d23391a
to
b80d82b
Compare
b80d82b
to
eb260a8
Compare
@adrianmcli I added the |
Thanks @SeanJCasey, I'm on vacation until Tuesday unfortunately but let's get this merged asap. |
Just adding a note that this resolves #23 |
Seems to work as expected! Thanks @SeanJCasey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some questions regarding the code and refactor requests.
return this.props.networkMismatchComp; | ||
} | ||
|
||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section can be re-written as:
return this.props.networkMismatchComp || <main>...</main>
This allows us to avoid the nested if statement and also makes it clear that this.props.networkMismatchComp
is a component.
import React, { Children, Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this comment block?
* Create component. | ||
*/ | ||
|
||
class LoadingContainer extends Component { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component has a ton of if-statements, consider refactoring.
render() { | ||
if (this.props.drizzleState) { | ||
if (this.props.drizzleState.web3.status === "failed") { | ||
if (this.props.errorComp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, this can be written as:
return this.props.errorComp || <main>...</main>
In order to avoid another if-statement.
|
||
if (this.props.drizzleState.web3.networkMismatch) { | ||
if (this.props.networkMismatchComp) { | ||
return this.props.networkMismatchComp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
|
||
if ( | ||
this.props.drizzleState.web3.status === "initialized" && | ||
Object.keys(this.props.drizzleState.accounts).length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider de-structuring and using intermediate variables.
@SeanJCasey I've went ahead and refactored import React, { Children, Component } from "react";
import PropTypes from "prop-types";
class LoadingContainer extends Component {
renderFailed() {
return (
this.props.errorComp || (
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1>⚠️</h1>
<p>
This browser has no connection to the Ethereum network. Please
use the Chrome/FireFox extension MetaMask, or dedicated Ethereum
browsers Mist or Parity.
</p>
</div>
</div>
</main>
)
);
}
renderNetworkMismatch() {
return (
this.props.networkMismatchComp || (
<main className="container network-warning">
<div className="pure-g">
<div className="pure-u-1-1">
<h1>⚠️</h1>
<p>This dapp does not support this network.</p>
</div>
</div>
</main>
)
);
}
renderNoAccounts() {
return (
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1>🦊</h1>
<p>
<strong>{"We can't find any Ethereum accounts!"}</strong> Please
check and make sure Metamask or your browser are pointed at the
correct network and your account is unlocked.
</p>
</div>
</div>
</main>
);
}
render() {
const { drizzleState, children, loadingComp } = this.props;
if (drizzleState) {
if (drizzleState.web3.status === "failed") {
this.renderFailed();
}
if (drizzleState.web3.networkMismatch) {
this.renderNetworkMismatch();
}
const noAccounts = Object.keys(drizzleState.accounts).length === 0;
if (drizzleState.web3.status === "initialized" && noAccounts) {
this.renderNoAccounts();
}
if (drizzleState.drizzleStatus.initialized) {
return Children.only(children);
}
}
return (
loadingComp || (
<main className="container loading-screen">
<div className="pure-g">
<div className="pure-u-1-1">
<h1>⚙️</h1>
<p>Loading dapp...</p>
</div>
</div>
</main>
)
);
}
}
LoadingContainer.propTypes = {
drizzleState: PropTypes.object,
children: PropTypes.node,
loadingComp: PropTypes.node,
errorComp: PropTypes.node,
networkMismatchComp: PropTypes.node,
};
export default LoadingContainer; |
Hey @adrianmcli , cool please do refactor as you see fit. I just copy/pasted/edited from the redux LoadingContainer for stylistic congruence (i.e., I implemented the |
@SeanJCasey On second glance, it appears my testing of the UIs failed. It doesn't recognize and allow Ganache because Ganache doesn't have a stable network ID of 5557 as this line assumes. Context:
|
@adrianmcli Hmm, interesting. I'll need to summon and defer to @cds-amal . We came to the conclusion that allowing port 5777 should (almost?) always be sufficient. Even if it isn't, we just need to make an addition to the readme that port 5777 is always allowed, but any custom ports need to be added (which might be obvious anyways if the user defines the |
Uses the
networkMismatch
flag to allow handling of network-related halting of loading drizzle.Updates the redux LoadingContainer and adds a new Context API-friendly Loading Container