Skip to content

Commit

Permalink
fix: fix test networks display for portfolio view (#28601)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

This PR fixes the display in the asset page and in the main token list
when the price checker setting is off

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28601?quickstart=1)

## **Related issues**

Fixes: #28594

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/user-attachments/assets/a1213b6a-3f23-49f5-be15-a0b369b9016e


<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
sahar-fehri authored Nov 21, 2024
1 parent df9e07d commit 08cc205
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
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

0 comments on commit 08cc205

Please sign in to comment.