-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Loading network screen #5893
Merged
Merged
Loading network screen #5893
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
47501a6
Add spinner and dropdown arrow to network indicator on custom network…
danjm 0e5e51b
Add identifier of private network to the network loading screen message.
danjm 20dbeba
Adds network loading retry / error screen.
danjm f4dc649
Improve styling of loading retry / error screen
danjm 04cc98d
Clean up for the loading-network-screen
danjm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './loading-network-screen.container' |
138 changes: 138 additions & 0 deletions
138
ui/app/components/loading-network-screen/loading-network-screen.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import Spinner from '../spinner' | ||
import Button from '../button' | ||
|
||
export default class LoadingNetworkScreen extends PureComponent { | ||
state = { | ||
showErrorScreen: false, | ||
} | ||
|
||
static contextTypes = { | ||
t: PropTypes.func, | ||
} | ||
|
||
static propTypes = { | ||
loadingMessage: PropTypes.string, | ||
cancelTime: PropTypes.number, | ||
provider: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
providerId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
showNetworkDropdown: PropTypes.func, | ||
setProviderArgs: PropTypes.array, | ||
lastSelectedProvider: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
setProviderType: PropTypes.func, | ||
isLoadingNetwork: PropTypes.bool, | ||
} | ||
|
||
componentDidMount = () => { | ||
this.cancelCallTimeout = setTimeout(this.cancelCall, this.props.cancelTime || 15000) | ||
} | ||
|
||
getConnectingLabel = function (loadingMessage) { | ||
if (loadingMessage) { | ||
return loadingMessage | ||
} | ||
const { provider, providerId } = this.props | ||
const providerName = provider.type | ||
|
||
let name | ||
|
||
if (providerName === 'mainnet') { | ||
name = this.context.t('connectingToMainnet') | ||
} else if (providerName === 'ropsten') { | ||
name = this.context.t('connectingToRopsten') | ||
} else if (providerName === 'kovan') { | ||
name = this.context.t('connectingToKovan') | ||
} else if (providerName === 'rinkeby') { | ||
name = this.context.t('connectingToRinkeby') | ||
} else { | ||
name = this.context.t('connectingTo', [providerId]) | ||
} | ||
|
||
return name | ||
} | ||
|
||
renderMessage = () => { | ||
return <span>{ this.getConnectingLabel(this.props.loadingMessage) }</span> | ||
} | ||
|
||
renderLoadingScreenContent = () => { | ||
return <div className="loading-overlay__screen-content"> | ||
<Spinner color="#F7C06C" /> | ||
{this.renderMessage()} | ||
</div> | ||
} | ||
|
||
renderErrorScreenContent = () => { | ||
const { showNetworkDropdown, setProviderArgs, setProviderType } = this.props | ||
|
||
return <div className="loading-overlay__error-screen"> | ||
<span className="loading-overlay__emoji">😞</span> | ||
<span>{ this.context.t('somethingWentWrong') }</span> | ||
<div className="loading-overlay__error-buttons"> | ||
<Button | ||
type="default" | ||
onClick={() => { | ||
window.clearTimeout(this.cancelCallTimeout) | ||
showNetworkDropdown() | ||
}} | ||
> | ||
{ this.context.t('switchNetworks') } | ||
</Button> | ||
|
||
<Button | ||
type="primary" | ||
onClick={() => { | ||
this.setState({ showErrorScreen: false }) | ||
setProviderType(...setProviderArgs) | ||
window.clearTimeout(this.cancelCallTimeout) | ||
this.cancelCallTimeout = setTimeout(this.cancelCall, this.props.cancelTime || 15000) | ||
}} | ||
> | ||
{ this.context.t('tryAgain') } | ||
</Button> | ||
</div> | ||
</div> | ||
} | ||
|
||
cancelCall = () => { | ||
const { isLoadingNetwork } = this.props | ||
|
||
if (isLoadingNetwork) { | ||
this.setState({ showErrorScreen: true }) | ||
} | ||
} | ||
|
||
componentDidUpdate = (prevProps) => { | ||
const { provider } = this.props | ||
const { provider: prevProvider } = prevProps | ||
if (provider.type !== prevProvider.type) { | ||
window.clearTimeout(this.cancelCallTimeout) | ||
this.setState({ showErrorScreen: false }) | ||
this.cancelCallTimeout = setTimeout(this.cancelCall, this.props.cancelTime || 15000) | ||
} | ||
} | ||
|
||
componentWillUnmount = () => { | ||
window.clearTimeout(this.cancelCallTimeout) | ||
} | ||
|
||
render () { | ||
const { lastSelectedProvider, setProviderType } = this.props | ||
|
||
return ( | ||
<div className="loading-overlay"> | ||
<div | ||
className="page-container__header-close" | ||
onClick={() => setProviderType(lastSelectedProvider || 'ropsten')} | ||
/> | ||
<div className="loading-overlay__container"> | ||
{ this.state.showErrorScreen | ||
? this.renderErrorScreenContent() | ||
: this.renderLoadingScreenContent() | ||
} | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
ui/app/components/loading-network-screen/loading-network-screen.container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { connect } from 'react-redux' | ||
import LoadingNetworkScreen from './loading-network-screen.component' | ||
import actions from '../../actions' | ||
import { getNetworkIdentifier } from '../../selectors' | ||
|
||
const mapStateToProps = state => { | ||
const { | ||
loadingMessage, | ||
currentView, | ||
} = state.appState | ||
const { | ||
provider, | ||
lastSelectedProvider, | ||
network, | ||
} = state.metamask | ||
const { rpcTarget, chainId, ticker, nickname, type } = provider | ||
|
||
const setProviderArgs = type === 'rpc' | ||
? [rpcTarget, chainId, ticker, nickname] | ||
: [provider.type] | ||
|
||
return { | ||
isLoadingNetwork: network === 'loading' && currentView.name !== 'config', | ||
loadingMessage, | ||
lastSelectedProvider, | ||
setProviderArgs, | ||
provider, | ||
providerId: getNetworkIdentifier(state), | ||
} | ||
} | ||
|
||
const mapDispatchToProps = dispatch => { | ||
return { | ||
setProviderType: (type) => { | ||
dispatch(actions.setProviderType(type)) | ||
}, | ||
showNetworkDropdown: () => dispatch(actions.showNetworkDropdown()), | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(LoadingNetworkScreen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './loading-network-error.container' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 looks like a formatting error?
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 think there should be a closing brace on the line above