Skip to content

fix: normalize token address casing in market data retrieval#809

Open
kvhnuke wants to merge 1 commit into
developfrom
fix/market-price-verify
Open

fix: normalize token address casing in market data retrieval#809
kvhnuke wants to merge 1 commit into
developfrom
fix/market-price-verify

Conversation

@kvhnuke

@kvhnuke kvhnuke commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved transaction decoding for token actions by handling contract addresses consistently, which helps ensure market information and prices are shown correctly.
    • Normalized recipient addresses in decoded results for more reliable display and matching.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

💼 Build Files
chrome: enkrypt-chrome-3bab07ae.zip
firefox: enkrypt-firefox-3bab07ae.zip

💉 Virus total analysis
chrome: 3bab07ae
firefox: 3bab07ae

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This change normalizes Ethereum contract addresses to lowercase in the transaction decoder. Market data lookups now use a lowercase key for the token contract address, and the decoded transaction's toAddress field is also lowercased before being returned.

Changes

Address normalization in transaction decoder

Layer / File(s) Summary
Lowercase market data lookup and toAddress output
packages/extension/src/providers/ethereum/libs/transaction/decoder.ts
Market info lookup and currentPriceUSD/CGToken retrieval now use tx.to!.toLowerCase() as the key, and the returned toAddress field is normalized to lowercase instead of preserving original casing.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: normalizing token address casing during market data lookup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/market-price-verify

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/extension/src/providers/ethereum/libs/transaction/decoder.ts (1)

62-73: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

LGTM on lowercase market-data lookup, minor duplication.

Lowercasing the contract address for getMarketInfoByContracts and the subsequent marketInfo lookups correctly addresses the casing mismatch. tx.to!.toLowerCase() is computed 4 times though; extracting it once would avoid the repeated work and improve readability.

♻️ Optional refactor
+        const lowerTo = tx.to!.toLowerCase();
         await marketData
           .getMarketInfoByContracts(
-            [tx.to!.toLowerCase()],
+            [lowerTo],
             network.coingeckoPlatform!,
           )
           .then(marketInfo => {
-            if (marketInfo[tx.to!.toLowerCase()]) {
+            if (marketInfo[lowerTo]) {
               currentPriceUSD =
-                marketInfo[tx.to!.toLowerCase()]!.current_price ?? 0;
-              CGToken = marketInfo[tx.to!.toLowerCase()]!.id;
+                marketInfo[lowerTo]!.current_price ?? 0;
+              CGToken = marketInfo[lowerTo]!.id;
             }
           });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/extension/src/providers/ethereum/libs/transaction/decoder.ts` around
lines 62 - 73, In the transaction decoder logic, the lowercase contract address
is computed repeatedly via tx.to!.toLowerCase() inside the market-data lookup
and response access, which adds unnecessary duplication. Refactor the flow in
the decoder.ts handler by extracting that value once into a local variable and
reusing it for getMarketInfoByContracts and the marketInfo indexing, keeping the
existing behavior in the decoder logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/extension/src/providers/ethereum/libs/transaction/decoder.ts`:
- Line 89: The DecodedTx mapping in decoder.ts is still calling toLowerCase on
tx.to via a non-null assertion, which will crash for contract-creation
transactions where tx.to is absent. Update the decoding logic around the tx.to
assignment so it safely handles undefined/null values, preserving the existing
behavior for contract creation by leaving toAddress unset or passing through the
missing value without invoking string methods.

---

Nitpick comments:
In `@packages/extension/src/providers/ethereum/libs/transaction/decoder.ts`:
- Around line 62-73: In the transaction decoder logic, the lowercase contract
address is computed repeatedly via tx.to!.toLowerCase() inside the market-data
lookup and response access, which adds unnecessary duplication. Refactor the
flow in the decoder.ts handler by extracting that value once into a local
variable and reusing it for getMarketInfoByContracts and the marketInfo
indexing, keeping the existing behavior in the decoder logic unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b55cd4ad-d20e-41c1-94a3-81e9491efee2

📥 Commits

Reviewing files that changed from the base of the PR and between df1cd61 and 3bab07a.

📒 Files selected for processing (1)
  • packages/extension/src/providers/ethereum/libs/transaction/decoder.ts

isContractCreation,
dataHex: bufferToHex(dataDecoder.data),
toAddress: tx.to!,
toAddress: tx.to!.toLowerCase(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Crash on contract-creation transactions.

tx.to can be undefined/null (see Line 17: isContractCreation = tx.to ? false : true, and the optional toAddress?: string in DecodedTx). The ! non-null assertion is compile-time only and has no runtime effect, so calling .toLowerCase() unconditionally will throw a TypeError for every contract-creation transaction, where previously tx.to was simply passed through as-is without any method call.

🐛 Proposed fix
-    toAddress: tx.to!.toLowerCase(),
+    toAddress: tx.to?.toLowerCase(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
toAddress: tx.to!.toLowerCase(),
toAddress: tx.to?.toLowerCase(),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/extension/src/providers/ethereum/libs/transaction/decoder.ts` at
line 89, The DecodedTx mapping in decoder.ts is still calling toLowerCase on
tx.to via a non-null assertion, which will crash for contract-creation
transactions where tx.to is absent. Update the decoding logic around the tx.to
assignment so it safely handles undefined/null values, preserving the existing
behavior for contract creation by leaving toAddress unset or passing through the
missing value without invoking string methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant