You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.6 KiB
139 lines
4.6 KiB
4 years ago
|
import { compose } from 'redux';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
5 years ago
|
import {
|
||
4 years ago
|
activeTabHasPermissions,
|
||
5 years ago
|
getCurrentEthBalance,
|
||
|
getFirstPermissionRequest,
|
||
4 years ago
|
getIsMainnet,
|
||
4 years ago
|
getOriginOfCurrentTab,
|
||
|
getTotalUnapprovedCount,
|
||
4 years ago
|
getUnapprovedTemplatedConfirmations,
|
||
4 years ago
|
getWeb3ShimUsageStateForOrigin,
|
||
|
unconfirmedTransactionsCountSelector,
|
||
4 years ago
|
getInfuraBlocked,
|
||
4 years ago
|
getShowWhatsNewPopup,
|
||
|
getSortedNotificationsToShow,
|
||
4 years ago
|
} from '../../selectors';
|
||
5 years ago
|
|
||
5 years ago
|
import {
|
||
5 years ago
|
restoreFromThreeBox,
|
||
|
turnThreeBoxSyncingOn,
|
||
|
getThreeBoxLastUpdated,
|
||
5 years ago
|
setShowRestorePromptToFalse,
|
||
5 years ago
|
setConnectedStatusPopoverHasBeenShown,
|
||
5 years ago
|
setDefaultHomeActiveTabName,
|
||
4 years ago
|
setWeb3ShimUsageAlertDismissed,
|
||
|
setAlertEnabledness,
|
||
4 years ago
|
} from '../../store/actions';
|
||
4 years ago
|
import { setThreeBoxLastUpdated, hideWhatsNewPopup } from '../../ducks/app/app';
|
||
4 years ago
|
import { getWeb3ShimUsageAlertEnabledness } from '../../ducks/metamask/metamask';
|
||
4 years ago
|
import { getSwapsFeatureLiveness } from '../../ducks/swaps/swaps';
|
||
4 years ago
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
||
5 years ago
|
import {
|
||
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
||
|
ENVIRONMENT_TYPE_POPUP,
|
||
4 years ago
|
} from '../../../shared/constants/app';
|
||
4 years ago
|
import {
|
||
|
ALERT_TYPES,
|
||
|
WEB3_SHIM_USAGE_ALERT_STATES,
|
||
4 years ago
|
} from '../../../shared/constants/alerts';
|
||
4 years ago
|
import Home from './home.component';
|
||
5 years ago
|
|
||
5 years ago
|
const mapStateToProps = (state) => {
|
||
4 years ago
|
const { metamask, appState } = state;
|
||
6 years ago
|
const {
|
||
6 years ago
|
suggestedTokens,
|
||
5 years ago
|
seedPhraseBackedUp,
|
||
5 years ago
|
tokens,
|
||
5 years ago
|
threeBoxSynced,
|
||
5 years ago
|
showRestorePrompt,
|
||
5 years ago
|
selectedAddress,
|
||
5 years ago
|
connectedStatusPopoverHasBeenShown,
|
||
5 years ago
|
defaultHomeActiveTabName,
|
||
4 years ago
|
swapsState,
|
||
4 years ago
|
} = metamask;
|
||
|
const accountBalance = getCurrentEthBalance(state);
|
||
|
const { forgottenPassword, threeBoxLastUpdated } = appState;
|
||
|
const totalUnapprovedCount = getTotalUnapprovedCount(state);
|
||
|
const swapsEnabled = getSwapsFeatureLiveness(state);
|
||
4 years ago
|
const pendingConfirmations = getUnapprovedTemplatedConfirmations(state);
|
||
5 years ago
|
|
||
4 years ago
|
const envType = getEnvironmentType();
|
||
|
const isPopup = envType === ENVIRONMENT_TYPE_POPUP;
|
||
|
const isNotification = envType === ENVIRONMENT_TYPE_NOTIFICATION;
|
||
6 years ago
|
|
||
4 years ago
|
const firstPermissionsRequest = getFirstPermissionRequest(state);
|
||
4 years ago
|
const firstPermissionsRequestId =
|
||
|
firstPermissionsRequest && firstPermissionsRequest.metadata
|
||
|
? firstPermissionsRequest.metadata.id
|
||
4 years ago
|
: null;
|
||
5 years ago
|
|
||
4 years ago
|
const originOfCurrentTab = getOriginOfCurrentTab(state);
|
||
4 years ago
|
const shouldShowWeb3ShimUsageNotification =
|
||
|
isPopup &&
|
||
|
getWeb3ShimUsageAlertEnabledness(state) &&
|
||
|
activeTabHasPermissions(state) &&
|
||
|
getWeb3ShimUsageStateForOrigin(state, originOfCurrentTab) ===
|
||
4 years ago
|
WEB3_SHIM_USAGE_ALERT_STATES.RECORDED;
|
||
4 years ago
|
|
||
6 years ago
|
return {
|
||
|
forgottenPassword,
|
||
6 years ago
|
suggestedTokens,
|
||
4 years ago
|
swapsEnabled,
|
||
6 years ago
|
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
|
||
4 years ago
|
shouldShowSeedPhraseReminder:
|
||
4 years ago
|
seedPhraseBackedUp === false &&
|
||
4 years ago
|
(parseInt(accountBalance, 16) > 0 || tokens.length > 0),
|
||
5 years ago
|
isPopup,
|
||
5 years ago
|
isNotification,
|
||
5 years ago
|
threeBoxSynced,
|
||
5 years ago
|
showRestorePrompt,
|
||
5 years ago
|
selectedAddress,
|
||
|
threeBoxLastUpdated,
|
||
5 years ago
|
firstPermissionsRequestId,
|
||
5 years ago
|
totalUnapprovedCount,
|
||
5 years ago
|
connectedStatusPopoverHasBeenShown,
|
||
5 years ago
|
defaultHomeActiveTabName,
|
||
4 years ago
|
haveSwapsQuotes: Boolean(Object.values(swapsState.quotes || {}).length),
|
||
|
swapsFetchParams: swapsState.fetchParams,
|
||
|
showAwaitingSwapScreen: swapsState.routeState === 'awaiting',
|
||
4 years ago
|
isMainnet: getIsMainnet(state),
|
||
4 years ago
|
originOfCurrentTab,
|
||
|
shouldShowWeb3ShimUsageNotification,
|
||
4 years ago
|
pendingConfirmations,
|
||
4 years ago
|
infuraBlocked: getInfuraBlocked(state),
|
||
4 years ago
|
notificationsToShow: getSortedNotificationsToShow(state).length > 0,
|
||
|
showWhatsNewPopup: getShowWhatsNewPopup(state),
|
||
4 years ago
|
};
|
||
|
};
|
||
6 years ago
|
|
||
5 years ago
|
const mapDispatchToProps = (dispatch) => ({
|
||
5 years ago
|
turnThreeBoxSyncingOn: () => dispatch(turnThreeBoxSyncingOn()),
|
||
|
setupThreeBox: () => {
|
||
4 years ago
|
dispatch(getThreeBoxLastUpdated()).then((lastUpdated) => {
|
||
|
if (lastUpdated) {
|
||
4 years ago
|
dispatch(setThreeBoxLastUpdated(lastUpdated));
|
||
4 years ago
|
} else {
|
||
4 years ago
|
dispatch(setShowRestorePromptToFalse());
|
||
|
dispatch(turnThreeBoxSyncingOn());
|
||
4 years ago
|
}
|
||
4 years ago
|
});
|
||
5 years ago
|
},
|
||
|
restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)),
|
||
5 years ago
|
setShowRestorePromptToFalse: () => dispatch(setShowRestorePromptToFalse()),
|
||
4 years ago
|
setConnectedStatusPopoverHasBeenShown: () =>
|
||
|
dispatch(setConnectedStatusPopoverHasBeenShown()),
|
||
5 years ago
|
onTabClick: (name) => dispatch(setDefaultHomeActiveTabName(name)),
|
||
4 years ago
|
setWeb3ShimUsageAlertDismissed: (origin) =>
|
||
|
setWeb3ShimUsageAlertDismissed(origin),
|
||
|
disableWeb3ShimUsageAlert: () =>
|
||
|
setAlertEnabledness(ALERT_TYPES.web3ShimUsage, false),
|
||
4 years ago
|
hideWhatsNewPopup: () => dispatch(hideWhatsNewPopup()),
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
6 years ago
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps, mapDispatchToProps),
|
||
4 years ago
|
)(Home);
|