Skip to content

Commit

Permalink
fix: wrong network shown in unknown network badge when popular networ…
Browse files Browse the repository at this point in the history
…ks filtered
  • Loading branch information
nickewansmith committed Jan 30, 2025
1 parent 3d13811 commit 99c6f19
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions app/components/UI/AssetOverview/Balance/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { useStyles } from '../../../../component-library/hooks';
import styleSheet from './Balance.styles';
import AssetElement from '../../AssetElement';
import { useSelector } from 'react-redux';
import { selectNetworkName } from '../../../../selectors/networkInfos';
import { selectChainId } from '../../../../selectors/networkController';
import {
selectChainId,
selectNetworkConfigurationByChainId,
} from '../../../../selectors/networkController';
import {
getTestNetImageByChainId,
getDefaultNetworkByChainId,
Expand Down Expand Up @@ -35,6 +37,7 @@ import {
UnpopularNetworkList,
CustomNetworkImgMapping,
} from '../../../../util/networks/customNetworks';
import { RootState } from '../../../../reducers';

interface BalanceProps {
asset: TokenI;
Expand Down Expand Up @@ -91,7 +94,9 @@ export const NetworkBadgeSource = (chainId: Hex, ticker: string) => {
const Balance = ({ asset, mainBalance, secondaryBalance }: BalanceProps) => {
const { styles } = useStyles(styleSheet, {});
const navigation = useNavigation();
const networkName = useSelector(selectNetworkName);
const networkConfigurationByChainId = useSelector((state: RootState) =>
selectNetworkConfigurationByChainId(state, asset.chainId as Hex),
);
const chainId = useSelector(selectChainId);

const tokenChainId = isPortfolioViewEnabled() ? asset.chainId : chainId;
Expand Down Expand Up @@ -156,7 +161,7 @@ const Balance = ({ asset, mainBalance, secondaryBalance }: BalanceProps) => {
<Badge
variant={BadgeVariant.Network}
imageSource={NetworkBadgeSource(tokenChainId as Hex, ticker)}
name={networkName || ''}
name={networkConfigurationByChainId?.name}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Text, {
import { useStyles } from '../../../../../component-library/hooks';
import AssetElement from '../../../AssetElement';
import NetworkMainAssetLogo from '../../../NetworkMainAssetLogo';
import { selectNetworkName } from '../../../../../selectors/networkInfos';
import { useSelector } from 'react-redux';
import styleSheet from './StakingBalance.styles';
import { View } from 'react-native';
Expand Down Expand Up @@ -48,6 +47,8 @@ import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics';
import { EVENT_LOCATIONS, EVENT_PROVIDERS } from '../../constants/events';
import NetworkAssetLogo from '../../../NetworkAssetLogo';
import { isPortfolioViewEnabled } from '../../../../../util/networks';
import { selectNetworkConfigurationByChainId } from '../../../../../selectors/networkController';
import { RootState } from '../../../../../reducers';

export interface StakingBalanceProps {
asset: TokenI;
Expand All @@ -61,7 +62,9 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => {
setHasSentViewingStakingRewardsMetric,
] = useState(false);

const networkName = useSelector(selectNetworkName);
const networkConfigurationByChainId = useSelector((state: RootState) =>
selectNetworkConfigurationByChainId(state, asset.chainId as Hex),
);

const { isEligible: isEligibleForPooledStaking } = useStakingEligibility();

Expand Down Expand Up @@ -216,7 +219,7 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => {
asset.chainId as Hex,
asset.ticker ?? asset.symbol,
)}
name={networkName}
name={networkConfigurationByChainId?.name}
/>
}
>
Expand Down
8 changes: 5 additions & 3 deletions app/components/UI/Tokens/TokenList/TokenListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
selectProviderConfig,
selectTicker,
selectNetworkConfigurations,
selectNetworkConfigurationByChainId,
} from '../../../../../selectors/networkController';
import {
selectContractExchangeRates,
Expand All @@ -26,7 +27,6 @@ import {
selectCurrentCurrency,
selectCurrencyRates,
} from '../../../../../selectors/currencyRateController';
import { selectNetworkName } from '../../../../../selectors/networkInfos';
import { RootState } from '../../../../../reducers';
import { safeToChecksumAddress } from '../../../../../util/address';
import {
Expand Down Expand Up @@ -99,7 +99,9 @@ export const TokenListItem = React.memo(
ticker,
type,
);
const networkName = useSelector(selectNetworkName);
const networkConfigurationByChainId = useSelector((state: RootState) =>
selectNetworkConfigurationByChainId(state, asset.chainId as Hex),
);
const primaryCurrency = useSelector(
(state: RootState) => state.settings.primaryCurrency,
);
Expand Down Expand Up @@ -327,7 +329,7 @@ export const TokenListItem = React.memo(
<Badge
variant={BadgeVariant.Network}
imageSource={networkBadgeSource(chainId)}
name={networkName}
name={networkConfigurationByChainId?.name}
/>
}
>
Expand Down

0 comments on commit 99c6f19

Please sign in to comment.