-
Notifications
You must be signed in to change notification settings - Fork 234
Network-aware LoadingContainer #9
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { Children, Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||
return this.props.errorComp; | ||
} | ||
|
||
return ( | ||
<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> | ||
); | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
} | ||
|
||
return ( | ||
<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> | ||
); | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Consider de-structuring and using intermediate variables. |
||
) { | ||
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> | ||
); | ||
} | ||
|
||
if (this.props.drizzleState.drizzleStatus.initialized) { | ||
return Children.only(this.props.children); | ||
} | ||
} | ||
|
||
if (this.props.loadingComp) { | ||
return this.props.loadingComp; | ||
} | ||
|
||
return ( | ||
<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; |
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:
This allows us to avoid the nested if statement and also makes it clear that
this.props.networkMismatchComp
is a component.