// @flow import React from 'react' import { Provider, connect } from 'react-redux' import { ConnectedRouter } from 'react-router-redux' import PropTypes from 'prop-types' import LoadingBolt from '../components/LoadingBolt' import Onboarding from '../components/Onboarding' import Syncing from '../components/Onboarding/Syncing' import { updateAlias, updatePassword, setAutopilot, changeStep, startLnd, createWallet, updateCreateWalletPassword, updateAezeedPassword, submitNewWallet, onboardingSelectors, unlockWallet, setSignupCreate, setSignupImport, updateSeedInput } from '../reducers/onboarding' import { fetchBlockHeight, lndSelectors } from '../reducers/lnd' import Routes from '../routes' const mapDispatchToProps = { updateAlias, updatePassword, updateCreateWalletPassword, updateAezeedPassword, setAutopilot, changeStep, startLnd, createWallet, submitNewWallet, unlockWallet, setSignupCreate, setSignupImport, updateSeedInput, fetchBlockHeight } const mapStateToProps = state => ({ lnd: state.lnd, onboarding: state.onboarding, syncPercentage: lndSelectors.syncPercentage(state), passwordIsValid: onboardingSelectors.passwordIsValid(state), reEnterSeedChecker: onboardingSelectors.reEnterSeedChecker(state), renderEnterSeedHtml: onboardingSelectors.renderEnterSeedHtml(state) }) const mergeProps = (stateProps, dispatchProps, ownProps) => { const syncingProps = { fetchBlockHeight: dispatchProps.fetchBlockHeight, syncPercentage: stateProps.syncPercentage } const aliasProps = { updateAlias: dispatchProps.updateAlias, alias: stateProps.onboarding.alias } const autopilotProps = { autopilot: stateProps.onboarding.autopilot, setAutopilot: dispatchProps.setAutopilot } const initWalletProps = { hasSeed: stateProps.onboarding.hasSeed, loginProps: { password: stateProps.onboarding.password, passwordIsValid: stateProps.passwordIsValid, hasSeed: stateProps.onboarding.hasSeed, unlockingWallet: stateProps.onboarding.unlockingWallet, unlockWalletError: stateProps.onboarding.unlockWalletError, updatePassword: dispatchProps.updatePassword, createWallet: dispatchProps.createWallet, unlockWallet: dispatchProps.unlockWallet }, signupProps: { signupForm: stateProps.onboarding.signupForm, setSignupCreate: dispatchProps.setSignupCreate, setSignupImport: dispatchProps.setSignupImport } } const newWalletSeedProps = { seed: stateProps.onboarding.seed } const newWalletPasswordProps = { createWalletPassword: stateProps.onboarding.createWalletPassword, updateCreateWalletPassword: dispatchProps.updateCreateWalletPassword } const newAezeedPasswordProps = { aezeedPassword: stateProps.onboarding.aezeedPassword, updateAezeedPassword: dispatchProps.updateAezeedPassword } const reEnterSeedProps = { seed: stateProps.onboarding.seed, seedInput: stateProps.onboarding.seedInput, reEnterSeedChecker: stateProps.reEnterSeedChecker, renderEnterSeedHtml: stateProps.renderEnterSeedHtml, updateSeedInput: dispatchProps.updateSeedInput } const onboardingProps = { onboarding: stateProps.onboarding, changeStep: dispatchProps.changeStep, startLnd: dispatchProps.startLnd, submitNewWallet: dispatchProps.submitNewWallet, aliasProps, autopilotProps, initWalletProps, newWalletSeedProps, newWalletPasswordProps, newAezeedPasswordProps, reEnterSeedProps } return { ...stateProps, ...dispatchProps, ...ownProps, onboardingProps, syncingProps } } const Root = ({ store, history, lnd, onboardingProps, syncingProps }) => { // If we are syncing show the syncing screen if (!onboardingProps.onboarding.onboarded) { return } // If we are syncing show the syncing screen if (lnd.syncing) { return } // Don't launch the app without gRPC connection if (!lnd.grpcStarted) { return } return ( ) } Root.propTypes = { store: PropTypes.object.isRequired, history: PropTypes.object.isRequired, lnd: PropTypes.object.isRequired, onboardingProps: PropTypes.object.isRequired, syncingProps: PropTypes.object.isRequired } export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Root)