From d729626a555529b50a02c7f5adc17c5ee83cef9a Mon Sep 17 00:00:00 2001 From: JungHwan Jang Date: Fri, 22 Nov 2024 10:33:17 -0500 Subject: [PATCH] CP-9541: Fix 'No asset selected' error when bridging BTC.b to BTC (#2111) --- .../app/contexts/SwapContext/SwapContext.tsx | 2 +- .../app/hooks/networks/useNetworks.ts | 4 ++-- .../screens/bridge/hooks/useBridgeAssets.ts | 4 ++-- .../screens/bridge/hooks/useBridgeNetworks.ts | 2 +- .../app/screens/bridge/hooks/useBridgeType.ts | 4 ++-- .../hooks/useTokenForBridgeTransaction.ts | 2 +- .../rpc/components/v2/ApprovalPopup.tsx | 2 +- .../app/screens/send/utils/avm/send.ts | 2 +- .../app/screens/send/utils/btc/send.ts | 2 +- .../app/screens/send/utils/evm/send.ts | 2 +- .../app/screens/send/utils/pvm/send.ts | 2 +- .../app/services/bridge/BridgeService.ts | 2 +- .../services/bridge/UnifiedBridgeService.ts | 4 ++-- .../app/services/posthog/PostHogService.ts | 2 +- .../walletconnectv2/WalletConnectService.ts | 4 ++-- .../services/walletconnectv2/utils.test.ts | 7 ++++--- .../app/services/walletconnectv2/utils.ts | 21 +------------------ .../rpc/handlers/wc_sessionRequest/utils.ts | 2 +- .../wc_sessionRequest/wc_sessionRequest.ts | 2 +- .../request/handleRequestViaVMModule.ts | 2 +- .../providers/walletConnect/walletConnect.ts | 2 +- .../app/store/unifiedBridge/listeners.ts | 2 +- .../app/{temp => utils}/caip2ChainIds.ts | 14 +++++++++++++ .../core-mobile/app/vmModule/ModuleManager.ts | 2 +- 24 files changed, 45 insertions(+), 49 deletions(-) rename packages/core-mobile/app/{temp => utils}/caip2ChainIds.ts (93%) diff --git a/packages/core-mobile/app/contexts/SwapContext/SwapContext.tsx b/packages/core-mobile/app/contexts/SwapContext/SwapContext.tsx index 158bc9a9c..f0091ed0c 100644 --- a/packages/core-mobile/app/contexts/SwapContext/SwapContext.tsx +++ b/packages/core-mobile/app/contexts/SwapContext/SwapContext.tsx @@ -21,7 +21,7 @@ import { selectActiveAccount } from 'store/account' import AnalyticsService from 'services/analytics/AnalyticsService' import { RpcMethod } from 'store/rpc/types' import { useInAppRequest } from 'hooks/useInAppRequest' -import { getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getEvmCaip2ChainId } from 'utils/caip2ChainIds' import { useNetworks } from 'hooks/networks/useNetworks' import { showTransactionErrorToast } from 'utils/toast' import { audioFeedback, Audios } from 'utils/AudioFeedback' diff --git a/packages/core-mobile/app/hooks/networks/useNetworks.ts b/packages/core-mobile/app/hooks/networks/useNetworks.ts index ac4632610..bd639ad1e 100644 --- a/packages/core-mobile/app/hooks/networks/useNetworks.ts +++ b/packages/core-mobile/app/hooks/networks/useNetworks.ts @@ -11,7 +11,7 @@ import { useCallback, useMemo } from 'react' import { selectIsDeveloperMode } from 'store/settings/advanced' import { type Network } from '@avalabs/core-chains-sdk' import { isAvalancheChainId } from 'services/network/utils/isAvalancheNetwork' -import { addNamespaceToChain } from 'services/walletconnectv2/utils' +import { getCaip2ChainId } from 'utils/caip2ChainIds' import { useGetNetworks } from './useGetNetworks' // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @@ -175,6 +175,6 @@ export const useNetworks = () => { const decorateWithCaip2ChainId = (networks: Networks): Networks => Object.entries(networks).reduce((acc, [key, network]) => { const chainId = parseInt(key) - acc[chainId] = { ...network, caip2ChainId: addNamespaceToChain(chainId) } + acc[chainId] = { ...network, caip2ChainId: getCaip2ChainId(chainId) } return acc }, {} as Networks) diff --git a/packages/core-mobile/app/screens/bridge/hooks/useBridgeAssets.ts b/packages/core-mobile/app/screens/bridge/hooks/useBridgeAssets.ts index 47312c88f..79b6d6e57 100644 --- a/packages/core-mobile/app/screens/bridge/hooks/useBridgeAssets.ts +++ b/packages/core-mobile/app/screens/bridge/hooks/useBridgeAssets.ts @@ -3,7 +3,7 @@ import { BridgeAsset, ChainAssetMap } from '@avalabs/bridge-unified' import UnifiedBridgeService from 'services/bridge/UnifiedBridgeService' import Logger from 'utils/Logger' import { useNetworks } from 'hooks/networks/useNetworks' -import { addNamespaceToChain } from 'services/walletconnectv2/utils' +import { getCaip2ChainId } from 'utils/caip2ChainIds' export const useBridgeAssets = (): { chainAssetMap: ChainAssetMap @@ -17,7 +17,7 @@ export const useBridgeAssets = (): { UnifiedBridgeService.getAssets() .then(allAssets => { setChainAssetMap(allAssets) - const caipChainId = addNamespaceToChain(activeNetwork.chainId) + const caipChainId = getCaip2ChainId(activeNetwork.chainId) setBridgeAssets(allAssets[caipChainId] ?? []) }) diff --git a/packages/core-mobile/app/screens/bridge/hooks/useBridgeNetworks.ts b/packages/core-mobile/app/screens/bridge/hooks/useBridgeNetworks.ts index cb19a814e..158db57a8 100644 --- a/packages/core-mobile/app/screens/bridge/hooks/useBridgeNetworks.ts +++ b/packages/core-mobile/app/screens/bridge/hooks/useBridgeNetworks.ts @@ -1,7 +1,7 @@ import { Network } from '@avalabs/core-chains-sdk' import { BridgeAsset } from '@avalabs/bridge-unified' import { useNetworks } from 'hooks/networks/useNetworks' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import { useBridgeAssets } from './useBridgeAssets' export const useBridgeSourceNetworks = (): Network[] => { diff --git a/packages/core-mobile/app/screens/bridge/hooks/useBridgeType.ts b/packages/core-mobile/app/screens/bridge/hooks/useBridgeType.ts index 0a85bd8c4..4d9727150 100644 --- a/packages/core-mobile/app/screens/bridge/hooks/useBridgeType.ts +++ b/packages/core-mobile/app/screens/bridge/hooks/useBridgeType.ts @@ -1,6 +1,6 @@ import { BridgeAsset, BridgeType } from '@avalabs/bridge-unified' import { useMemo } from 'react' -import { getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getCaip2ChainId } from 'utils/caip2ChainIds' export const useBridgeType = ( bridgeAsset: BridgeAsset | undefined, @@ -11,6 +11,6 @@ export const useBridgeType = ( return undefined } - return bridgeAsset.destinations[getEvmCaip2ChainId(targetChainId)]?.[0] + return bridgeAsset.destinations[getCaip2ChainId(targetChainId)]?.[0] }, [bridgeAsset, targetChainId]) } diff --git a/packages/core-mobile/app/screens/bridge/hooks/useTokenForBridgeTransaction.ts b/packages/core-mobile/app/screens/bridge/hooks/useTokenForBridgeTransaction.ts index 532e1bf36..316094916 100644 --- a/packages/core-mobile/app/screens/bridge/hooks/useTokenForBridgeTransaction.ts +++ b/packages/core-mobile/app/screens/bridge/hooks/useTokenForBridgeTransaction.ts @@ -9,7 +9,7 @@ import { useNetworkContractTokens } from 'hooks/networks/useNetworkContractToken import { useNetworks } from 'hooks/networks/useNetworks' import { useMemo } from 'react' import { isBitcoinChainId } from 'utils/network/isBitcoinNetwork' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import { isEthereumChainId } from 'services/network/utils/isEthereumNetwork' import { Blockchain, BridgeTransaction } from '@avalabs/core-bridge-sdk' import { isUnifiedBridgeTransfer } from '../utils/bridgeUtils' diff --git a/packages/core-mobile/app/screens/rpc/components/v2/ApprovalPopup.tsx b/packages/core-mobile/app/screens/rpc/components/v2/ApprovalPopup.tsx index 698f545a0..af562a0e1 100644 --- a/packages/core-mobile/app/screens/rpc/components/v2/ApprovalPopup.tsx +++ b/packages/core-mobile/app/screens/rpc/components/v2/ApprovalPopup.tsx @@ -29,7 +29,7 @@ import Avatar from 'components/Avatar' import GlobeSVG from 'components/svg/GlobeSVG' import { useSpendLimits } from 'hooks/useSpendLimits' import { isHex } from 'viem' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import RpcRequestBottomSheet from '../shared/RpcRequestBottomSheet' import { DetailSectionView } from '../shared/DetailSectionView' import BalanceChange from './BalanceChange' diff --git a/packages/core-mobile/app/screens/send/utils/avm/send.ts b/packages/core-mobile/app/screens/send/utils/avm/send.ts index 05aa43d84..8a26ec75e 100644 --- a/packages/core-mobile/app/screens/send/utils/avm/send.ts +++ b/packages/core-mobile/app/screens/send/utils/avm/send.ts @@ -4,7 +4,7 @@ import SentryWrapper from 'services/sentry/SentryWrapper' import { resolve } from '@avalabs/core-utils-sdk' import { Request } from 'store/rpc/utils/createInAppRequest' import { RpcMethod } from '@avalabs/vm-module-types' -import { getAvalancheCaip2ChainId } from 'temp/caip2ChainIds' +import { getAvalancheCaip2ChainId } from 'utils/caip2ChainIds' import { AvalancheSendTransactionParams } from '@avalabs/avalanche-module' import { stripChainAddress } from 'store/account/utils' import WalletService from 'services/wallet/WalletService' diff --git a/packages/core-mobile/app/screens/send/utils/btc/send.ts b/packages/core-mobile/app/screens/send/utils/btc/send.ts index 24ac8bddb..e43e03321 100644 --- a/packages/core-mobile/app/screens/send/utils/btc/send.ts +++ b/packages/core-mobile/app/screens/send/utils/btc/send.ts @@ -3,7 +3,7 @@ import { resolve } from '@avalabs/core-utils-sdk' import SentryWrapper from 'services/sentry/SentryWrapper' import { Request } from 'store/rpc/utils/createInAppRequest' import { BitcoinSendTransactionParams } from '@avalabs/bitcoin-module' -import { getBitcoinCaip2ChainId } from 'temp/caip2ChainIds' +import { getBitcoinCaip2ChainId } from 'utils/caip2ChainIds' export const send = async ({ request, diff --git a/packages/core-mobile/app/screens/send/utils/evm/send.ts b/packages/core-mobile/app/screens/send/utils/evm/send.ts index 9c51f2f3e..71c35bd31 100644 --- a/packages/core-mobile/app/screens/send/utils/evm/send.ts +++ b/packages/core-mobile/app/screens/send/utils/evm/send.ts @@ -1,6 +1,6 @@ import SentryWrapper from 'services/sentry/SentryWrapper' import { Request } from 'store/rpc/utils/createInAppRequest' -import { getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getEvmCaip2ChainId } from 'utils/caip2ChainIds' import { Transaction } from '@sentry/react' import { transactionRequestToTransactionParams } from 'store/rpc/utils/transactionRequestToTransactionParams' import { RpcMethod, TokenWithBalanceEVM } from '@avalabs/vm-module-types' diff --git a/packages/core-mobile/app/screens/send/utils/pvm/send.ts b/packages/core-mobile/app/screens/send/utils/pvm/send.ts index c7be54f0c..7d699e3c0 100644 --- a/packages/core-mobile/app/screens/send/utils/pvm/send.ts +++ b/packages/core-mobile/app/screens/send/utils/pvm/send.ts @@ -2,7 +2,7 @@ import { resolve } from '@avalabs/core-utils-sdk' import { RpcMethod } from '@avalabs/vm-module-types' import SentryWrapper from 'services/sentry/SentryWrapper' import { Request } from 'store/rpc/utils/createInAppRequest' -import { getAvalancheCaip2ChainId } from 'temp/caip2ChainIds' +import { getAvalancheCaip2ChainId } from 'utils/caip2ChainIds' import { AvalancheSendTransactionParams } from '@avalabs/avalanche-module' import { stripChainAddress } from 'store/account/utils' import WalletService from 'services/wallet/WalletService' diff --git a/packages/core-mobile/app/services/bridge/BridgeService.ts b/packages/core-mobile/app/services/bridge/BridgeService.ts index 55bd45538..aa7c9698d 100644 --- a/packages/core-mobile/app/services/bridge/BridgeService.ts +++ b/packages/core-mobile/app/services/bridge/BridgeService.ts @@ -23,7 +23,7 @@ import { Request } from 'store/rpc/utils/createInAppRequest' import { RpcMethod } from 'store/rpc/types' import { bnToBig, noop, stringToBN } from '@avalabs/core-utils-sdk' import { transactionRequestToTransactionParams } from 'store/rpc/utils/transactionRequestToTransactionParams' -import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'utils/caip2ChainIds' type TransferBTCParams = { fromAccount: string diff --git a/packages/core-mobile/app/services/bridge/UnifiedBridgeService.ts b/packages/core-mobile/app/services/bridge/UnifiedBridgeService.ts index 7114a7c69..70b5471c9 100644 --- a/packages/core-mobile/app/services/bridge/UnifiedBridgeService.ts +++ b/packages/core-mobile/app/services/bridge/UnifiedBridgeService.ts @@ -18,9 +18,9 @@ import { import { Network } from '@avalabs/core-chains-sdk' import { assertNotUndefined } from 'utils/assertions' import Logger from 'utils/Logger' -import { addNamespaceToChain } from 'services/walletconnectv2/utils' import { BitcoinProvider } from '@avalabs/core-wallets-sdk' import { lowerCaseKeys } from 'utils/lowerCaseKeys' +import { getCaip2ChainId } from 'utils/caip2ChainIds' type BridgeService = ReturnType @@ -205,7 +205,7 @@ export class UnifiedBridgeService { private async buildChain(network: Network): Promise { return { - chainId: addNamespaceToChain(network.chainId), + chainId: getCaip2ChainId(network.chainId), chainName: network.chainName, rpcUrl: network.rpcUrl, networkToken: { diff --git a/packages/core-mobile/app/services/posthog/PostHogService.ts b/packages/core-mobile/app/services/posthog/PostHogService.ts index fd1398b83..2e05d13e8 100644 --- a/packages/core-mobile/app/services/posthog/PostHogService.ts +++ b/packages/core-mobile/app/services/posthog/PostHogService.ts @@ -2,7 +2,7 @@ import Config from 'react-native-config' import Logger from 'utils/Logger' import DeviceInfoService from 'services/deviceInfo/DeviceInfoService' import { JsonMap } from 'store/posthog' -import { applyTempChainIdConversion } from 'temp/caip2ChainIds' +import { applyTempChainIdConversion } from 'utils/caip2ChainIds' import { PostHogServiceNoop } from 'services/posthog/PostHogServiceNoop' import { sanitizeFeatureFlags } from './sanitizeFeatureFlags' import { diff --git a/packages/core-mobile/app/services/walletconnectv2/WalletConnectService.ts b/packages/core-mobile/app/services/walletconnectv2/WalletConnectService.ts index c278124f7..e8f833343 100644 --- a/packages/core-mobile/app/services/walletconnectv2/WalletConnectService.ts +++ b/packages/core-mobile/app/services/walletconnectv2/WalletConnectService.ts @@ -14,13 +14,13 @@ import Logger from 'utils/Logger' import promiseWithTimeout from 'utils/js/promiseWithTimeout' import { WalletConnectServiceNoop } from 'services/walletconnectv2/WalletConnectServiceNoop' import { CorePrimaryAccount } from '@avalabs/types' +import { getCaip2ChainId } from 'utils/caip2ChainIds' import { CLIENT_METADATA, WalletConnectCallbacks, WalletConnectServiceInterface } from './types' import { - addNamespaceToChain, getAddressWithCaip2ChainId, updateAccountListInNamespace, updateChainListInNamespace @@ -205,7 +205,7 @@ class WalletConnectService implements WalletConnectServiceInterface { account: CorePrimaryAccount }): Promise => { const topic = session.topic - const caip2ChainId = addNamespaceToChain(chainId) + const caip2ChainId = getCaip2ChainId(chainId) const blockchainNamespace = caip2ChainId.split(':')[0] diff --git a/packages/core-mobile/app/services/walletconnectv2/utils.test.ts b/packages/core-mobile/app/services/walletconnectv2/utils.test.ts index 810d74157..2c57386e9 100644 --- a/packages/core-mobile/app/services/walletconnectv2/utils.test.ts +++ b/packages/core-mobile/app/services/walletconnectv2/utils.test.ts @@ -4,7 +4,8 @@ import { AvalancheCaip2ChainId, BitcoinCaip2ChainId } from '@avalabs/core-chains-sdk' -import { addNamespaceToChain, getAddressWithCaip2ChainId } from './utils' +import { getCaip2ChainId } from 'utils/caip2ChainIds' +import { getAddressWithCaip2ChainId } from './utils' // Mock data const mockAccount: CorePrimaryAccount = { @@ -23,10 +24,10 @@ const mockAccount: CorePrimaryAccount = { addressCoreEth: 'CoreEthAddress' } -describe('addNamespaceToChain', () => { +describe('getCaip2ChainId', () => { it('should add eip155 namespace to a chainId', () => { const chainId = 1 - const result = addNamespaceToChain(chainId) + const result = getCaip2ChainId(chainId) expect(result).toBe('eip155:1') }) }) diff --git a/packages/core-mobile/app/services/walletconnectv2/utils.ts b/packages/core-mobile/app/services/walletconnectv2/utils.ts index f4cbbe4d5..c45869399 100644 --- a/packages/core-mobile/app/services/walletconnectv2/utils.ts +++ b/packages/core-mobile/app/services/walletconnectv2/utils.ts @@ -1,26 +1,7 @@ import { BlockchainNamespace } from '@avalabs/core-chains-sdk' -import { - getAvalancheCaip2ChainId, - getBitcoinCaip2ChainIdByChainId, - isXChainId, - isPChainId -} from 'temp/caip2ChainIds' +import { isXChainId, isPChainId } from 'utils/caip2ChainIds' import { CorePrimaryAccount } from '@avalabs/types' -// prefix correct namespace to a chainId -// '1' -> 'eip155:1' -export const addNamespaceToChain = (chainId: number): string => { - const caip2ChainId = - getAvalancheCaip2ChainId(chainId) || - getBitcoinCaip2ChainIdByChainId(chainId) - - if (caip2ChainId) { - return caip2ChainId - } - - return `${BlockchainNamespace.EIP155}:${chainId}` -} - // generate full address with caip2 chain ID based on the blockchain namespace // an example result 'eip155:1:0x241b0073b66bfc19FCB54308861f604F5Eb8f51b' export const getAddressWithCaip2ChainId = ({ diff --git a/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/utils.ts b/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/utils.ts index a98f81721..592dedb78 100644 --- a/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/utils.ts +++ b/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/utils.ts @@ -24,7 +24,7 @@ import { isCChainId, isPChainId, isBtcChainId -} from 'temp/caip2ChainIds' +} from 'utils/caip2ChainIds' const CORE_WEB_HOSTNAMES = [ 'localhost', diff --git a/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/wc_sessionRequest.ts b/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/wc_sessionRequest.ts index cc5404dfc..87caf516c 100644 --- a/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/wc_sessionRequest.ts +++ b/packages/core-mobile/app/store/rpc/handlers/wc_sessionRequest/wc_sessionRequest.ts @@ -11,7 +11,7 @@ import { } from 'store/network/slice' import { selectIsBlockaidDappScanBlocked } from 'store/posthog/slice' import { createInAppRequest } from 'store/rpc/utils/createInAppRequest' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import mergeWith from 'lodash/mergeWith' import isArray from 'lodash/isArray' import union from 'lodash/union' diff --git a/packages/core-mobile/app/store/rpc/listeners/request/handleRequestViaVMModule.ts b/packages/core-mobile/app/store/rpc/listeners/request/handleRequestViaVMModule.ts index 297bb7237..18a59f57c 100644 --- a/packages/core-mobile/app/store/rpc/listeners/request/handleRequestViaVMModule.ts +++ b/packages/core-mobile/app/store/rpc/listeners/request/handleRequestViaVMModule.ts @@ -8,7 +8,7 @@ import Logger from 'utils/Logger' import { selectNetwork } from 'store/network/slice' import { isRpcRequest } from 'store/rpc/utils/isRpcRequest' import { mapToVmNetwork } from 'vmModule/utils/mapToVmNetwork' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import { CorePrimaryAccount } from '@avalabs/types' import { Avalanche } from '@avalabs/core-wallets-sdk' import { getAddressByVM } from 'store/account/utils' diff --git a/packages/core-mobile/app/store/rpc/providers/walletConnect/walletConnect.ts b/packages/core-mobile/app/store/rpc/providers/walletConnect/walletConnect.ts index 73258d95c..7396084c0 100644 --- a/packages/core-mobile/app/store/rpc/providers/walletConnect/walletConnect.ts +++ b/packages/core-mobile/app/store/rpc/providers/walletConnect/walletConnect.ts @@ -10,7 +10,7 @@ import { selectActiveNetwork } from 'store/network' import { UPDATE_SESSION_DELAY } from 'consts/walletConnect' import AnalyticsService from 'services/analytics/AnalyticsService' import { showDappConnectionSuccessToast } from 'utils/toast' -import { getChainIdFromCaip2 } from 'temp/caip2ChainIds' +import { getChainIdFromCaip2 } from 'utils/caip2ChainIds' import { getJsonRpcErrorMessage } from 'utils/getJsonRpcErrorMessage' import { AgnosticRpcProvider, RpcMethod, RpcProvider } from '../../types' import { isSessionProposal, isUserRejectedError } from './utils' diff --git a/packages/core-mobile/app/store/unifiedBridge/listeners.ts b/packages/core-mobile/app/store/unifiedBridge/listeners.ts index de94dcfa8..67944d4fc 100644 --- a/packages/core-mobile/app/store/unifiedBridge/listeners.ts +++ b/packages/core-mobile/app/store/unifiedBridge/listeners.ts @@ -22,7 +22,7 @@ import { createInAppRequest } from 'store/rpc/utils/createInAppRequest' import { FeatureGates } from 'services/posthog/types' import { getBitcoinProvider } from 'services/network/utils/providerUtils' import { RpcMethod } from '@avalabs/vm-module-types' -import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'utils/caip2ChainIds' import { TransactionParams } from '@avalabs/evm-module' import { removePendingTransfer, diff --git a/packages/core-mobile/app/temp/caip2ChainIds.ts b/packages/core-mobile/app/utils/caip2ChainIds.ts similarity index 93% rename from packages/core-mobile/app/temp/caip2ChainIds.ts rename to packages/core-mobile/app/utils/caip2ChainIds.ts index c21135cae..de23558dd 100644 --- a/packages/core-mobile/app/temp/caip2ChainIds.ts +++ b/packages/core-mobile/app/utils/caip2ChainIds.ts @@ -147,3 +147,17 @@ export const getChainIdFromCaip2 = ( ? getBitcoinChainId(caip2ChainId) : Number(caip2ChainId.split(':')[1]) } + +// get caip2 chain id from chain id +// '1' -> 'eip155:1' +export const getCaip2ChainId = (chainId: number): string => { + const caip2ChainId = + getAvalancheCaip2ChainId(chainId) || + getBitcoinCaip2ChainIdByChainId(chainId) + + if (caip2ChainId) { + return caip2ChainId + } + + return `${BlockchainNamespace.EIP155}:${chainId}` +} diff --git a/packages/core-mobile/app/vmModule/ModuleManager.ts b/packages/core-mobile/app/vmModule/ModuleManager.ts index e81a9f07a..870312f32 100644 --- a/packages/core-mobile/app/vmModule/ModuleManager.ts +++ b/packages/core-mobile/app/vmModule/ModuleManager.ts @@ -15,7 +15,7 @@ import { assertNotUndefined } from 'utils/assertions' import { AvalancheModule } from '@avalabs/avalanche-module' import { BlockchainId } from '@avalabs/glacier-sdk' import { BitcoinModule } from '@avalabs/bitcoin-module' -import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'temp/caip2ChainIds' +import { getBitcoinCaip2ChainId, getEvmCaip2ChainId } from 'utils/caip2ChainIds' import { APPLICATION_NAME, APPLICATION_VERSION } from 'utils/network/constants' import { ModuleErrors, VmModuleErrors } from './errors' import { approvalController } from './ApprovalController/ApprovalController'