Skip to content

Commit

Permalink
multichain folder
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Jan 17, 2025
1 parent 1705db1 commit e3f517e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
8 changes: 5 additions & 3 deletions app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/Tokens/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions app/selectors/multichain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './multichain';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RootState } from '../reducers';
import { RootState } from '../../reducers';
import {
selectedAccountNativeTokenCachedBalanceByChainId,
selectAccountTokensAcrossChains,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e3f517e

Please sign in to comment.