import Home from './home.component' import { compose } from 'redux' import { connect } from 'react-redux' import { withRouter } from 'react-router-dom' import { unconfirmedTransactionsCountSelector } from '../../selectors/confirm-transaction' import { getCurrentEthBalance, getDaiV1Token, getFirstPermissionRequest } from '../../selectors/selectors' import { restoreFromThreeBox, turnThreeBoxSyncingOn, getThreeBoxLastUpdated, setShowRestorePromptToFalse, } from '../../store/actions' import { setThreeBoxLastUpdated } from '../../ducks/app/app' import { getEnvironmentType } from '../../../../app/scripts/lib/util' import { ENVIRONMENT_TYPE_POPUP } from '../../../../app/scripts/lib/enums' const mapStateToProps = (state) => { const { metamask, appState } = state const { suggestedTokens, seedPhraseBackedUp, tokens, threeBoxSynced, showRestorePrompt, selectedAddress, } = metamask const accountBalance = getCurrentEthBalance(state) const { forgottenPassword, threeBoxLastUpdated } = appState const isPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP const firstPermissionsRequest = getFirstPermissionRequest(state) const firstPermissionsRequestId = (firstPermissionsRequest && firstPermissionsRequest.metadata) ? firstPermissionsRequest.metadata.id : null return { forgottenPassword, suggestedTokens, unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state), shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0), isPopup, threeBoxSynced, showRestorePrompt, selectedAddress, threeBoxLastUpdated, hasDaiV1Token: Boolean(getDaiV1Token(state)), firstPermissionsRequestId, } } const mapDispatchToProps = (dispatch) => ({ turnThreeBoxSyncingOn: () => dispatch(turnThreeBoxSyncingOn()), setupThreeBox: () => { dispatch(getThreeBoxLastUpdated()) .then((lastUpdated) => { if (lastUpdated) { dispatch(setThreeBoxLastUpdated(lastUpdated)) } else { dispatch(setShowRestorePromptToFalse()) dispatch(turnThreeBoxSyncingOn()) } }) }, restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)), setShowRestorePromptToFalse: () => dispatch(setShowRestorePromptToFalse()), }) export default compose( withRouter, connect(mapStateToProps, mapDispatchToProps) )(Home)