Skip to content

fix(scan): prefix indexer-rs txids with 0x before passing to viem#78

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/scan-tx-id-prefix-evm-canonical
May 14, 2026
Merged

fix(scan): prefix indexer-rs txids with 0x before passing to viem#78
github-actions[bot] merged 1 commit into
mainfrom
fix/scan-tx-id-prefix-evm-canonical

Conversation

@satyakwok
Copy link
Copy Markdown
Member

@satyakwok satyakwok commented May 14, 2026

Why

Operator clicked a tx detail page and got the global error boundary ("Terjadi kesalahan") instead of the tx data. The indexer-rs API returned the tx correctly; the failure was client-side.

Cause: indexer-rs stores txids bare ("0b3187c4e9e4..."). normalizeTx in lib/api.ts copied that as-is into TransactionData.id. Downstream consumers TokenTransfers + TxLogs then passed tx.id straight into viem's getTransactionReceipt({ hash }) — viem's Hash type is \0x${string}`` and the bare form throws at runtime. Uncaught throw → error boundary.

What

Prefix 0x once at the normalizer boundary so every caller downstream gets EVM-canonical form. Two sites:

  • normalizeTx (single-tx detail)
  • fetchLatestTransactions (list mapper)

Both check startsWith("0x") before prepending, so a future indexer that already serves prefixed txids stays a no-op.

Verify

Hard-reload https://scan.sentrixchain.com/tx/0x0b3187c4e9e4b36da940f1447b75b2bd89102ccbc36e2fd654942b2e84c94375 after deploy — should render the WSRX deposit details with the Tokens Transferred panel populated, no error boundary.

Summary by CodeRabbit

  • Bug Fixes
    • Transaction IDs are now consistently formatted with the EVM-canonical 0x prefix for uniform display across the app.

Review Change Stack

indexer-rs stores txids bare ("0b3187..."). normalizeTx + the list
mapper copied them as-is into TransactionData.id, so downstream
consumers — TokenTransfers + TxLogs — passed the bare form into
viem's getTransactionReceipt({ hash }), which expects `0x${string}`
and throws otherwise. The throw escaped to the global error
boundary → user saw 'Terjadi kesalahan' instead of the tx detail.

Prefix once at the normalizer boundary so every caller of
TransactionData.id gets the EVM-canonical form.
@github-actions github-actions Bot enabled auto-merge (squash) May 14, 2026 01:10
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR normalizes transaction IDs returned by the backend to consistently use the EVM-canonical 0x... format. The normalizeTx function now prefixes bare txid values with 0x when constructing TransactionData.id. The same normalization pattern is applied in fetchLatestTransactions when mapping latest transaction rows. This ensures downstream consumers receive transaction IDs in a uniform format regardless of how the backend returns them.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main fix: prefixing txids with 0x in the scan module to ensure viem compatibility.
Description check ✅ Passed The description includes a clear summary of the problem and solution. The 'Verify' section serves as a manual test plan, though it lacks a formal test plan checklist as specified in the template.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/scan-tx-id-prefix-evm-canonical

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 skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@apps/scan/lib/api.ts`:
- Around line 391-392: Extract a shared helper function normalizeTxid(txid:
string) that ensures a single lowercase "0x" prefix: if txid is falsy return it,
if it matches /^0x/i return txid.replace(/^0x/i, "0x"), else return "0x" + txid.
Replace the inline logic that builds id (the `const id = txid &&
!txid.startsWith("0x") ? \`0x\${txid}\` : txid;` expression and the similar
occurrence later) to call normalizeTxid(txid) so both mappings use the same
case-insensitive normalizer.
🪄 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 Plus

Run ID: 8ab2b763-eb36-4adb-8ee6-2525628ed5ad

📥 Commits

Reviewing files that changed from the base of the PR and between d0248b8 and a874ac0.

📒 Files selected for processing (1)
  • apps/scan/lib/api.ts

Comment thread apps/scan/lib/api.ts
Comment on lines +391 to 392
const id = txid && !txid.startsWith("0x") ? `0x${txid}` : txid;
return {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use one case-insensitive txid normalizer for both mappings.

At Line 391 and Line 438, startsWith("0x") is case-sensitive, so 0X... gets double-prefixed (0x0X...). Extract a shared helper and use /^0x/i to avoid malformed IDs and future drift.

Proposed patch
+function normalizeEvmTxId(txid?: string): string {
+  const v = (txid ?? "").trim();
+  if (!v) return "";
+  return /^0x/i.test(v) ? `0x${v.slice(2)}` : `0x${v}`;
+}
+
 function normalizeTx(raw: RawTxDetail): TransactionData | null {
   const tx = raw.transaction;
   if (!tx) return null;
@@
-  const txid = tx.txid ?? "";
-  const id = txid && !txid.startsWith("0x") ? `0x${txid}` : txid;
+  const id = normalizeEvmTxId(tx.txid);
   return {
     id,
@@
   const rows = Array.isArray(res) ? res : (res.transactions ?? []);
   return rows.map((t): TransactionData => ({
-    id: t.txid && !t.txid.startsWith("0x") ? `0x${t.txid}` : t.txid,
+    id: normalizeEvmTxId(t.txid),
     from: t.from,

Also applies to: 438-438

🤖 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 `@apps/scan/lib/api.ts` around lines 391 - 392, Extract a shared helper
function normalizeTxid(txid: string) that ensures a single lowercase "0x"
prefix: if txid is falsy return it, if it matches /^0x/i return
txid.replace(/^0x/i, "0x"), else return "0x" + txid. Replace the inline logic
that builds id (the `const id = txid && !txid.startsWith("0x") ? \`0x\${txid}\`
: txid;` expression and the similar occurrence later) to call
normalizeTxid(txid) so both mappings use the same case-insensitive normalizer.

@github-actions github-actions Bot merged commit 931154c into main May 14, 2026
7 checks passed
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