1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

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

This commit is contained in:
Dan J Miller 2022-09-14 13:05:59 -02:30 committed by GitHub
parent 17855b5df8
commit e5da67515c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View File

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

View File

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

View File

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