From 1bbeb80dff765c9948f72a67687667b5fde3e3ba Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Mon, 19 Sep 2022 15:10:30 -0230 Subject: [PATCH] Ensure the seed phrase reminder is displayed with precedence over the network deprecation warning (#15869) * Ensure the seed phrase reminder is displayed with precedence over the network deprecation message * Prevent error when attempting to get balance before account info has been fully sete * Fix implementation of seedphrase-reminder-display-fix * Prioritize seed phrase reminder notification over portfolio tooltip, and that tooltip over testnet deprecation --- ui/pages/home/home.component.js | 7 ++++++- ui/pages/home/home.container.js | 10 ++-------- ui/pages/routes/routes.component.js | 14 +++++++++++--- ui/pages/routes/routes.container.js | 4 ++++ ui/selectors/selectors.js | 13 ++++++++++++- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index ccd454eed..e82a623de 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -612,6 +612,7 @@ export default class Home extends PureComponent { showRecoveryPhraseReminder, firstTimeFlowType, completedOnboarding, + shouldShowSeedPhraseReminder, } = this.props; if (forgottenPassword) { @@ -658,7 +659,11 @@ export default class Home extends PureComponent { subHeader={ { const { suggestedAssets, seedPhraseBackedUp, - tokens, threeBoxSynced, showRestorePrompt, selectedAddress, connectedStatusPopoverHasBeenShown, defaultHomeActiveTabName, swapsState, - dismissSeedBackUpReminder, firstTimeFlowType, completedOnboarding, } = metamask; - const accountBalance = getCurrentEthBalance(state); const { forgottenPassword, threeBoxLastUpdated } = appState; const totalUnapprovedCount = getTotalUnapprovedCount(state); const swapsEnabled = getSwapsFeatureIsLive(state); @@ -123,10 +120,7 @@ const mapStateToProps = (state) => { suggestedAssets, swapsEnabled, unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state), - shouldShowSeedPhraseReminder: - seedPhraseBackedUp === false && - (parseInt(accountBalance, 16) > 0 || tokens.length > 0) && - dismissSeedBackUpReminder === false, + shouldShowSeedPhraseReminder: getShouldShowSeedPhraseReminder(state), isPopup, isNotification, threeBoxSynced, diff --git a/ui/pages/routes/routes.component.js b/ui/pages/routes/routes.component.js index b2f484866..211f0035e 100644 --- a/ui/pages/routes/routes.component.js +++ b/ui/pages/routes/routes.component.js @@ -110,6 +110,8 @@ export default class Routes extends Component { allAccountsOnNetworkAreEmpty: PropTypes.bool, isTestNet: PropTypes.bool, currentChainId: PropTypes.string, + shouldShowSeedPhraseReminder: PropTypes.bool, + portfolioTooltipIsBeingShown: PropTypes.bool, }; static contextTypes = { @@ -368,6 +370,8 @@ export default class Routes extends Component { allAccountsOnNetworkAreEmpty, isTestNet, currentChainId, + shouldShowSeedPhraseReminder, + portfolioTooltipIsBeingShown, } = this.props; const loadMessage = loadingMessage || isNetworkLoading @@ -383,6 +387,12 @@ export default class Routes extends Component { const windowType = getEnvironmentType(); + const shouldShowNetworkDeprecationWarning = + windowType !== ENVIRONMENT_TYPE_NOTIFICATION && + isUnlocked && + !shouldShowSeedPhraseReminder && + !portfolioTooltipIsBeingShown; + return (
- {windowType !== ENVIRONMENT_TYPE_NOTIFICATION && isUnlocked && ( - - )} + {shouldShowNetworkDeprecationWarning && } {shouldShowNetworkInfo && } diff --git a/ui/pages/routes/routes.container.js b/ui/pages/routes/routes.container.js index b70872e64..496a8f2a8 100644 --- a/ui/pages/routes/routes.container.js +++ b/ui/pages/routes/routes.container.js @@ -10,6 +10,8 @@ import { getTheme, getIsTestnet, getCurrentChainId, + getShouldShowSeedPhraseReminder, + getShowPortfolioTooltip, } from '../../selectors'; import { lockMetamask, @@ -48,6 +50,8 @@ function mapStateToProps(state) { allAccountsOnNetworkAreEmpty: getAllAccountsOnNetworkAreEmpty(state), isTestNet: getIsTestnet(state), currentChainId: getCurrentChainId(state), + shouldShowSeedPhraseReminder: getShouldShowSeedPhraseReminder(state), + portfolioTooltipIsBeingShown: getShowPortfolioTooltip(state), }; } diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 471d30886..bbaa5f874 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -442,7 +442,7 @@ export function getTargetAccountWithSendEtherInfo(state, targetAddress) { } export function getCurrentEthBalance(state) { - return getCurrentAccountWithSendEtherInfo(state).balance; + return getCurrentAccountWithSendEtherInfo(state)?.balance; } export function getGasIsLoading(state) { @@ -1209,3 +1209,14 @@ export function getAllAccountsOnNetworkAreEmpty(state) { return hasNoNativeFundsOnAnyAccounts && hasNoTokens; } + +export function getShouldShowSeedPhraseReminder(state) { + const { tokens, seedPhraseBackedUp, dismissSeedBackUpReminder } = + state.metamask; + const accountBalance = getCurrentEthBalance(state) ?? 0; + return ( + seedPhraseBackedUp === false && + (parseInt(accountBalance, 16) > 0 || tokens.length > 0) && + dismissSeedBackUpReminder === false + ); +}