From 7ebd561ff9cf84fc8c04dfbf8e69f6589c038e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Regadas?= Date: Mon, 8 May 2023 15:09:00 +0100 Subject: [PATCH] [MMI] adds mmi logic in home view (#18960) * adds mmi logic to home container * adds code fences to home component * adds code fences to home component * lint fix * lint fix * updates fences and runs prettier * version bump * clean up code fence --- package.json | 1 + ui/pages/home/home.component.js | 156 ++++++++++++++++++++++++++++---- ui/pages/home/home.container.js | 110 ++++++++++++++-------- yarn.lock | 8 ++ 4 files changed, 216 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index a66a79c11..e878e91a8 100644 --- a/package.json +++ b/package.json @@ -231,6 +231,7 @@ "@keystonehq/metamask-airgapped-keyring": "^0.9.2", "@lavamoat/snow": "^1.5.0", "@material-ui/core": "^4.11.0", + "@metamask-institutional/portfolio-dashboard": "1.1.2", "@metamask/address-book-controller": "^2.0.0", "@metamask/announcement-controller": "^3.0.0", "@metamask/approval-controller": "^2.1.0", diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index e32d6ebee..6bcb8532e 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -55,9 +55,14 @@ import { CONFIRMATION_V_NEXT_ROUTE, ADD_NFT_ROUTE, ONBOARDING_SECURE_YOUR_WALLET_ROUTE, + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + CONFIRM_INSTITUTIONAL_FEATURE_CONNECT, + CONFIRM_ADD_CUSTODIAN_TOKEN, + INTERACTIVE_REPLACEMENT_TOKEN_PAGE, + ///: END:ONLY_INCLUDE_IN } from '../../helpers/constants/routes'; import ZENDESK_URLS from '../../helpers/constants/zendesk-url'; -///: BEGIN:ONLY_INCLUDE_IN(build-main) +///: BEGIN:ONLY_INCLUDE_IN(build-main,build-mmi) import { SUPPORT_LINK } from '../../../shared/lib/ui-utils'; ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(build-beta) @@ -71,12 +76,25 @@ function shouldCloseNotificationPopup({ isNotification, totalUnapprovedCount, isSigningQRHardwareTransaction, + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + waitForConfirmDeepLinkDialog, + institutionalConnectRequests, + ///: END:ONLY_INCLUDE_IN }) { - return ( + let shouldCLose = isNotification && totalUnapprovedCount === 0 && - !isSigningQRHardwareTransaction - ); + !isSigningQRHardwareTransaction; + + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + shouldCLose &&= + // MMI User must be shown a deeplink + !waitForConfirmDeepLinkDialog && + // MMI User is connecting to custodian or compliance + institutionalConnectRequests.length === 0; + ///: END:ONLY_INCLUDE_IN + + return shouldCLose; } export default class Home extends PureComponent { @@ -152,6 +170,14 @@ export default class Home extends PureComponent { clearNewNetworkAdded: PropTypes.func, setActiveNetwork: PropTypes.func, onboardedInThisUISession: PropTypes.bool, + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + institutionalConnectRequests: PropTypes.arrayOf(PropTypes.object), + mmiPortfolioEnabled: PropTypes.bool, + mmiPortfolioUrl: PropTypes.string, + modalOpen: PropTypes.bool, + setWaitForConfirmDeepLinkDialog: PropTypes.func, + waitForConfirmDeepLinkDialog: PropTypes.bool, + ///: END:ONLY_INCLUDE_IN }; state = { @@ -188,6 +214,55 @@ export default class Home extends PureComponent { } } + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + checkInstitutionalConnectRequest() { + const { history, institutionalConnectRequests } = this.props; + if ( + institutionalConnectRequests && + institutionalConnectRequests.length > 0 && + institutionalConnectRequests[0].feature === 'custodian' + ) { + if ( + institutionalConnectRequests[0].method === + 'metamaskinstitutional_reauthenticate' + ) { + history.push(INTERACTIVE_REPLACEMENT_TOKEN_PAGE); + } else if ( + institutionalConnectRequests[0].method === + 'metamaskinstitutional_authenticate' + ) { + history.push(CONFIRM_ADD_CUSTODIAN_TOKEN); + } + } else if ( + institutionalConnectRequests && + institutionalConnectRequests.length > 0 && + institutionalConnectRequests[0].feature !== 'custodian' + ) { + history.push(CONFIRM_INSTITUTIONAL_FEATURE_CONNECT); + } + } + + shouldCloseCurrentWindow() { + const { + isNotification, + modalOpen, + totalUnapprovedCount, + institutionalConnectRequests, + waitForConfirmDeepLinkDialog, + } = this.props; + + if ( + isNotification && + totalUnapprovedCount === 0 && + institutionalConnectRequests.length === 0 && + !waitForConfirmDeepLinkDialog && + !modalOpen + ) { + global.platform.closeCurrentWindow(); + } + } + ///: END:ONLY_INCLUDE_IN + checkStatusAndNavigate() { const { firstPermissionsRequestId, @@ -200,6 +275,11 @@ export default class Home extends PureComponent { swapsFetchParams, pendingConfirmations, } = this.props; + + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + this.shouldCloseCurrentWindow(); + ///: END:ONLY_INCLUDE_IN + if (!isNotification && showAwaitingSwapScreen) { history.push(AWAITING_SWAP_ROUTE); } else if (!isNotification && haveSwapsQuotes) { @@ -215,10 +295,22 @@ export default class Home extends PureComponent { } else if (pendingConfirmations.length > 0) { history.push(CONFIRMATION_V_NEXT_ROUTE); } + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + this.checkInstitutionalConnectRequest(); + ///: END:ONLY_INCLUDE_IN } componentDidMount() { this.checkStatusAndNavigate(); + + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + const { setWaitForConfirmDeepLinkDialog } = this.props; + + window.addEventListener('beforeunload', () => { + // If user closes notification window manually, change waitForConfirmDeepLinkDialog to false + setWaitForConfirmDeepLinkDialog(false); + }); + ///: END:ONLY_INCLUDE_IN } static getDerivedStateFromProps(props) { @@ -625,6 +717,10 @@ export default class Home extends PureComponent { completedOnboarding, onboardedInThisUISession, newNetworkAddedConfigurationId, + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + mmiPortfolioEnabled, + mmiPortfolioUrl, + ///: END:ONLY_INCLUDE_IN } = this.props; if (forgottenPassword) { @@ -653,6 +749,9 @@ export default class Home extends PureComponent { exact />
+ { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) + } {showWhatsNew ? : null} {!showWhatsNew && showRecoveryPhraseReminder ? ( {process.env.MULTICHAIN ? null : }
- + { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) + + ///: END:ONLY_INCLUDE_IN + } + { + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + + ///: END:ONLY_INCLUDE_IN + }
- - { - history.push(ADD_NFT_ROUTE); - }} - /> - + { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) + + { + history.push(ADD_NFT_ROUTE); + }} + /> + + ///: END:ONLY_INCLUDE_IN + }
{ - ///: BEGIN:ONLY_INCLUDE_IN(build-main) + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-mmi) t('needHelp', [ { const totalUnapprovedCount = getTotalUnapprovedCount(state); const swapsEnabled = getSwapsFeatureIsLive(state); const pendingConfirmations = getUnapprovedTemplatedConfirmations(state); + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + const institutionalConnectRequests = getInstitutionalConnectRequests(state); + ///: END:ONLY_INCLUDE_IN const envType = getEnvironmentType(); const isPopup = envType === ENVIRONMENT_TYPE_POPUP; @@ -155,50 +167,68 @@ const mapStateToProps = (state) => { newTokensImported: getNewTokensImported(state), newNetworkAddedConfigurationId: appState.newNetworkAddedConfigurationId, onboardedInThisUISession: appState.onboardedInThisUISession, + ///: 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 }; }; -const mapDispatchToProps = (dispatch) => ({ - closeNotificationPopup: () => closeNotificationPopup(), - ///: BEGIN:ONLY_INCLUDE_IN(snaps) - removeSnapError: async (id) => await removeSnapError(id), +const mapDispatchToProps = (dispatch) => { + ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) + const mmiActions = mmiActionsFactory(); ///: 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)); - }, -}); + + 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 + }; +}; export default compose( withRouter, diff --git a/yarn.lock b/yarn.lock index 8b87ccdc8..aab21f545 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3614,6 +3614,13 @@ __metadata: languageName: node linkType: hard +"@metamask-institutional/portfolio-dashboard@npm:1.1.2": + version: 1.1.2 + resolution: "@metamask-institutional/portfolio-dashboard@npm:1.1.2" + checksum: f2e1ec83fe0411f4d2e67dfdf2183f89667f34ae862425ece7b5cd0f4099eb7ae091910d67a3f15b7b5982e87bc80e9f668c25072c3bc5a977377fce14357cd3 + languageName: node + linkType: hard + "@metamask/abi-utils@npm:^1.1.0": version: 1.1.1 resolution: "@metamask/abi-utils@npm:1.1.1" @@ -24173,6 +24180,7 @@ __metadata: "@lavamoat/lavapack": ^5.0.0 "@lavamoat/snow": ^1.5.0 "@material-ui/core": ^4.11.0 + "@metamask-institutional/portfolio-dashboard": 1.1.2 "@metamask/address-book-controller": ^2.0.0 "@metamask/announcement-controller": ^3.0.0 "@metamask/approval-controller": ^2.1.0