1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-24 04:13:27 +02:00
metamask-extension/ui/app/pages/home/home.container.js
Dan J Miller b73f543b23
Whats new popup (#10583)
* Add 'What's New' notification popup

* Move selectors from shared/notifications into ui/ directory

* Use keys for localized message in whats new notifications objects, to ensure notifications will be translated.

* Remove unused swaps intro popup locale messages

* Fix keys of whats new notification locales

* Remove notifications messages and descriptions from comment in shared/notifications

* Move notifcationActionFunctions to shared/notifications and make it stateless

* Get notification data from constants instead of state in whats-new-popup

* Code cleanup

* Fix build quote reference to swapsEthToken, broken during rebase

* Rename notificationFilters to notificationToExclude to clarify its purpose

* Documentation for getSortedNotificationsToShow

* Move notification action functions from shared/ to whats-new-popup.js

* Stop setting swapsWelcomeMessageHasBeenShown to state in app-state controller

* Update e2e tests for whats new popup changes

* Updating migration files

* Addressing feedback part 1

* Addressing feedback part 2

* Remove unnecessary div in whats-new-popup

* Change getNotificationsToExclude to getNotificationsToInclude for use in the getSortedNotificationsToShow selector

* Delete intro-popup directory and test files

* Lint fix

* Add notifiction state to address-entry fixture

* Use two separate functions for rendering first and subsequent notifications in the whats-new-popup

* Ensure that string literals are passed to t for whats new popup text

* Update import-ui fixtures to include notificaiton controller state

* Remove unnecessary, accidental change confirm-approve

* Remove swaps notification in favour of mobile swaps as first notifcation and TBD 3rd notification

* Update whats-new-popup to use intersection observer api to detect if notification has been seen

* Add notifications to send-edit and threebox e2e test fixtures

* Update ui/app/selectors/selectors.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* Update ui/app/selectors/selectors.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* Clean up locale code for whats-new-popup notifications

* Disconnect observers in whats-new-popup when their callback is first called

* Add test case for migration 58 for when the AppStateController does not exist

* Rename popover components containerRef to popoverWrapRef

* Fix messages.json

* Update notification messages and images

* Rename popoverWrapRef -> popoverRef in whats-new-popup and popover.component

* Only create one observer, and only after images have loaded, in whats-new-popup

* Set width and height on whats-new-popup image, instead of setting state on img load

* Update ui/app/components/app/whats-new-popup/whats-new-popup.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* Code clean up in whats new popup re: notification rendering and action functions

* Code cleanup in render notification functions of whats-new-popup

* Update ui/app/components/app/whats-new-popup/whats-new-popup.js

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

* lint fix

* Update and localize  notification dates

* Clean up date code in shred/notifications/index.js

Co-authored-by: ryanml <ryanlanese@gmail.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-04-28 14:21:41 -02:30

139 lines
4.6 KiB
JavaScript

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