Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix test networks display for portfolio view #28601

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions ui/components/app/assets/token-cell/token-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,14 @@ export default function TokenCell({
image;

const secondaryThreshold = 0.01;

// Format for fiat balance with currency style
const secondary = formatWithThreshold(
tokenFiatAmount,
secondaryThreshold,
locale,
{
style: 'currency',
currency: currentCurrency.toUpperCase(),
},
);
const secondary =
tokenFiatAmount === null
? undefined
: formatWithThreshold(tokenFiatAmount, secondaryThreshold, locale, {
style: 'currency',
currency: currentCurrency.toUpperCase(),
});

const primary = formatAmount(
locale,
Expand Down
18 changes: 17 additions & 1 deletion ui/components/app/assets/token-list/token-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { sortAssets } from '../util/sort';
import {
getCurrencyRates,
getCurrentNetwork,
getIsTestnet,
getMarketData,
getNetworkConfigurationIdByChainId,
getNewTokensImported,
getPreferences,
getSelectedAccount,
getSelectedAccountNativeTokenCachedBalanceByChainId,
getSelectedAccountTokensAcrossChains,
getShowFiatInTestnets,
getTokenExchangeRates,
} from '../../../../selectors';
import { getConversionRate } from '../../../../ducks/metamask/metamask';
Expand All @@ -24,6 +26,8 @@ import { endTrace, TraceName } from '../../../../../shared/lib/trace';
import { useTokenBalances } from '../../../../hooks/useTokenBalances';
import { setTokenNetworkFilter } from '../../../../store/actions';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { useMultichainSelector } from '../../../../hooks/useMultichainSelector';
import { getMultichainShouldShowFiat } from '../../../../selectors/multichain';

type TokenListProps = {
onTokenClick: (chainId: string, address: string) => void;
Expand Down Expand Up @@ -212,6 +216,18 @@ export default function TokenList({
console.log(t('loadingTokens'));
}

// Check if testnet
const isTestnet = useSelector(getIsTestnet);
const shouldShowFiat = useMultichainSelector(
getMultichainShouldShowFiat,
selectedAccount,
);
const isMainnet = !isTestnet;
// Check if show conversion is enabled
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
const showFiat =
shouldShowFiat && (isMainnet || (isTestnet && showFiatInTestnets));

return (
<div>
{sortedFilteredTokens.map((tokenData) => (
Expand All @@ -220,7 +236,7 @@ export default function TokenList({
chainId={tokenData.chainId}
address={tokenData.address}
symbol={tokenData.symbol}
tokenFiatAmount={tokenData.tokenFiatAmount}
tokenFiatAmount={showFiat ? tokenData.tokenFiatAmount : null}
image={tokenData?.image}
isNative={tokenData.isNative}
string={tokenData.string}
Expand Down
17 changes: 16 additions & 1 deletion ui/pages/asset/components/asset-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
getCurrencyRates,
getSelectedAccountNativeTokenCachedBalanceByChainId,
getSelectedAccount,
getIsTestnet,
getShowFiatInTestnets,
} from '../../../selectors';
import {
Display,
Expand Down Expand Up @@ -49,6 +51,8 @@ import CoinButtons from '../../../components/app/wallet-overview/coin-buttons';
import { getIsNativeTokenBuyable } from '../../../ducks/ramps';
import { calculateTokenBalance } from '../../../components/app/assets/util/calculateTokenBalance';
import { useTokenBalances } from '../../../hooks/useTokenBalances';
import { useMultichainSelector } from '../../../hooks/useMultichainSelector';
import { getMultichainShouldShowFiat } from '../../../selectors/multichain';
import { getPortfolioUrl } from '../../../helpers/utils/portfolio';
import AssetChart from './chart/asset-chart';
import TokenButtons from './token-buttons';
Expand Down Expand Up @@ -109,6 +113,17 @@ const AssetPage = ({
const marketData = useSelector(getMarketData);
const currencyRates = useSelector(getCurrencyRates);

const isTestnet = useSelector(getIsTestnet);
const shouldShowFiat = useMultichainSelector(
getMultichainShouldShowFiat,
selectedAccount,
);
const isMainnet = !isTestnet;
// Check if show conversion is enabled
const showFiatInTestnets = useSelector(getShowFiatInTestnets);
const showFiat =
shouldShowFiat && (isMainnet || (isTestnet && showFiatInTestnets));

const nativeBalances: Record<Hex, Hex> = useSelector(
getSelectedAccountNativeTokenCachedBalanceByChainId,
) as Record<Hex, Hex>;
Expand Down Expand Up @@ -254,7 +269,7 @@ const AssetPage = ({
chainId={chainId}
symbol={symbol}
image={image}
tokenFiatAmount={tokenFiatAmount}
tokenFiatAmount={showFiat ? tokenFiatAmount : null}
string={balance?.toString()}
/>
<Box
Expand Down
Loading