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
|
|
|
getFirstPermissionRequest,
|
2022-08-03 18:02:44 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
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,
|
|
|
|
unconfirmedTransactionsCountSelector,
|
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-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,
|
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-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,
|
2022-06-30 18:19:07 +02:00
|
|
|
setRpcTarget,
|
2022-02-15 01:02:51 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
removeSnapError,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../store/actions';
|
2022-06-30 18:19:07 +02:00
|
|
|
import {
|
|
|
|
hideWhatsNewPopup,
|
|
|
|
setNewCustomNetworkAdded,
|
|
|
|
} 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';
|
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-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);
|
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
|
|
|
|
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
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);
|
|
|
|
|
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),
|
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,
|
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,
|
2022-02-15 01:02:51 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
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-02-02 19:56:41 +01:00
|
|
|
showOutdatedBrowserWarning:
|
|
|
|
getIsBrowserDeprecated() && getShowOutdatedBrowserWarning(state),
|
2021-06-05 08:33:58 +02:00
|
|
|
seedPhraseBackedUp,
|
2021-10-25 22:38:43 +02:00
|
|
|
newNetworkAdded: 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),
|
2022-06-30 18:19:07 +02:00
|
|
|
newCustomNetworkAdded: appState.newCustomNetworkAdded,
|
2022-10-04 17:52:42 +02:00
|
|
|
onboardedInThisUISession: appState.onboardedInThisUISession,
|
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) => ({
|
2022-01-05 18:09:19 +01:00
|
|
|
closeNotificationPopup: () => closeNotificationPopup(),
|
2022-02-15 01:02:51 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
removeSnapError: async (id) => await removeSnapError(id),
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
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: () =>
|
2023-01-27 19:28:03 +01:00
|
|
|
setAlertEnabledness(AlertTypes.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)),
|
2023-02-02 19:56:41 +01:00
|
|
|
setOutdatedBrowserWarningLastShown: (lastShown) => {
|
|
|
|
dispatch(setOutdatedBrowserWarningLastShown(lastShown));
|
|
|
|
},
|
2021-10-25 22:38:43 +02:00
|
|
|
setNewNetworkAdded: (newNetwork) => {
|
2023-01-31 13:01:10 +01:00
|
|
|
console.log({ newNetwork });
|
2021-10-25 22:38:43 +02:00
|
|
|
dispatch(setNewNetworkAdded(newNetwork));
|
|
|
|
},
|
2023-02-16 20:23:29 +01:00
|
|
|
setNewNftAddedMessage: (message) => {
|
2023-02-22 18:14:47 +01:00
|
|
|
dispatch(setRemoveNftMessage(''));
|
2023-02-16 20:23:29 +01:00
|
|
|
dispatch(setNewNftAddedMessage(message));
|
2021-11-26 21:03:35 +01:00
|
|
|
},
|
2023-02-16 20:23:29 +01:00
|
|
|
setRemoveNftMessage: (message) => {
|
2023-02-22 18:14:47 +01:00
|
|
|
dispatch(setNewNftAddedMessage(''));
|
2023-02-16 20:23:29 +01:00
|
|
|
dispatch(setRemoveNftMessage(message));
|
2023-01-23 12:53:44 +01:00
|
|
|
},
|
2022-05-09 19:47:06 +02:00
|
|
|
setNewTokensImported: (newTokens) => {
|
|
|
|
dispatch(setNewTokensImported(newTokens));
|
|
|
|
},
|
2022-07-27 22:19:05 +02:00
|
|
|
clearNewCustomNetworkAdded: () => {
|
2022-06-30 18:19:07 +02:00
|
|
|
dispatch(setNewCustomNetworkAdded({}));
|
|
|
|
},
|
|
|
|
setRpcTarget: (rpcUrl, chainId, ticker, nickname) => {
|
|
|
|
dispatch(setRpcTarget(rpcUrl, chainId, ticker, nickname));
|
|
|
|
},
|
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);
|