Ensure network info popup only displays on networks where the user has no balances (#15821)

feature/default_network_editable
Dan J Miller 2 years ago committed by GitHub
parent 17855b5df8
commit e5da67515c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      ui/pages/routes/routes.component.js
  2. 7
      ui/pages/routes/routes.container.js
  3. 10
      ui/selectors/selectors.js

@ -107,7 +107,8 @@ export default class Routes extends Component {
theme: PropTypes.string, theme: PropTypes.string,
sendStage: PropTypes.string, sendStage: PropTypes.string,
isNetworkUsed: PropTypes.bool, isNetworkUsed: PropTypes.bool,
hasAnAccountWithNoFundsOnNetwork: PropTypes.bool, allAccountsOnNetworkAreEmpty: PropTypes.bool,
isTestNet: PropTypes.bool,
}; };
static contextTypes = { static contextTypes = {
@ -363,7 +364,8 @@ export default class Routes extends Component {
browserEnvironmentOs: os, browserEnvironmentOs: os,
browserEnvironmentBrowser: browser, browserEnvironmentBrowser: browser,
isNetworkUsed, isNetworkUsed,
hasAnAccountWithNoFundsOnNetwork, allAccountsOnNetworkAreEmpty,
isTestNet,
} = this.props; } = this.props;
const loadMessage = const loadMessage =
loadingMessage || isNetworkLoading loadingMessage || isNetworkLoading
@ -371,7 +373,10 @@ export default class Routes extends Component {
: null; : null;
const shouldShowNetworkInfo = const shouldShowNetworkInfo =
isUnlocked && !isNetworkUsed && hasAnAccountWithNoFundsOnNetwork; isUnlocked &&
!isTestNet &&
!isNetworkUsed &&
allAccountsOnNetworkAreEmpty;
const windowType = getEnvironmentType(); const windowType = getEnvironmentType();

@ -2,12 +2,13 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom'; import { withRouter } from 'react-router-dom';
import { compose } from 'redux'; import { compose } from 'redux';
import { import {
getHasAnyAccountWithNoFundsOnNetwork, getAllAccountsOnNetworkAreEmpty,
getIsNetworkUsed, getIsNetworkUsed,
getNetworkIdentifier, getNetworkIdentifier,
getPreferences, getPreferences,
isNetworkLoading, isNetworkLoading,
getTheme, getTheme,
getIsTestnet,
} from '../../selectors'; } from '../../selectors';
import { import {
lockMetamask, lockMetamask,
@ -43,8 +44,8 @@ function mapStateToProps(state) {
theme: getTheme(state), theme: getTheme(state),
sendStage: getSendStage(state), sendStage: getSendStage(state),
isNetworkUsed: getIsNetworkUsed(state), isNetworkUsed: getIsNetworkUsed(state),
hasAnAccountWithNoFundsOnNetwork: allAccountsOnNetworkAreEmpty: getAllAccountsOnNetworkAreEmpty(state),
getHasAnyAccountWithNoFundsOnNetwork(state), isTestnet: getIsTestnet(state),
}; };
} }

@ -1194,10 +1194,12 @@ export function getIsNetworkUsed(state) {
return Boolean(usedNetworks[chainId]); return Boolean(usedNetworks[chainId]);
} }
export function getHasAnyAccountWithNoFundsOnNetwork(state) { export function getAllAccountsOnNetworkAreEmpty(state) {
const balances = getMetaMaskCachedBalances(state) ?? {}; const balances = getMetaMaskCachedBalances(state) ?? {};
const hasAnAccountWithNoFundsOnNetwork = const hasNoNativeFundsOnAnyAccounts = Object.values(balances).every(
Object.values(balances).indexOf('0x0'); (balance) => balance === '0x0' || balance === '0x00',
);
const hasNoTokens = getNumberOfTokens(state) === 0;
return hasAnAccountWithNoFundsOnNetwork !== -1; return hasNoNativeFundsOnAnyAccounts && hasNoTokens;
} }

Loading…
Cancel
Save