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

Update chain id logic #16

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/tenderly/tenderly-snap.git"
},
"source": {
"shasum": "JNLIjh3TKVEi5tyOrY975mbE9GYvtA6ruLcmilpZvPc=",
"shasum": "kb5428TsWWeG9ZBWltgh9MEESOZFmNKzhi0GHDsKNAo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
7 changes: 3 additions & 4 deletions packages/snap/src/tenderly/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,15 @@ export const isTenderlyDomain = (origin: string) => {
* @throws {Error} If the input format is invalid, or processing fails.
* @example
* parseChainId("eip155:1") // returns "0x1"
* parseChainId("eip155:a86a") // returns "0xa86a"
* parseChainId("eip155:76adf1") // returns "0x76adf1"
* parseChainId("eip155:11155111") // returns "0xaa36a7"
*/
export const parseChainId = (chainId: string): string => {
try {
// Split the chainId string
const [, reference] = chainId.split(':');

// Append '0x' to the reference and return
return `0x${reference}`;
// Convert the reference from base 10 to hexadecimal and prefix with '0x'
return `0x${parseInt(reference, 10).toString(16)}`;
} catch (error) {
throw new Error(
`An unexpected error occurred while parsing CAIP-2 chainId (${chainId}): ${error.message}`,
Expand Down
Loading