Skip to content
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
11 changes: 9 additions & 2 deletions apps/scan/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,15 @@ interface RawTxDetail {
function normalizeTx(raw: RawTxDetail): TransactionData | null {
const tx = raw.transaction;
if (!tx) return null;
// indexer-rs stores txids bare (no 0x prefix). Downstream consumers —
// TokenTransfers + TxLogs — pass tx.id straight into viem's
// getTransactionReceipt({ hash }) which expects `0x${string}` and throws
// otherwise (uncaught → global error boundary). Prefix here so every
// caller of TransactionData.id gets the EVM-canonical form.
const txid = tx.txid ?? "";
const id = txid && !txid.startsWith("0x") ? `0x${txid}` : txid;
return {
Comment on lines +391 to 392
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.

id: tx.txid ?? "",
id,
from: tx.from_address ?? "",
to: tx.to_address ?? "",
amount: toSrx(tx.amount ?? 0),
Expand Down Expand Up @@ -428,7 +435,7 @@ export async function fetchLatestTransactions(network: NetworkId, count = 10) {
if (!res) return [];
const rows = Array.isArray(res) ? res : (res.transactions ?? []);
return rows.map((t): TransactionData => ({
id: t.txid,
id: t.txid && !t.txid.startsWith("0x") ? `0x${t.txid}` : t.txid,
from: t.from,
to: t.to,
amount: toSrx(t.amount ?? 0),
Expand Down
Loading