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: cherry-pick fix check for undefined marketData (#28870) #28950

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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
// When a network gets added/removed we want to make sure that we switch to the filtered list of the current network
// We only want to do this if the "Current Network" filter is selected
useEffect(() => {
if (Object.keys(tokenNetworkFilter).length === 1) {
if (Object.keys(tokenNetworkFilter || {}).length === 1) {
dispatch(setTokenNetworkFilter({ [currentNetwork.chainId]: true }));
}
}, [Object.keys(allNetworks).length]);
Expand Down
5 changes: 3 additions & 2 deletions ui/components/app/assets/asset-list/asset-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ const AssetList = ({ onClickAsset, showTokensLinks }: AssetListProps) => {
);

const totalTokens =
process.env.PORTFOLIO_VIEW && !allNetworksFilterShown
process.env.PORTFOLIO_VIEW &&
!allNetworksFilterShown &&
detectedTokensMultichain
? (Object.values(detectedTokensMultichain).reduce(
// @ts-expect-error TS18046: 'tokenArray' is of type 'unknown'
(count, tokenArray) => count + tokenArray.length,
0,
) as number)
: detectedTokens.length;

return (
<>
{totalTokens &&
Expand Down
4 changes: 1 addition & 3 deletions ui/components/app/assets/token-list/token-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ export default function TokenList({
const allNetworkFilters = Object.fromEntries(
Object.keys(allNetworks).map((chainId) => [chainId, true]),
);

if (Object.keys(tokenNetworkFilter).length > 1) {
if (Object.keys(tokenNetworkFilter || {}).length > 1) {
dispatch(setTokenNetworkFilter(allNetworkFilters));
}
}
}, [Object.keys(allNetworks).length]);

const consolidatedBalances = () => {
const tokensWithBalance: TokenWithFiatAmount[] = [];

Object.entries(selectedAccountTokensChains).forEach(
([stringChainKey, tokens]) => {
const chainId = stringChainKey as Hex;
Expand Down
19 changes: 10 additions & 9 deletions ui/hooks/useTokenFiatAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ export function useTokenFiatAmount(
shallowEqual,
);

const contractMarketData = chainId
? Object.entries(allMarketData[chainId]).reduce(
(acc, [address, marketData]) => {
acc[address] = marketData?.price ?? null;
return acc;
},
{},
)
: null;
const contractMarketData =
chainId && allMarketData[chainId]
? Object.entries(allMarketData[chainId]).reduce(
(acc, [address, marketData]) => {
acc[address] = marketData?.price ?? null;
return acc;
},
{},
)
: null;

const tokenMarketData = chainId ? contractMarketData : contractExchangeRates;

Expand Down
Loading