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,
|
|
|
|
getWeb3ShimUsageStateForOrigin,
|
|
|
|
unconfirmedTransactionsCountSelector,
|
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-10-06 20:28:38 +02:00
|
|
|
setSwapsWelcomeMessageHasBeenShown,
|
2020-12-11 00:40:29 +01:00
|
|
|
setWeb3ShimUsageAlertDismissed,
|
|
|
|
setAlertEnabledness,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { setThreeBoxLastUpdated } from '../../ducks/app/app';
|
|
|
|
import { getWeb3ShimUsageAlertEnabledness } from '../../ducks/metamask/metamask';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
getSwapsWelcomeMessageSeenStatus,
|
|
|
|
getSwapsFeatureLiveness,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../ducks/swaps/swaps';
|
|
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
2020-04-20 19:21:57 +02:00
|
|
|
import {
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
|
|
|
ENVIRONMENT_TYPE_POPUP,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../shared/constants/app';
|
2020-12-11 00:40:29 +01:00
|
|
|
import {
|
|
|
|
ALERT_TYPES,
|
|
|
|
WEB3_SHIM_USAGE_ALERT_STATES,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../../shared/constants/alerts';
|
|
|
|
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 {
|
2018-08-28 20:20:30 +02:00
|
|
|
suggestedTokens,
|
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-02-22 17:20:42 +01:00
|
|
|
pendingApprovals = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = metamask;
|
|
|
|
const accountBalance = getCurrentEthBalance(state);
|
|
|
|
const { forgottenPassword, threeBoxLastUpdated } = appState;
|
|
|
|
const totalUnapprovedCount = getTotalUnapprovedCount(state);
|
|
|
|
const swapsEnabled = getSwapsFeatureLiveness(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,
|
2018-08-28 20:20:30 +02:00
|
|
|
suggestedTokens,
|
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 &&
|
2020-11-03 00:41:28 +01:00
|
|
|
(parseInt(accountBalance, 16) > 0 || tokens.length > 0),
|
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
|
|
|
swapsWelcomeMessageHasBeenShown: getSwapsWelcomeMessageSeenStatus(state),
|
|
|
|
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-02-22 17:20:42 +01:00
|
|
|
pendingApprovals: Object.values(pendingApprovals),
|
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-11-03 00:41:28 +01:00
|
|
|
setSwapsWelcomeMessageHasBeenShown: () =>
|
|
|
|
dispatch(setSwapsWelcomeMessageHasBeenShown()),
|
2020-12-11 00:40:29 +01:00
|
|
|
setWeb3ShimUsageAlertDismissed: (origin) =>
|
|
|
|
setWeb3ShimUsageAlertDismissed(origin),
|
|
|
|
disableWeb3ShimUsageAlert: () =>
|
|
|
|
setAlertEnabledness(ALERT_TYPES.web3ShimUsage, false),
|
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);
|