Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(onboarding): prevent state update during render
Browse files Browse the repository at this point in the history
  • Loading branch information
korhaliv committed Apr 10, 2019
1 parent d82065e commit f32e6b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions renderer/components/Onboarding/Onboarding.js
Expand Up @@ -80,13 +80,12 @@ class Onboarding extends React.Component {
* @return {{key: string}[]} Modified list of form steps.
*/
removeAutopilotStepIfMainnet = formSteps => {
const { network, setAutopilot } = this.props
const { network } = this.props
if (network === 'mainnet') {
const index = formSteps.findIndex(s => s.key === 'Autopilot')
if (index >= 0) {
formSteps.splice(index, 1)
}
setAutopilot(false)
}
return formSteps
}
Expand Down Expand Up @@ -158,7 +157,11 @@ class Onboarding extends React.Component {
<Wizard.Step key="SeedConfirm" component={SeedConfirm} {...{ seed }} />,
<Wizard.Step key="Password" component={Password} {...{ setPassword }} />,
<Wizard.Step key="Name" component={Name} {...{ name, setName }} />,
<Wizard.Step key="Network" component={Network} {...{ network, setNetwork }} />,
<Wizard.Step
key="Network"
component={Network}
{...{ network, setNetwork, setAutopilot }}
/>,
<Wizard.Step key="Autopilot" component={Autopilot} {...{ autopilot, setAutopilot }} />,
<Wizard.Step key="WalletCreate" component={WalletCreate} {...{ createNewWallet }} />,
]
Expand Down
14 changes: 11 additions & 3 deletions renderer/components/Onboarding/Steps/Network.js
Expand Up @@ -7,6 +7,7 @@ import messages from './messages'
class Network extends React.Component {
static propTypes = {
network: PropTypes.string, // eslint-disable-line react/boolean-prop-naming
setAutopilot: PropTypes.func.isRequired,
setNetwork: PropTypes.func.isRequired,
wizardApi: PropTypes.object,
wizardState: PropTypes.object,
Expand All @@ -18,16 +19,23 @@ class Network extends React.Component {
}

handleSubmit = values => {
const { setNetwork } = this.props
setNetwork(values.network)
const { setNetwork, setAutopilot } = this.props
const { network } = values
setNetwork(network)

// It is currently not recommended to use autopilot on mainnet.
// If user has selected mainnet, disable it
if (network === 'mainnet') {
setAutopilot(false)
}
}

setFormApi = formApi => {
this.formApi = formApi
}

render() {
const { wizardApi, wizardState, network, setNetwork, ...rest } = this.props
const { wizardApi, wizardState, network, setNetwork, setAutopilot, ...rest } = this.props
const { getApi, onChange, onSubmit, onSubmitFailure } = wizardApi
const { currentItem } = wizardState
return (
Expand Down

0 comments on commit f32e6b2

Please sign in to comment.