Skip to content

Commit 584d9a3

Browse files
committed
feat: introduce useAssetVisibility hook and AssetsController selectors
- Add getCustomAssets, getAssetsBalance, getAssetsInfo, getAssetPreferences selectors for AssetsController state with unit tests - Add useAssetVisibility hook that derives the correct AssetsController action (addCustomAsset / removeCustomAsset / hideAsset / unhideAsset) based on the token's current state - Wire handleHideToken into MoreTokenActionsMenu behind the isAssetsUnifyStateEnabled feature flag (legacy TokensController path still runs unconditionally) - Replace direct AssetsController.addCustomAsset calls in AddCustomToken and SearchTokenAutocomplete with handleAddCustomAsset from the hook, removing per-component account-ID lookups - Fix assets-controller-messenger test: add missing NetworkController:networkAdded and NetworkController:networkRemoved events to the arrayContaining assertion
1 parent ead9094 commit 584d9a3

9 files changed

Lines changed: 905 additions & 64 deletions

File tree

app/components/UI/TokenDetails/components/MoreTokenActionsMenu.tsx

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { TokenI } from '../../Tokens/types';
2222
import { RootState } from '../../../../reducers';
2323
import { selectAsset } from '../../../../selectors/assets/assets-list';
2424
import { isMusdToken } from '../../../UI/Earn/constants/musd';
25+
import { selectIsAssetsUnifyStateEnabled } from '../../../../selectors/featureFlagController/assetsUnifyState';
26+
import useAssetVisibility from './useAssetVisibility';
27+
import { isNonEvmChainId } from '../../../../core/Multichain/utils';
28+
import { removeNonEvmToken } from '../../Tokens/util/removeNonEvmToken';
29+
import { selectSelectedInternalAccountByScope } from '../../../../selectors/multichainAccounts/accounts';
2530

2631
export interface MoreTokenActionsMenuParams {
2732
hasPerpsMarket: boolean;
@@ -67,6 +72,14 @@ const MoreTokenActionsMenu = () => {
6772
const { trackEvent, createEventBuilder } = useAnalytics();
6873
const explorer = useBlockExplorer(asset.chainId);
6974

75+
const isAssetsUnifyStateEnabled = useSelector(
76+
selectIsAssetsUnifyStateEnabled,
77+
);
78+
const selectInternalAccountByScope = useSelector(
79+
selectSelectedInternalAccountByScope,
80+
);
81+
const { handleHideToken } = useAssetVisibility(asset);
82+
7083
const closeBottomSheetAndNavigate = useCallback(
7184
(navigateFunc: () => void) => {
7285
sheetRef.current?.onCloseBottomSheet(navigateFunc);
@@ -127,15 +140,27 @@ const MoreTokenActionsMenu = () => {
127140
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
128141
screen: 'AssetHideConfirmation',
129142
params: {
130-
onConfirm: () => {
143+
onConfirm: async () => {
131144
navigation.navigate('WalletView');
132145
try {
133-
const { TokensController, NetworkController } = Engine.context;
134-
const networkClientId =
135-
NetworkController.findNetworkClientIdByChainId(
136-
asset.chainId as Hex,
137-
);
138-
TokensController.ignoreTokens([asset.address], networkClientId);
146+
if (asset.chainId && isNonEvmChainId(asset.chainId)) {
147+
await removeNonEvmToken({
148+
tokenAddress: asset.address,
149+
tokenChainId: asset.chainId,
150+
selectInternalAccountByScope,
151+
});
152+
} else {
153+
const { TokensController, NetworkController } = Engine.context;
154+
const networkClientId =
155+
NetworkController.findNetworkClientIdByChainId(
156+
asset.chainId as Hex,
157+
);
158+
TokensController.ignoreTokens([asset.address], networkClientId);
159+
}
160+
161+
if (isAssetsUnifyStateEnabled) {
162+
handleHideToken();
163+
}
139164

140165
const tokenSymbol = asset.symbol || null;
141166

@@ -172,6 +197,9 @@ const MoreTokenActionsMenu = () => {
172197
asset.chainId,
173198
asset.address,
174199
asset.symbol,
200+
isAssetsUnifyStateEnabled,
201+
handleHideToken,
202+
selectInternalAccountByScope,
175203
trackEvent,
176204
createEventBuilder,
177205
]);

0 commit comments

Comments
 (0)