Skip to content

Commit 9963092

Browse files
BitHighlanderclaude
andcommitted
fix(tron): scope trc20-transfer event caip to the token contract
Review follow-up to the caip-match gate in #48: dApp TRC-20 events were still emitting caip: TRON_CAIP (tron:27Lqcw/slip44:195 — the native-TRX caip). The UI's ctx.caip === event.caip guard matched when the user had TRX selected in the side panel, leaking the TRX symbol/icon onto a USDT approval — exactly the failure the gate was supposed to block. Emit a token-scoped caip for trc20-transfer: tron:27Lqcw/token:${decoded.contractAddress} Now the fallback only fires when the side-panel happened to have this exact token selected. Any other selection (TRX, a different TRC-20, or an unrelated chain) leaves symbol/icon empty, which is the correct behavior — the handler still populates payment.decimals=0 so amounts render as raw base units. trx-transfer keeps TRON_CAIP (legitimate native TRX match desired). contract-call keeps TRON_CAIP too — its renderer owns its own labels (Contract:, Function:, "TRX sent:") with a hardcoded 'TRX' fallback on the call_value row, so the caip match affects only the avatar icon. Not worth the extra complexity. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2c69b54 commit 9963092

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

chrome-extension/src/background/chains/tronHandler.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,25 @@ export const handleTronRequest = async (
603603
// token display should teach decodeTronTx to look up decimals
604604
// from assetData or an on-chain call — not a fix for this PR.
605605
const decimals = decoded.kind === 'trc20-transfer' ? 0 : 6;
606+
// For TRC-20 events, scope the caip to the specific token
607+
// contract so the UI's ctx.caip-match gate only fires when the
608+
// side-panel had THIS token selected. Otherwise a dApp USDT
609+
// transfer with the user on the TRX asset page would match
610+
// (both sides = tron:27Lqcw/slip44:195) and render with the TRX
611+
// symbol/icon — the exact leak #48's gate was meant to block.
612+
//
613+
// Native TRX and generic contract-call stay on TRON_CAIP:
614+
// trx-transfer is native TRX so matching the TRX context is
615+
// correct; contract-call renders its own Contract/Function UI
616+
// with a hardcoded 'TRX' fallback on the call_value row, so a
617+
// partial caip-match can't leak the wrong symbol into anything
618+
// user-facing.
619+
const eventCaip =
620+
decoded.kind === 'trc20-transfer' && decoded.contractAddress
621+
? `${TRON_NETWORK_ID}/token:${decoded.contractAddress}`
622+
: TRON_CAIP;
606623
const event = buildEvent(requestInfo, 'transfer', params, {
607-
caip: TRON_CAIP,
624+
caip: eventCaip,
608625
from: sender,
609626
to: decoded.toAddress,
610627
amount: decoded.displayAmount,

0 commit comments

Comments
 (0)