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

feat: multi chain list and network filter (experimental) #12256

Draft
wants to merge 172 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
0248c74
feat: Add sortAssets utility function
gambinish Sep 27, 2024
6a2e8c7
chore: Breakup monolithic Tokens/index.tsx into smaller components
gambinish Sep 27, 2024
7a78717
fix: Correctly handle null check for buyable footer button
gambinish Sep 27, 2024
57295ee
fix: Tweak boolean logic for rendering footer components
gambinish Sep 27, 2024
d00354f
chore: Update snapshot
gambinish Sep 27, 2024
be87f81
chore: Type out tokens as TokenI[]
gambinish Sep 27, 2024
68c7b2e
chore: Remove unecessary comments around import statements in Networt…
gambinish Sep 27, 2024
a02e139
Merge branch 'main' into chore/componetize-tokens-screen
gambinish Sep 27, 2024
de5bbed
Merge branch 'main' into chore/componetize-tokens-screen
gambinish Sep 27, 2024
0fd9ad5
Merge branch 'main' into chore/componetize-tokens-screen
gambinish Sep 27, 2024
032618c
chore: Add unit tests to utility file, provide exports from index file
gambinish Sep 30, 2024
a58f1ba
chore: Rename handleBalance to me more descriptive of what its logic …
gambinish Sep 30, 2024
1dd31e3
chore: rename Networth to PortfolioBalance for clarity
gambinish Sep 30, 2024
16ded6a
chore: Cleanup styles extra whitespace
gambinish Sep 30, 2024
52d3d85
Merge branch 'main' into chore/componetize-tokens-screen
gambinish Sep 30, 2024
dd3ffdf
fix: Update snapshot tests
gambinish Sep 30, 2024
da640bc
Merge branch 'chore/componetize-tokens-screen' of github.com:MetaMask…
gambinish Sep 30, 2024
ebcbcf6
fix: Remove unused component
gambinish Sep 30, 2024
31fad19
Merge branch 'main' into chore/componetize-tokens-screen
gambinish Sep 30, 2024
4a8d927
chore: Move PotfolioBalance above TabView
gambinish Oct 1, 2024
a7b4c17
fix: Wrap PortfolioBalance and ScrollableView in fragment for token r…
gambinish Oct 1, 2024
658fcf6
fix: Padding tweak below tab bar for consistency of token list
gambinish Oct 1, 2024
18035d4
fix: Reorganize test suite for PortfolioBalance
gambinish Oct 1, 2024
c570c2c
fix: Revert changes to wallet test
gambinish Oct 1, 2024
a97128b
fix: Update fiatBalance text style to DisplayMD
gambinish Oct 1, 2024
8036a0a
chore: Patch PreferencesController with tokenSortConfig
gambinish Oct 1, 2024
1f0ac51
chore: Patch preferences controller with type
gambinish Oct 1, 2024
34d987c
feat: Build token sorting UI, patch PreferencesController
gambinish Oct 4, 2024
d57558b
chore: Merge main, address merge conflicts
gambinish Oct 7, 2024
c5c954c
fix: ListHeaderComponent not needed in FlatList anymore
gambinish Oct 7, 2024
4f635e8
fix: Update snapshots and lint
gambinish Oct 7, 2024
469270a
chore: Merge develop, address conflicts
gambinish Oct 8, 2024
82eb1a2
chore: Remove destructive index
gambinish Oct 9, 2024
f18b820
Merge branch 'main' into feat/mmassets_357-sort-import-tokens-mobile-…
gambinish Oct 10, 2024
d3a79fc
chore: Merge main, address conflicts
gambinish Oct 10, 2024
5fc979c
chore: Repatch preferences controller with tokenSortConfig
gambinish Oct 10, 2024
2890148
fix: Declning balance sort
gambinish Oct 10, 2024
25a7238
fix: Export raw value from deriveBalanceFromAssetMarketDetails
gambinish Oct 10, 2024
6637303
fix: deriveBalanceFromAssetMarketDetails.test.ts
gambinish Oct 10, 2024
0415b73
fix: Update unit tests and snapshots
gambinish Oct 10, 2024
ff32cc4
fix: Lint unused imports from Tokens/index.tsx
gambinish Oct 10, 2024
f4f2519
chore: Update testIds and locale strings
gambinish Oct 11, 2024
bd61eff
fix: Update WalletView import selector
gambinish Oct 11, 2024
f28b6fe
fix: Update snapshots
gambinish Oct 11, 2024
7c9d5cc
chore: Cleanup
gambinish Oct 11, 2024
e747848
fix: Add navigation type
gambinish Oct 11, 2024
71ce22f
fix: fix snapshot
salimtb Oct 11, 2024
6aa6f3f
Merge branch 'main' into feat/mmassets_357-sort-import-tokens-mobile-…
salimtb Oct 15, 2024
fe21f40
chore: Update snapshots
gambinish Oct 15, 2024
6f52163
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--reorg-port…
gambinish Oct 15, 2024
579f012
fix: Update placeholders in switch statement
gambinish Oct 15, 2024
68338a3
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--token-sort…
gambinish Oct 15, 2024
ff95c72
chore: Add additional e2e test for import token footer link
gambinish Oct 15, 2024
1d929ce
chore: Update snapshots
gambinish Oct 15, 2024
9cf6337
chore: Patch PreferencesController with tokenNetworkFilter
gambinish Oct 16, 2024
fcf0d64
fix: Update to correct type in PreferenceController patch
gambinish Oct 16, 2024
e3196a3
fix: Correct method name in patched PreferenceController
gambinish Oct 16, 2024
aa5b6da
chore: Integrate Filter dropdown with PreferencesController
gambinish Oct 16, 2024
a926d64
fix: Break out of switch statement rather than returning arbitrary st…
gambinish Oct 16, 2024
d3c5d81
chore: Init BottomSheet refactor
gambinish Oct 16, 2024
e925da3
fix: Remove arbitrary 8 second delays from import-tokens.spec
gambinish Oct 16, 2024
0c9ca35
fix: Use ButtonBase component to customize button text color more dir…
gambinish Oct 16, 2024
63bb1a2
fix: Update snapshot
gambinish Oct 16, 2024
a5d8b71
fix: Mock initial state that PortfolioBalance component needs
gambinish Oct 16, 2024
0b617f2
fix: Mock tabs in snapshot
gambinish Oct 16, 2024
96436be
fix: Consider Error boundary during Wallet rendering process
gambinish Oct 16, 2024
1365f4d
fix: Update localized string
gambinish Oct 16, 2024
bd9ad0d
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--reorg-port…
gambinish Oct 16, 2024
da5862d
Merge branch 'main' into feat/mmassets_357-sort-import-tokens-mobile-…
gambinish Oct 17, 2024
c0a28bc
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--reorg-port…
gambinish Oct 17, 2024
2934811
Merge branch 'main' into feat/mmassets_357-sort-import-tokens-mobile-…
gambinish Oct 17, 2024
8cb67f7
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--reorg-port…
gambinish Oct 17, 2024
990067f
Merge branch 'main' into feat/mmassets_357-sort-import-tokens-mobile-…
gambinish Oct 17, 2024
1f5ad7f
chore: Add TokenSortBottomSheet to RootModalFlow in Routes
gambinish Oct 17, 2024
e5b060e
fix: Resolve upstream conflicts
gambinish Oct 17, 2024
c057c24
fix: Lint:tsc
gambinish Oct 17, 2024
4e9f8d9
fix: Lint
gambinish Oct 17, 2024
319706d
chore: Init unit tests for new UI
gambinish Oct 18, 2024
6bfa6ab
chore: Merge main
gambinish Oct 23, 2024
60bbfe3
chore: Show selected network in filter
gambinish Oct 23, 2024
bd40392
fix: Update unit tests and snapshots
gambinish Oct 23, 2024
dd3de6f
chore: Merge main, address conflicts
gambinish Oct 23, 2024
e8b22c4
fix: Add test for refresh control on tokens screen
gambinish Oct 23, 2024
d5a41ba
chore: Update testID selectors for token list
gambinish Oct 23, 2024
ce983b8
chore: Add tokenSort BottomSheet trigger test
gambinish Oct 23, 2024
931b122
chore: Lint
gambinish Oct 23, 2024
3fd170f
fix: Update snapshots
gambinish Oct 23, 2024
0d00f62
chore: TokenSortBottomSheet unit tests
gambinish Oct 23, 2024
a6f12d0
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Oct 23, 2024
784c39f
chore: Cleanup
gambinish Oct 23, 2024
6a4a64e
chore: Cleanup, and queryByTestID for test stability
gambinish Oct 23, 2024
1dfd1bf
chore: More cleanup
gambinish Oct 23, 2024
fe1e236
chore: Merge main, address conflicts
gambinish Oct 23, 2024
0fe13d9
fix: Lint
gambinish Oct 24, 2024
4c6b6c2
Merge branch 'feat/mmassets_357-sort-import-tokens-mobile--token-sort…
gambinish Oct 24, 2024
84ca594
fix: Lint after conflicts
gambinish Oct 24, 2024
997fc3d
fix: Missing testIDs after merge for unit tests
gambinish Oct 24, 2024
43e9c85
chore: Merge main, address conflicts
gambinish Oct 29, 2024
18c4e43
refactor: Filter ActionSheet should be BottomSheet
gambinish Oct 29, 2024
d34b986
chore: Tweak styles to fix merge conflict
gambinish Oct 29, 2024
621bd6f
fix: Update unit tests with correct import path
gambinish Oct 29, 2024
4c5dab9
chore: Add unit tests for TokenFilterBottomSheet
gambinish Oct 29, 2024
d3b4356
chore: Add locale strings
gambinish Oct 29, 2024
e656fe6
chore: Add MM_TOKEN_NETWORK_FILTER_ENABLED feature flag
gambinish Oct 29, 2024
04c2613
fix: Add missing locale string
gambinish Oct 29, 2024
b146421
chore: Update snapshots
gambinish Oct 29, 2024
7fe0909
fix: Cleanup localisation strings and code comments
gambinish Oct 29, 2024
16a6bac
fix: Cleanup localisation strings, remove code comments, update featu…
gambinish Oct 29, 2024
27c3050
chore: Revert changes to component-library that are no longer needed
gambinish Oct 29, 2024
a79f3a6
fix: Lint whitespace diff
gambinish Oct 29, 2024
1c1b6cb
fix: Another whitespace diff fix
gambinish Oct 29, 2024
a8fc838
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Oct 31, 2024
66c27e6
chore: Merge main
gambinish Oct 31, 2024
77442e4
fix: Remove outdated patch to preferenceController
gambinish Oct 31, 2024
195f656
chore: Repatch package with tokenNetworkFilter
gambinish Oct 31, 2024
cfcc55f
fix: Lint
gambinish Nov 1, 2024
ad121ee
chore: Merge main, address conflicts
gambinish Nov 1, 2024
e3fdea1
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 1, 2024
9ebaa20
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 1, 2024
11af1e7
chore: Merge main
gambinish Nov 4, 2024
dc5d76c
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 4, 2024
9d3260e
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 5, 2024
b2781a5
refactor: Update AssetListControls buttons to icons per design revisions
gambinish Nov 5, 2024
f3b9a14
fix: Update button text wrapping with snapshots
gambinish Nov 5, 2024
4a52719
Merge branch 'feat/mmassets-431_network-filter-ui' of github.com:Meta…
gambinish Nov 5, 2024
e392f21
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 5, 2024
68a76d6
fix: Lint
gambinish Nov 5, 2024
166ac02
Merge branch 'feat/mmassets-431_network-filter-ui' of github.com:Meta…
gambinish Nov 5, 2024
fcafb86
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 5, 2024
de35586
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 6, 2024
edc8c5c
chore: Replace unrelated build flag
gambinish Nov 6, 2024
915549e
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 7, 2024
ab20b3e
fix: Remove unused font style
gambinish Nov 8, 2024
fd28086
fix: Use true for feature flag
gambinish Nov 8, 2024
db79b71
fix: Unblock podfile during CI
gambinish Nov 8, 2024
497db58
chore: Merge main, fix conflicts
gambinish Nov 9, 2024
864c841
feat: updating token list related logic to prepare for multichain
vinnyhoward Nov 11, 2024
b3fedb2
internalAccounts
vinnyhoward Nov 11, 2024
0e56fb5
Merge branch 'main' of github.com:MetaMask/metamask-mobile into feat-…
vinnyhoward Nov 11, 2024
a2775a8
Merge branch 'main' into feat/mmassets-431_network-filter-ui
vinnyhoward Nov 11, 2024
e3459ae
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 11, 2024
0595d96
Merge branch 'main' into feat/mmassets-431_network-filter-ui
gambinish Nov 11, 2024
13036b5
feat: creating selectors for multichain
vinnyhoward Nov 12, 2024
6701035
Merge branch 'feat/mmassets-431_network-filter-ui' of github.com:Meta…
vinnyhoward Nov 12, 2024
d2e8233
feat: add token rates controller and token balances and token list co…
salimtb Nov 10, 2024
0a067d6
fix: add patch for controllers
salimtb Nov 12, 2024
484785a
Merge branch 'main' of github.com:MetaMask/metamask-mobile into feat-…
vinnyhoward Nov 12, 2024
1970754
multichain currency rate polling
bergeron Nov 12, 2024
e23a19c
remove unused places
bergeron Nov 12, 2024
9a2342c
lint
bergeron Nov 12, 2024
910395e
add unit test
bergeron Nov 12, 2024
1492b4c
update unit tests
bergeron Nov 12, 2024
ae15f45
update unit test
bergeron Nov 12, 2024
3b6c675
remove other network updates
bergeron Nov 12, 2024
2e9dff3
remove additional call
bergeron Nov 12, 2024
9a5935e
bump asset controller, and poll tokens across chains
bergeron Nov 13, 2024
14281c1
add platform argument to token detection controller
bergeron Nov 13, 2024
00f66d4
feat: multi chain assets now render and can be filtered
vinnyhoward Nov 13, 2024
545e484
fix: updating price percentage change by day and staking ui bugs
vinnyhoward Nov 13, 2024
d5ec08c
fix: remove patch that is causing crash
vinnyhoward Nov 13, 2024
e838a96
Merge branch 'main' of github.com:MetaMask/metamask-mobile into feat-…
vinnyhoward Nov 13, 2024
f3f67c1
fix: fix build
salimtb Nov 14, 2024
0910468
fix: add patch
salimtb Nov 14, 2024
92576bf
feat: token filter feature
salimtb Nov 14, 2024
2663782
fix: fix polling
salimtb Nov 14, 2024
0a8926e
Merge branch 'feat-431-network-filter' of github.com:MetaMask/metamas…
vinnyhoward Nov 14, 2024
ccec2d8
update: detected tokens show correect amount but cannot import all to…
vinnyhoward Nov 15, 2024
3a4cc62
Merge branch 'main' into feat-431-network-filter
salimtb Nov 15, 2024
31326df
fix: fix token autodetection
salimtb Nov 15, 2024
d3b31f6
fix: fix import
salimtb Nov 15, 2024
ac92fb1
fix: fix bugs and clean up
salimtb Nov 15, 2024
4c0f35c
fix: optimized multi chain list selector, added non-zero perferences …
vinnyhoward Nov 15, 2024
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
11 changes: 11 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1731607498998</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
11 changes: 11 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ const mockInitialState: DeepPartial<RootState> = {
},
},
TokenBalancesController: {
contractBalances: {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': '0x5',
tokenBalances: {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': {
'0x5': {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': '0x2b46',
},
},
},
},
AccountsController: MOCK_ACCOUNTS_CONTROLLER_STATE,
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/AssetElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ const AssetElement: React.FC<AssetElementProps> = ({
{balance && (
<SensitiveText
variant={
asset?.hasBalanceError ||
asset.balanceFiat === TOKEN_RATE_UNDEFINED
asset?.hasBalanceError
? TextVariant.BodySM
: TextVariant.BodyLGMedium
}
Expand Down
5 changes: 4 additions & 1 deletion app/components/UI/AssetOverview/Price/Price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const Price = ({
<Text variant={TextVariant.BodyMDMedium}>{asset.symbol}</Text>
)}
{!isNaN(price) && (
<Text testID={TokenOverviewSelectorsIDs.TOKEN_PRICE} variant={TextVariant.HeadingLG}>
<Text
testID={TokenOverviewSelectorsIDs.TOKEN_PRICE}
variant={TextVariant.HeadingLG}
>
{isLoading ? (
<View style={styles.loadingPrice}>
<SkeletonPlaceholder>
Expand Down
44 changes: 44 additions & 0 deletions app/components/UI/NetworkAssetLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { ChainId } from '@metamask/controller-utils';
import TokenIcon from '../Swaps/components/TokenIcon';

interface NetworkAssetLogoProps {
chainId: string;
ticker: string;
style: object;
big: boolean;
biggest: boolean;
testID: string;
}

function NetworkAssetLogo({
chainId,
ticker,
style,
big,
biggest,
testID,
}: NetworkAssetLogoProps) {
if (chainId === ChainId.mainnet) {
return (
<TokenIcon
big={big}
biggest={biggest}
symbol={'ETH'}
style={style}
testID={testID}
/>
);
}
return (
<TokenIcon
big={big}
biggest={biggest}
symbol={ticker}
style={style}
testID={testID}
/>
);
}

export default NetworkAssetLogo;
31 changes: 20 additions & 11 deletions app/components/UI/NetworkModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ const NetworkModals = (props: NetworkProps) => {
return true;
};

const customNetworkInformation = {
chainId,
blockExplorerUrl,
chainName: nickname,
rpcUrl,
icon: imageUrl,
ticker,
alerts,
};

const onUpdateNetworkFilter = useCallback(() => {
const { PreferencesController } = Engine.context;
PreferencesController.setTokenNetworkFilter({
[customNetworkInformation.chainId]: true,
});
}, [customNetworkInformation.chainId]);

const addNetwork = async () => {
const isValidUrl = validateRpcUrl(rpcUrl);
if (showPopularNetworkModal) {
Expand Down Expand Up @@ -172,16 +189,6 @@ const NetworkModals = (props: NetworkProps) => {
selectNetworkConfigurations,
);

const customNetworkInformation = {
chainId,
blockExplorerUrl,
chainName: nickname,
rpcUrl,
icon: imageUrl,
ticker,
alerts,
};

const checkNetwork = useCallback(async () => {
if (useSafeChainsListValidation) {
const alertsNetwork = await checkSafeNetwork(
Expand Down Expand Up @@ -245,6 +252,7 @@ const NetworkModals = (props: NetworkProps) => {
}

if (networkClientId) {
onUpdateNetworkFilter();
await NetworkController.setActiveNetwork(networkClientId);
}

Expand All @@ -270,7 +278,7 @@ const NetworkModals = (props: NetworkProps) => {
const { networkClientId } =
updatedNetwork?.rpcEndpoints?.[updatedNetwork.defaultRpcEndpointIndex] ??
{};

onUpdateNetworkFilter();
await NetworkController.setActiveNetwork(networkClientId);
};

Expand Down Expand Up @@ -339,6 +347,7 @@ const NetworkModals = (props: NetworkProps) => {
addedNetwork?.rpcEndpoints?.[addedNetwork.defaultRpcEndpointIndex] ??
{};

onUpdateNetworkFilter();
NetworkController.setActiveNetwork(networkClientId);
}
onClose();
Expand Down
57 changes: 50 additions & 7 deletions app/components/UI/Tokens/TokenList/TokenListFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import Text, {
import { WalletViewSelectorsIDs } from '../../../../../../e2e/selectors/wallet/WalletView.selectors';
import { strings } from '../../../../../../locales/i18n';
import { useSelector } from 'react-redux';
import { selectDetectedTokens } from '../../../../../selectors/tokensController';
import {
selectDetectedTokens,
selectAllDetectedTokensFlat,
} from '../../../../../selectors/tokensController';
import { isZero } from '../../../../../util/lodash';
import useRampNetwork from '../../../Ramp/hooks/useRampNetwork';
import { createBuyNavigationDetails } from '../../../Ramp/routes/utils';
Expand All @@ -23,9 +26,15 @@ import {
useMetrics,
} from '../../../../../components/hooks/useMetrics';
import { getDecimalChainId } from '../../../../../util/networks';
import { selectChainId } from '../../../../../selectors/networkController';
import {
selectChainId,
selectNetworkConfigurations,
} from '../../../../../selectors/networkController';
import { TokenI } from '../../types';
import { selectUseTokenDetection } from '../../../../../selectors/preferencesController';
import {
selectUseTokenDetection,
selectTokenNetworkFilter,
} from '../../../../../selectors/preferencesController';

interface TokenListFooterProps {
tokens: TokenI[];
Expand All @@ -34,6 +43,21 @@ interface TokenListFooterProps {
isAddTokenEnabled: boolean;
}

const isPortfolioViewEnabled = process.env.PORTFOLIO_VIEW === 'true';

const getDetectedTokensCount = (
isPortfolioEnabled: boolean,
isAllNetworksSelected: boolean,
allTokens: TokenI[],
filteredTokens: TokenI[] | undefined,
): number => {
if (!isPortfolioEnabled) {
return filteredTokens?.length ?? 0;
}

return isAllNetworksSelected ? allTokens.length : filteredTokens?.length ?? 0;
};

export const TokenListFooter = ({
tokens,
goToAddToken,
Expand All @@ -45,9 +69,19 @@ export const TokenListFooter = ({
const { trackEvent } = useMetrics();
const [isNetworkRampSupported, isNativeTokenRampSupported] = useRampNetwork();

const detectedTokens = useSelector(selectDetectedTokens);
const detectedTokens = useSelector(selectDetectedTokens) as TokenI[];
const allDetectedTokens = useSelector(
selectAllDetectedTokensFlat,
) as TokenI[];

const isTokenDetectionEnabled = useSelector(selectUseTokenDetection);
const chainId = useSelector(selectChainId);
// TODO: Can probably create "isAllNetworks" selector for these
// since they are re-used in multiple places
const tokenNetworkFilter = useSelector(selectTokenNetworkFilter); // X
const allNetworks = useSelector(selectNetworkConfigurations); // X
const isAllNetworks =
Object.keys(tokenNetworkFilter).length === Object.keys(allNetworks).length; // X

const styles = createStyles(colors);

Expand All @@ -67,10 +101,19 @@ export const TokenListFooter = ({
});
};

const tokenCount = getDetectedTokensCount(
isPortfolioViewEnabled,
isAllNetworks,
allDetectedTokens,
detectedTokens,
);

const areTokensDetected = tokenCount > 0;

return (
<>
{/* renderTokensDetectedSection */}
{detectedTokens?.length !== 0 && isTokenDetectionEnabled && (
{areTokensDetected && isTokenDetectionEnabled && (
<TouchableOpacity
style={styles.tokensDetectedButton}
onPress={showDetectedTokens}
Expand All @@ -80,8 +123,8 @@ export const TokenListFooter = ({
testID={WalletViewSelectorsIDs.WALLET_TOKEN_DETECTION_LINK_BUTTON}
>
{strings('wallet.tokens_detected_in_account', {
tokenCount: detectedTokens.length,
tokensLabel: detectedTokens.length > 1 ? 'tokens' : 'token',
tokenCount,
tokensLabel: tokenCount > 1 ? 'tokens' : 'token',
})}
</Text>
</TouchableOpacity>
Expand Down
Loading
Loading