2021-02-04 19:15:23 +01:00
|
|
|
import { compose } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2023-05-08 16:09:00 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
import {
|
|
|
|
getMmiPortfolioEnabled,
|
|
|
|
getMmiPortfolioUrl,
|
|
|
|
} from '@metamask-institutional/portfolio-dashboard';
|
|
|
|
import { mmiActionsFactory } from '../../store/institutional/institution-background';
|
|
|
|
import { getWaitForConfirmDeepLinkDialog } from '../../selectors/institutional/selectors';
|
|
|
|
import { getInstitutionalConnectRequests } from '../../ducks/institutional/institutional';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
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
|
|
|
getFirstPermissionRequest,
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-09-20 14:46:25 +02:00
|
|
|
getFirstSnapInstallOrUpdateRequest,
|
2022-08-03 18:02:44 +02:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
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,
|
2021-04-15 19:41:40 +02:00
|
|
|
getInfuraBlocked,
|
2021-04-28 18:51:41 +02:00
|
|
|
getShowWhatsNewPopup,
|
2022-04-27 10:36:32 +02:00
|
|
|
getSortedAnnouncementsToShow,
|
2021-06-05 08:33:58 +02:00
|
|
|
getShowRecoveryPhraseReminder,
|
2023-04-14 18:51:13 +02:00
|
|
|
getShowTermsOfUse,
|
2023-02-02 19:56:41 +01:00
|
|
|
getShowOutdatedBrowserWarning,
|
2021-10-25 22:38:43 +02:00
|
|
|
getNewNetworkAdded,
|
2021-11-23 18:28:39 +01:00
|
|
|
hasUnsignedQRHardwareTransaction,
|
|
|
|
hasUnsignedQRHardwareMessage,
|
2023-02-16 20:23:29 +01:00
|
|
|
getNewNftAddedMessage,
|
2022-05-09 19:47:06 +02:00
|
|
|
getNewTokensImported,
|
2022-09-19 19:40:30 +02:00
|
|
|
getShouldShowSeedPhraseReminder,
|
2023-02-16 20:23:29 +01:00
|
|
|
getRemoveNftMessage,
|
2023-06-15 22:18:12 +02:00
|
|
|
getSuggestedTokens,
|
|
|
|
getSuggestedNfts,
|
2023-06-29 17:51:56 +02:00
|
|
|
getApprovalFlows,
|
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 {
|
2022-01-05 18:09:19 +01:00
|
|
|
closeNotificationPopup,
|
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,
|
2023-04-14 18:51:13 +02:00
|
|
|
setTermsOfUseLastAgreed,
|
2023-02-02 19:56:41 +01:00
|
|
|
setOutdatedBrowserWarningLastShown,
|
2021-10-25 22:38:43 +02:00
|
|
|
setNewNetworkAdded,
|
2023-02-16 20:23:29 +01:00
|
|
|
setNewNftAddedMessage,
|
|
|
|
setRemoveNftMessage,
|
2022-05-09 19:47:06 +02:00
|
|
|
setNewTokensImported,
|
2023-03-09 22:00:28 +01:00
|
|
|
setActiveNetwork,
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-02-15 01:02:51 +01:00
|
|
|
removeSnapError,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
2023-03-09 22:00:28 +01:00
|
|
|
import { 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';
|
2023-02-02 19:56:41 +01:00
|
|
|
import { getIsBrowserDeprecated } from '../../helpers/utils/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 {
|
2023-01-27 19:28:03 +01:00
|
|
|
AlertTypes,
|
|
|
|
Web3ShimUsageAlertStates,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../shared/constants/alerts';
|
2023-05-11 07:56:17 +02:00
|
|
|
import { hasTransactionPendingApprovals } from '../../selectors/transactions';
|
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 {
|
2019-08-02 05:57:26 +02:00
|
|
|
seedPhraseBackedUp,
|
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,
|
2022-03-21 18:57:59 +01:00
|
|
|
firstTimeFlowType,
|
|
|
|
completedOnboarding,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = metamask;
|
2023-02-02 17:46:22 +01:00
|
|
|
const { forgottenPassword } = metamask;
|
2021-02-04 19:15:23 +01:00
|
|
|
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);
|
2023-05-08 16:09:00 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
const institutionalConnectRequests = getInstitutionalConnectRequests(state);
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
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
|
|
|
|
2022-08-03 18:02:44 +02:00
|
|
|
let firstPermissionsRequest, firstPermissionsRequestId;
|
|
|
|
firstPermissionsRequest = getFirstPermissionRequest(state);
|
|
|
|
firstPermissionsRequestId = firstPermissionsRequest?.metadata.id || null;
|
|
|
|
|
|
|
|
// getFirstPermissionRequest should be updated with snap update logic once we hit main extension release
|
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-08-03 18:02:44 +02:00
|
|
|
if (!firstPermissionsRequest) {
|
2022-09-20 14:46:25 +02:00
|
|
|
firstPermissionsRequest = getFirstSnapInstallOrUpdateRequest(state);
|
2022-08-03 18:02:44 +02:00
|
|
|
firstPermissionsRequestId = firstPermissionsRequest?.metadata.id || null;
|
|
|
|
}
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
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) ===
|
2023-01-27 19:28:03 +01:00
|
|
|
Web3ShimUsageAlertStates.recorded;
|
2020-12-11 00:40:29 +01:00
|
|
|
|
2021-11-23 18:28:39 +01:00
|
|
|
const isSigningQRHardwareTransaction =
|
|
|
|
hasUnsignedQRHardwareTransaction(state) ||
|
|
|
|
hasUnsignedQRHardwareMessage(state);
|
|
|
|
|
2023-06-15 22:18:12 +02:00
|
|
|
const hasWatchTokenPendingApprovals = getSuggestedTokens(state).length > 0;
|
|
|
|
|
|
|
|
const hasWatchNftPendingApprovals = getSuggestedNfts(state).length > 0;
|
2023-04-25 11:47:49 +02:00
|
|
|
|
2018-07-24 20:40:05 +02:00
|
|
|
return {
|
|
|
|
forgottenPassword,
|
2023-06-15 22:18:12 +02:00
|
|
|
hasWatchTokenPendingApprovals,
|
|
|
|
hasWatchNftPendingApprovals,
|
2020-10-06 20:28:38 +02:00
|
|
|
swapsEnabled,
|
2023-05-11 07:56:17 +02:00
|
|
|
hasTransactionPendingApprovals: hasTransactionPendingApprovals(state),
|
2022-09-19 19:40:30 +02:00
|
|
|
shouldShowSeedPhraseReminder: getShouldShowSeedPhraseReminder(state),
|
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
|
|
|
selectedAddress,
|
2019-12-05 22:05:50 +01:00
|
|
|
firstPermissionsRequestId,
|
2020-04-20 19:21:57 +02:00
|
|
|
totalUnapprovedCount,
|
2023-07-13 10:42:08 +02:00
|
|
|
hasApprovalFlows:
|
|
|
|
Array.isArray(getApprovalFlows) && getApprovalFlows(state).length > 0,
|
2020-04-22 19:11:36 +02:00
|
|
|
connectedStatusPopoverHasBeenShown,
|
2020-05-25 21:01:28 +02:00
|
|
|
defaultHomeActiveTabName,
|
2022-03-21 18:57:59 +01:00
|
|
|
firstTimeFlowType,
|
|
|
|
completedOnboarding,
|
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),
|
2022-06-01 19:09:13 +02:00
|
|
|
announcementsToShow: getSortedAnnouncementsToShow(state).length > 0,
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-02-15 01:02:51 +01:00
|
|
|
errorsToShow: metamask.snapErrors,
|
|
|
|
shouldShowErrors: Object.entries(metamask.snapErrors || []).length > 0,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-04-28 18:51:41 +02:00
|
|
|
showWhatsNewPopup: getShowWhatsNewPopup(state),
|
2021-06-05 08:33:58 +02:00
|
|
|
showRecoveryPhraseReminder: getShowRecoveryPhraseReminder(state),
|
2023-04-14 18:51:13 +02:00
|
|
|
showTermsOfUsePopup: getShowTermsOfUse(state),
|
2023-02-02 19:56:41 +01:00
|
|
|
showOutdatedBrowserWarning:
|
|
|
|
getIsBrowserDeprecated() && getShowOutdatedBrowserWarning(state),
|
2021-06-05 08:33:58 +02:00
|
|
|
seedPhraseBackedUp,
|
2023-03-09 22:00:28 +01:00
|
|
|
newNetworkAddedName: getNewNetworkAdded(state),
|
2021-11-23 18:28:39 +01:00
|
|
|
isSigningQRHardwareTransaction,
|
2023-02-16 20:23:29 +01:00
|
|
|
newNftAddedMessage: getNewNftAddedMessage(state),
|
|
|
|
removeNftMessage: getRemoveNftMessage(state),
|
2022-05-09 19:47:06 +02:00
|
|
|
newTokensImported: getNewTokensImported(state),
|
2023-03-09 22:00:28 +01:00
|
|
|
newNetworkAddedConfigurationId: appState.newNetworkAddedConfigurationId,
|
2022-10-04 17:52:42 +02:00
|
|
|
onboardedInThisUISession: appState.onboardedInThisUISession,
|
2023-05-08 16:09:00 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
waitForConfirmDeepLinkDialog: getWaitForConfirmDeepLinkDialog(state),
|
|
|
|
institutionalConnectRequests,
|
|
|
|
modalOpen: state.appState.modal.open,
|
|
|
|
mmiPortfolioUrl: getMmiPortfolioUrl(state),
|
|
|
|
mmiPortfolioEnabled: getMmiPortfolioEnabled(state),
|
|
|
|
notificationsToShow: getSortedAnnouncementsToShow(state).length > 0,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-07-24 20:40:05 +02:00
|
|
|
|
2023-05-08 16:09:00 +02:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
const mmiActions = mmiActionsFactory();
|
2022-02-15 01:02:51 +01:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
2023-05-08 16:09:00 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
closeNotificationPopup: () => closeNotificationPopup(),
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
|
|
|
removeSnapError: async (id) => await removeSnapError(id),
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
setConnectedStatusPopoverHasBeenShown: () =>
|
|
|
|
dispatch(setConnectedStatusPopoverHasBeenShown()),
|
|
|
|
onTabClick: (name) => dispatch(setDefaultHomeActiveTabName(name)),
|
|
|
|
setWeb3ShimUsageAlertDismissed: (origin) =>
|
|
|
|
setWeb3ShimUsageAlertDismissed(origin),
|
|
|
|
disableWeb3ShimUsageAlert: () =>
|
|
|
|
setAlertEnabledness(AlertTypes.web3ShimUsage, false),
|
|
|
|
hideWhatsNewPopup: () => dispatch(hideWhatsNewPopup()),
|
|
|
|
setRecoveryPhraseReminderHasBeenShown: () =>
|
|
|
|
dispatch(setRecoveryPhraseReminderHasBeenShown()),
|
|
|
|
setRecoveryPhraseReminderLastShown: (lastShown) =>
|
|
|
|
dispatch(setRecoveryPhraseReminderLastShown(lastShown)),
|
|
|
|
setTermsOfUseLastAgreed: (lastAgreed) => {
|
|
|
|
dispatch(setTermsOfUseLastAgreed(lastAgreed));
|
|
|
|
},
|
|
|
|
setOutdatedBrowserWarningLastShown: (lastShown) => {
|
|
|
|
dispatch(setOutdatedBrowserWarningLastShown(lastShown));
|
|
|
|
},
|
|
|
|
setNewNftAddedMessage: (message) => {
|
|
|
|
dispatch(setRemoveNftMessage(''));
|
|
|
|
dispatch(setNewNftAddedMessage(message));
|
|
|
|
},
|
|
|
|
setRemoveNftMessage: (message) => {
|
|
|
|
dispatch(setNewNftAddedMessage(''));
|
|
|
|
dispatch(setRemoveNftMessage(message));
|
|
|
|
},
|
|
|
|
setNewTokensImported: (newTokens) => {
|
|
|
|
dispatch(setNewTokensImported(newTokens));
|
|
|
|
},
|
|
|
|
clearNewNetworkAdded: () => {
|
|
|
|
dispatch(setNewNetworkAdded({}));
|
|
|
|
},
|
|
|
|
setActiveNetwork: (networkConfigurationId) => {
|
|
|
|
dispatch(setActiveNetwork(networkConfigurationId));
|
|
|
|
},
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
|
|
setWaitForConfirmDeepLinkDialog: (wait) =>
|
|
|
|
dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(wait)),
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
};
|
|
|
|
};
|
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);
|