diff --git a/app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx b/app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx index d65c3172fe8d..0883d3836ead 100644 --- a/app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx +++ b/app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx @@ -55,9 +55,11 @@ import { import { InternalAccount } from '@metamask/keyring-internal-api'; import { getChainIdsToPoll } from '../../../../../selectors/tokensController'; import AggregatedPercentageCrossChains from '../../../../../component-library/components-temp/Price/AggregatedPercentage/AggregatedPercentageCrossChains'; -import { selectMultichainSelectedAccountCachedBalance } from '../../../../../selectors/multichain'; -import { selectMultichainIsEvm } from '../../../../../selectors/multichain'; -import { selectMultichainDefaultToken } from '../../../../../selectors/multichain'; +import { + selectMultichainSelectedAccountCachedBalance, + selectMultichainIsEvm, + selectMultichainDefaultToken, +} from '../../../../../selectors/multichain'; export const PortfolioBalance = () => { const { PreferencesController } = Engine.context; diff --git a/app/components/UI/Tokens/index.test.tsx b/app/components/UI/Tokens/index.test.tsx index a68c483475ca..edc59bb79e4a 100644 --- a/app/components/UI/Tokens/index.test.tsx +++ b/app/components/UI/Tokens/index.test.tsx @@ -14,7 +14,7 @@ import { createTokensBottomSheetNavDetails } from './TokensBottomSheet'; // eslint-disable-next-line import/no-namespace import * as networks from '../../../util/networks'; // eslint-disable-next-line import/no-namespace -import * as multichain from '../../../selectors/multichain'; +import * as multichain from '../../../selectors/multichain/'; jest.mock('../../../core/NotificationManager', () => ({ showSimpleNotification: jest.fn(() => Promise.resolve()), diff --git a/app/selectors/multichain/index.ts b/app/selectors/multichain/index.ts new file mode 100644 index 000000000000..f62c2c9df6ea --- /dev/null +++ b/app/selectors/multichain/index.ts @@ -0,0 +1 @@ +export * from './multichain'; diff --git a/app/selectors/multichain.test.ts b/app/selectors/multichain/multichain.test.ts similarity index 99% rename from app/selectors/multichain.test.ts rename to app/selectors/multichain/multichain.test.ts index 276517a18cd5..3e700a58f636 100644 --- a/app/selectors/multichain.test.ts +++ b/app/selectors/multichain/multichain.test.ts @@ -1,4 +1,4 @@ -import { RootState } from '../reducers'; +import { RootState } from '../../reducers'; import { selectedAccountNativeTokenCachedBalanceByChainId, selectAccountTokensAcrossChains, diff --git a/app/selectors/multichain.ts b/app/selectors/multichain/multichain.ts similarity index 90% rename from app/selectors/multichain.ts rename to app/selectors/multichain/multichain.ts index d927c9a2ac62..049c49b8bbb4 100644 --- a/app/selectors/multichain.ts +++ b/app/selectors/multichain/multichain.ts @@ -12,37 +12,37 @@ import { NetworkType, NetworkNickname, } from '@metamask/controller-utils'; -import { RootState } from '../reducers'; +import { RootState } from '../../reducers'; import { selectSelectedInternalAccountFormattedAddress, selectSelectedInternalAccount, -} from './accountsController'; -import { selectAllTokens } from './tokensController'; +} from '../accountsController'; +import { selectAllTokens } from '../tokensController'; import { selectAccountBalanceByChainId, selectAccountsByChainId, -} from './accountTrackerController'; +} from '../accountTrackerController'; import { selectChainId, selectNetworkConfigurations, selectProviderConfig, -} from './networkController'; -import { TokenI } from '../components/UI/Tokens/types'; -import { renderFromWei, weiToFiat } from '../util/number'; +} from '../networkController'; +import { TokenI } from '../../components/UI/Tokens/types'; +import { renderFromWei, weiToFiat } from '../../util/number'; import { selectConversionRate, selectCurrencyRates, selectCurrentCurrency, -} from './currencyRateController'; +} from '../currencyRateController'; -import { isMainNet } from '../util/networks'; -import { isBtcMainnetAddress } from '../core/Multichain/utils'; +import { isMainNet } from '../../util/networks'; +import { isBtcMainnetAddress } from '../../core/Multichain/utils'; import { isEvmAccountType } from '@metamask/keyring-api'; -import { createDeepEqualSelector } from './util'; +import { createDeepEqualSelector } from '../util'; import { MULTICHAIN_PROVIDER_CONFIGS, MultichainProviderConfig, -} from '../core/Multichain/constants'; +} from '../../core/Multichain/constants'; import { NetworkClientConfiguration, NetworkClientType, @@ -298,12 +298,12 @@ export const selectMultichainIsEvm = createSelector( }, ); -export type MultichainNetwork = { +export interface MultichainNetwork { nickname: string; isEvmNetwork: boolean; chainId: CaipChainId; network: NetworkClientConfiguration | MultichainProviderConfig; -}; +} function getMultichainNetworkProviders(): MultichainProviderConfig[] { return Object.values(MULTICHAIN_PROVIDER_CONFIGS); @@ -350,35 +350,35 @@ export const selectMultichainNetwork = createSelector( type: NetworkClientType.Custom, }, }; - } else { - // These are the default networks, they do not have nicknames - nickname = - NETWORK_TO_NAME_MAP[ - providerConfig.type as keyof typeof NETWORK_TO_NAME_MAP - ] ?? providerConfig.type; - - return { - nickname, - isEvmNetwork: true, - chainId: `eip155:${Number(chainId)}` as CaipChainId, - network: { - chainId: providerConfig.chainId, - network: providerConfig.type as InfuraNetworkType, - ticker: providerConfig.ticker, - type: NetworkClientType.Infura, - infuraProjectId: '{infuraProjectId}', // This will be replaced by the network client - }, - }; } + + // These are the default networks, they do not have nicknames + nickname = + NETWORK_TO_NAME_MAP[ + providerConfig.type as keyof typeof NETWORK_TO_NAME_MAP + ] ?? providerConfig.type; + + return { + nickname, + isEvmNetwork: true, + chainId: `eip155:${Number(chainId)}` as CaipChainId, + network: { + chainId: providerConfig.chainId, + network: providerConfig.type as InfuraNetworkType, + ticker: providerConfig.ticker, + type: NetworkClientType.Infura, + infuraProjectId: '{infuraProjectId}', // This will be replaced by the network client + }, + }; } // Non-EVM networks: // For non-EVM, we know we have a selected account, since the logic `isEvm` is based // on having a non-EVM account being selected! const nonEvmNetworks = getMultichainNetworkProviders(); - const nonEvmNetwork = nonEvmNetworks.find((provider) => { - return provider.isAddressCompatible(selectedAccount.address); - }); + const nonEvmNetwork = nonEvmNetworks.find((provider) => + provider.isAddressCompatible(selectedAccount.address), + ); if (!nonEvmNetwork) { throw new Error( @@ -415,7 +415,6 @@ export const selectMultichainDefaultToken = createSelector( selectProviderConfig, selectMultichainProviderConfig, (isEvm, providerConfig, multichainProviderConfig) => { - console.log('providerConfig', providerConfig); const symbol = isEvm ? providerConfig?.ticker ?? 'ETH' : multichainProviderConfig?.ticker;