2021-02-04 19:15:23 +01:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2020-04-20 19:21:57 +02:00
|
|
|
import {
|
2020-12-11 00:40:29 +01:00
|
|
|
activeTabHasPermissions,
|
2020-04-20 19:21:57 +02:00
|
|
|
getCurrentEthBalance,
|
|
|
|
getFirstPermissionRequest,
|
2020-10-09 17:37:11 +02:00
|
|
|
getIsMainnet,
|
2020-12-11 00:40:29 +01:00
|
|
|
getOriginOfCurrentTab,
|
|
|
|
getTotalUnapprovedCount,
|
2021-03-23 22:12:32 +01:00
|
|
|
getUnapprovedTemplatedConfirmations,
|
2020-12-11 00:40:29 +01:00
|
|
|
getWeb3ShimUsageStateForOrigin,
|
|
|
|
unconfirmedTransactionsCountSelector,
|
2021-04-15 19:41:40 +02:00
|
|
|
getInfuraBlocked,
|
2021-04-28 18:51:41 +02:00
|
|
|
getShowWhatsNewPopup,
|
|
|
|
getSortedNotificationsToShow,
|
2021-06-05 08:33:58 +02:00
|
|
|
getShowRecoveryPhraseReminder,
|
2021-10-25 22:38:43 +02:00
|
|
|
getNewNetworkAdded,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../selectors';
|
2020-05-02 21:41:17 +02:00
|
|
|
|
2019-08-01 15:24:33 +02:00
|
|
|
import {
|
2019-09-16 19:11:01 +02:00
|
|
|
restoreFromThreeBox,
|
|
|
|
turnThreeBoxSyncingOn,
|
|
|
|
getThreeBoxLastUpdated,
|
2019-09-26 09:24:52 +02:00
|
|
|
setShowRestorePromptToFalse,
|
2020-04-22 19:11:36 +02:00
|
|
|
setConnectedStatusPopoverHasBeenShown,
|
2020-05-25 21:01:28 +02:00
|
|
|
setDefaultHomeActiveTabName,
|
2020-12-11 00:40:29 +01:00
|
|
|
setWeb3ShimUsageAlertDismissed,
|
|
|
|
setAlertEnabledness,
|
2021-06-05 08:33:58 +02:00
|
|
|
setRecoveryPhraseReminderHasBeenShown,
|
|
|
|
setRecoveryPhraseReminderLastShown,
|
2021-10-25 22:38:43 +02:00
|
|
|
setNewNetworkAdded,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
2021-04-28 18:51:41 +02:00
|
|
|
import { setThreeBoxLastUpdated, hideWhatsNewPopup } from '../../ducks/app/app';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getWeb3ShimUsageAlertEnabledness } from '../../ducks/metamask/metamask';
|
2021-07-09 17:24:00 +02:00
|
|
|
import { getSwapsFeatureIsLive } from '../../ducks/swaps/swaps';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
2020-04-20 19:21:57 +02:00
|
|
|
import {
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../shared/constants/app';
|
2020-12-11 00:40:29 +01:00
|
|
|
import {
|
|
|
|
ALERT_TYPES,
|
|
|
|
WEB3_SHIM_USAGE_ALERT_STATES,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../shared/constants/alerts';
|
2021-02-04 19:15:23 +01:00
|
|
|
import Home from './home.component';
|
2019-07-12 17:41:39 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { metamask, appState } = state;
|
2018-07-24 20:40:05 +02:00
|
|
|
const {
|
2021-09-10 19:37:19 +02:00
|
|
|
suggestedAssets,
|
2019-08-02 05:57:26 +02:00
|
|
|
seedPhraseBackedUp,
|
2019-08-02 20:43:15 +02:00
|
|
|
tokens,
|
2019-09-16 19:11:01 +02:00
|
|
|
threeBoxSynced,
|
2019-09-26 09:24:52 +02:00
|
|
|
showRestorePrompt,
|
2019-09-16 19:11:01 +02:00
|
|
|
selectedAddress,
|
2020-04-22 19:11:36 +02:00
|
|
|
connectedStatusPopoverHasBeenShown,
|
2020-05-25 21:01:28 +02:00
|
|
|
defaultHomeActiveTabName,
|
2020-10-06 20:28:38 +02:00
|
|
|
swapsState,
|
2021-05-05 15:58:29 +02:00
|
|
|
dismissSeedBackUpReminder,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = metamask;
|
|
|
|
const accountBalance = getCurrentEthBalance(state);
|
|
|
|
const { forgottenPassword, threeBoxLastUpdated } = appState;
|
|
|
|
const totalUnapprovedCount = getTotalUnapprovedCount(state);
|
2021-07-09 17:24:00 +02:00
|
|
|
const swapsEnabled = getSwapsFeatureIsLive(state);
|
2021-03-23 22:12:32 +01:00
|
|
|
const pendingConfirmations = getUnapprovedTemplatedConfirmations(state);
|
2020-04-20 19:21:57 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const envType = getEnvironmentType();
|
|
|
|
const isPopup = envType === ENVIRONMENT_TYPE_POPUP;
|
|
|
|
const isNotification = envType === ENVIRONMENT_TYPE_NOTIFICATION;
|
2018-07-24 20:40:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const firstPermissionsRequest = getFirstPermissionRequest(state);
|
2020-11-03 00:41:28 +01:00
|
|
|
const firstPermissionsRequestId =
|
|
|
|
firstPermissionsRequest && firstPermissionsRequest.metadata
|
|
|
|
? firstPermissionsRequest.metadata.id
|
2021-02-04 19:15:23 +01:00
|
|
|
: null;
|
2019-08-01 15:24:33 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const originOfCurrentTab = getOriginOfCurrentTab(state);
|
2020-12-11 00:40:29 +01:00
|
|
|
const shouldShowWeb3ShimUsageNotification =
|
|
|
|
isPopup &&
|
|
|
|
getWeb3ShimUsageAlertEnabledness(state) &&
|
|
|
|
activeTabHasPermissions(state) &&
|
|
|
|
getWeb3ShimUsageStateForOrigin(state, originOfCurrentTab) ===
|
2021-02-04 19:15:23 +01:00
|
|
|
WEB3_SHIM_USAGE_ALERT_STATES.RECORDED;
|
2020-12-11 00:40:29 +01:00
|
|
|
|
2018-07-24 20:40:05 +02:00
|
|
|
return {
|
|
|
|
forgottenPassword,
|
2021-09-10 19:37:19 +02:00
|
|
|
suggestedAssets,
|
2020-10-06 20:28:38 +02:00
|
|
|
swapsEnabled,
|
2018-07-31 07:03:20 +02:00
|
|
|
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
|
2020-11-03 00:41:28 +01:00
|
|
|
shouldShowSeedPhraseReminder:
|
2020-11-10 17:04:20 +01:00
|
|
|
seedPhraseBackedUp === false &&
|
2021-05-05 15:58:29 +02:00
|
|
|
(parseInt(accountBalance, 16) > 0 || tokens.length > 0) &&
|
|
|
|
dismissSeedBackUpReminder === false,
|
2019-08-02 22:31:26 +02:00
|
|
|
isPopup,
|
2020-04-20 19:21:57 +02:00
|
|
|
isNotification,
|
2019-09-16 19:11:01 +02:00
|
|
|
threeBoxSynced,
|
2019-09-26 09:24:52 +02:00
|
|
|
showRestorePrompt,
|
2019-09-16 19:11:01 +02:00
|
|
|
selectedAddress,
|
|
|
|
threeBoxLastUpdated,
|
2019-12-05 22:05:50 +01:00
|
|
|
firstPermissionsRequestId,
|
2020-04-20 19:21:57 +02:00
|
|
|
totalUnapprovedCount,
|
2020-04-22 19:11:36 +02:00
|
|
|
connectedStatusPopoverHasBeenShown,
|
2020-05-25 21:01:28 +02:00
|
|
|
defaultHomeActiveTabName,
|
2020-10-06 20:28:38 +02:00
|
|
|
haveSwapsQuotes: Boolean(Object.values(swapsState.quotes || {}).length),
|
|
|
|
swapsFetchParams: swapsState.fetchParams,
|
|
|
|
showAwaitingSwapScreen: swapsState.routeState === 'awaiting',
|
2020-10-09 17:37:11 +02:00
|
|
|
isMainnet: getIsMainnet(state),
|
2020-12-11 00:40:29 +01:00
|
|
|
originOfCurrentTab,
|
|
|
|
shouldShowWeb3ShimUsageNotification,
|
2021-03-23 22:12:32 +01:00
|
|
|
pendingConfirmations,
|
2021-04-15 19:41:40 +02:00
|
|
|
infuraBlocked: getInfuraBlocked(state),
|
2021-04-28 18:51:41 +02:00
|
|
|
notificationsToShow: getSortedNotificationsToShow(state).length > 0,
|
|
|
|
showWhatsNewPopup: getShowWhatsNewPopup(state),
|
2021-06-05 08:33:58 +02:00
|
|
|
showRecoveryPhraseReminder: getShowRecoveryPhraseReminder(state),
|
|
|
|
seedPhraseBackedUp,
|
2021-10-25 22:38:43 +02:00
|
|
|
newNetworkAdded: getNewNetworkAdded(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-07-24 20:40:05 +02:00
|
|
|
|
2019-08-01 15:24:33 +02:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2019-09-16 19:11:01 +02:00
|
|
|
turnThreeBoxSyncingOn: () => dispatch(turnThreeBoxSyncingOn()),
|
|
|
|
setupThreeBox: () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
dispatch(getThreeBoxLastUpdated()).then((lastUpdated) => {
|
|
|
|
if (lastUpdated) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(setThreeBoxLastUpdated(lastUpdated));
|
2020-11-03 00:41:28 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(setShowRestorePromptToFalse());
|
|
|
|
dispatch(turnThreeBoxSyncingOn());
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-09-16 19:11:01 +02:00
|
|
|
},
|
|
|
|
restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)),
|
2019-09-26 09:24:52 +02:00
|
|
|
setShowRestorePromptToFalse: () => dispatch(setShowRestorePromptToFalse()),
|
2020-11-03 00:41:28 +01:00
|
|
|
setConnectedStatusPopoverHasBeenShown: () =>
|
|
|
|
dispatch(setConnectedStatusPopoverHasBeenShown()),
|
2020-05-25 21:01:28 +02:00
|
|
|
onTabClick: (name) => dispatch(setDefaultHomeActiveTabName(name)),
|
2020-12-11 00:40:29 +01:00
|
|
|
setWeb3ShimUsageAlertDismissed: (origin) =>
|
|
|
|
setWeb3ShimUsageAlertDismissed(origin),
|
|
|
|
disableWeb3ShimUsageAlert: () =>
|
|
|
|
setAlertEnabledness(ALERT_TYPES.web3ShimUsage, false),
|
2021-04-28 18:51:41 +02:00
|
|
|
hideWhatsNewPopup: () => dispatch(hideWhatsNewPopup()),
|
2021-06-05 08:33:58 +02:00
|
|
|
setRecoveryPhraseReminderHasBeenShown: () =>
|
|
|
|
dispatch(setRecoveryPhraseReminderHasBeenShown()),
|
|
|
|
setRecoveryPhraseReminderLastShown: (lastShown) =>
|
|
|
|
dispatch(setRecoveryPhraseReminderLastShown(lastShown)),
|
2021-10-25 22:38:43 +02:00
|
|
|
setNewNetworkAdded: (newNetwork) => {
|
|
|
|
dispatch(setNewNetworkAdded(newNetwork));
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-08-01 15:24:33 +02:00
|
|
|
|
2018-07-24 20:40:05 +02:00
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(Home);
|