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

fix: formatChainIdToHex fails to parse evm caip chainIds #30848

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions shared/modules/bridge-utils/caip-formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { MultichainNetworks } from '../../constants/multichain/networks';
import { ChainId } from '../../types/bridge';
import { decimalToPrefixedHex, hexToDecimal } from '../conversion.utils';
import { MULTICHAIN_NATIVE_CURRENCY_TO_CAIP19 } from '../../constants/multichain/assets';
import { isValidNumber } from './validators';

// Returns true if the address looka like a native asset
export const isNativeAddress = (address?: string | null) =>
Expand Down Expand Up @@ -71,14 +70,13 @@ export const formatChainIdToHex = (
}
if (isCaipChainId(chainId)) {
const { reference } = parseCaipChainId(chainId);
if (isCaipReference(reference) && isValidNumber(reference)) {
if (isCaipReference(reference) && !isNaN(Number(reference))) {
return decimalToPrefixedHex(reference);
}
}
// TODO handle non-evm chainIds
// Throw an error if a non-evm chainId is passed to this function
// This should never happen, but it's a sanity check
throw new Error('Invalid cross-chain swaps chainId');
throw new Error(`Invalid cross-chain swaps chainId: ${chainId}`);
};

// Converts an asset or account address to a string that can be used for bridge-api requests
Expand Down
Loading