Establish onboarding-flow wrapper/router base and feature flag env variable (#12247)
* establish onboarding-flow wrapper/router base and feature flag env variable * small cleanup * addressing feedbackfeature/default_network_editable
parent
730605353a
commit
9355fb21c7
@ -0,0 +1,18 @@ |
||||
@import 'recovery-phrase/index'; |
||||
@import 'new-account/index'; |
||||
|
||||
.onboarding-flow { |
||||
width: 100%; |
||||
background-color: $white; |
||||
display: flex; |
||||
flex-direction: column; |
||||
justify-content: center; |
||||
align-items: center; |
||||
|
||||
&__wrapper { |
||||
margin-top: 40px; |
||||
padding: 32px; |
||||
border: 1px solid $Grey-100; |
||||
border-radius: 20px; |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
import React from 'react'; |
||||
import { useSelector } from 'react-redux'; |
||||
import { Redirect } from 'react-router-dom'; |
||||
import { |
||||
DEFAULT_ROUTE, |
||||
ONBOARDING_COMPLETION_ROUTE, |
||||
ONBOARDING_GET_STARTED_ROUTE, |
||||
ONBOARDING_UNLOCK_ROUTE, |
||||
LOCK_ROUTE, |
||||
} from '../../../helpers/constants/routes'; |
||||
import { |
||||
getCompletedOnboarding, |
||||
getIsInitialized, |
||||
getIsUnlocked, |
||||
getSeedPhraseBackedUp, |
||||
} from '../../../ducks/metamask/metamask'; |
||||
|
||||
export default function OnboardingFlowSwitch() { |
||||
const completedOnboarding = useSelector(getCompletedOnboarding); |
||||
const isInitialized = useSelector(getIsInitialized); |
||||
const seedPhraseBackedUp = useSelector(getSeedPhraseBackedUp); |
||||
const isUnlocked = useSelector(getIsUnlocked); |
||||
|
||||
if (completedOnboarding) { |
||||
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />; |
||||
} |
||||
|
||||
if (seedPhraseBackedUp !== null) { |
||||
return <Redirect to={{ pathname: ONBOARDING_COMPLETION_ROUTE }} />; |
||||
} |
||||
|
||||
if (isUnlocked) { |
||||
return <Redirect to={{ pathname: LOCK_ROUTE }} />; |
||||
} |
||||
|
||||
if (!isInitialized) { |
||||
return <Redirect to={{ pathname: ONBOARDING_GET_STARTED_ROUTE }} />; |
||||
} |
||||
|
||||
return <Redirect to={{ pathname: ONBOARDING_UNLOCK_ROUTE }} />; |
||||
} |
@ -0,0 +1,109 @@ |
||||
import React, { useEffect, useState } from 'react'; |
||||
import { Switch, Route, useHistory } from 'react-router-dom'; |
||||
import { useDispatch, useSelector } from 'react-redux'; |
||||
import Unlock from '../unlock-page'; |
||||
import { |
||||
ONBOARDING_CREATE_PASSWORD_ROUTE, |
||||
ONBOARDING_REVIEW_SRP_ROUTE, |
||||
ONBOARDING_CONFIRM_SRP_ROUTE, |
||||
ONBOARDING_UNLOCK_ROUTE, |
||||
DEFAULT_ROUTE, |
||||
} from '../../helpers/constants/routes'; |
||||
import { |
||||
getCompletedOnboarding, |
||||
getIsInitialized, |
||||
getIsUnlocked, |
||||
getSeedPhraseBackedUp, |
||||
} from '../../ducks/metamask/metamask'; |
||||
import { |
||||
createNewVaultAndGetSeedPhrase, |
||||
unlockAndGetSeedPhrase, |
||||
} from '../../store/actions'; |
||||
import { getFirstTimeFlowTypeRoute } from '../../selectors'; |
||||
import OnboardingFlowSwitch from './onboarding-flow-switch/onboarding-flow-switch'; |
||||
import NewAccount from './new-account/new-account'; |
||||
import ReviewRecoveryPhrase from './recovery-phrase/review-recovery-phrase'; |
||||
import ConfirmRecoveryPhrase from './recovery-phrase/confirm-recovery-phrase'; |
||||
|
||||
export default function OnboardingFlow() { |
||||
const [seedPhrase, setSeedPhrase] = useState(''); |
||||
const dispatch = useDispatch(); |
||||
const history = useHistory(); |
||||
const isInitialized = useSelector(getIsInitialized); |
||||
const isUnlocked = useSelector(getIsUnlocked); |
||||
const completedOnboarding = useSelector(getCompletedOnboarding); |
||||
const seedPhraseBackedUp = useSelector(getSeedPhraseBackedUp); |
||||
const nextRoute = useSelector(getFirstTimeFlowTypeRoute); |
||||
|
||||
useEffect(() => { |
||||
// For ONBOARDING_V2 dev purposes,
|
||||
// Remove when ONBOARDING_V2 dev complete
|
||||
if (process.env.ONBOARDING_V2) { |
||||
history.push(ONBOARDING_CREATE_PASSWORD_ROUTE); |
||||
return; |
||||
} |
||||
|
||||
if (completedOnboarding && seedPhraseBackedUp) { |
||||
history.push(DEFAULT_ROUTE); |
||||
return; |
||||
} |
||||
|
||||
if (isInitialized && !isUnlocked) { |
||||
history.push(ONBOARDING_UNLOCK_ROUTE); |
||||
} |
||||
}, [ |
||||
history, |
||||
completedOnboarding, |
||||
isInitialized, |
||||
isUnlocked, |
||||
seedPhraseBackedUp, |
||||
]); |
||||
|
||||
const handleCreateNewAccount = async (password) => { |
||||
const newSeedPhrase = await dispatch( |
||||
createNewVaultAndGetSeedPhrase(password), |
||||
); |
||||
setSeedPhrase(newSeedPhrase); |
||||
}; |
||||
|
||||
const handleUnlock = async (password) => { |
||||
const retreivedSeedPhrase = await dispatch( |
||||
unlockAndGetSeedPhrase(password), |
||||
); |
||||
setSeedPhrase(retreivedSeedPhrase); |
||||
history.push(nextRoute); |
||||
}; |
||||
|
||||
return ( |
||||
<div className="onboarding-flow"> |
||||
<div className="onboarding-flow__wrapper"> |
||||
<Switch> |
||||
<Route |
||||
path={ONBOARDING_CREATE_PASSWORD_ROUTE} |
||||
render={(routeProps) => ( |
||||
<NewAccount |
||||
{...routeProps} |
||||
createNewAccount={handleCreateNewAccount} |
||||
/> |
||||
)} |
||||
/> |
||||
<Route |
||||
path={ONBOARDING_REVIEW_SRP_ROUTE} |
||||
render={() => <ReviewRecoveryPhrase seedPhrase={seedPhrase} />} |
||||
/> |
||||
<Route |
||||
path={ONBOARDING_CONFIRM_SRP_ROUTE} |
||||
render={() => <ConfirmRecoveryPhrase seedPhrase={seedPhrase} />} |
||||
/> |
||||
<Route |
||||
path={ONBOARDING_UNLOCK_ROUTE} |
||||
render={(routeProps) => ( |
||||
<Unlock {...routeProps} onSubmit={handleUnlock} /> |
||||
)} |
||||
/> |
||||
<Route exact path="*" component={OnboardingFlowSwitch} /> |
||||
</Switch> |
||||
</div> |
||||
</div> |
||||
); |
||||
} |
Loading…
Reference in new issue