Skip to content

Commit 165c2e2

Browse files
committed
Exclude transaction from address in data address list
1 parent 2da403c commit 165c2e2

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/components/request-viewer/send-transaction.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ export function SendTransaction({
151151
{data && data !== '0x' && (
152152
<TransactionDataListItem
153153
chainId={chainId}
154-
address={to}
154+
from={from}
155+
to={to}
155156
data={data}
156157
provider={provider}
157158
/>
@@ -330,12 +331,14 @@ async function sign(
330331

331332
export function TransactionDataListItem({
332333
chainId,
333-
address,
334+
from,
335+
to,
334336
data,
335337
provider,
336338
}: {
337339
chainId: string;
338-
address: string;
340+
from: string;
341+
to: string;
339342
data: string;
340343
provider: ethers.JsonRpcProvider | undefined;
341344
}): ReactNode {
@@ -344,7 +347,7 @@ export function TransactionDataListItem({
344347
const {chainService} = useEntrances();
345348

346349
const [decoded, addresses, verified] = useAsyncValue(
347-
() => decodeTransactionData(address, data, provider),
350+
() => decodeTransactionData(from, to, data, provider),
348351
[data, provider],
349352
) ?? [data, [], undefined];
350353

@@ -430,21 +433,22 @@ export function TransactionDataListItem({
430433
const SIGNATURE_HASH_BYTE_LIKE_LENGTH = 10;
431434

432435
async function decodeTransactionData(
433-
address: string,
436+
from: string,
437+
to: string,
434438
data: string,
435439
provider: ethers.JsonRpcProvider | undefined,
436440
): Promise<[decoded: string, addresses: string[], verified: boolean]> {
437441
if (data.length < SIGNATURE_HASH_BYTE_LIKE_LENGTH) {
438442
return [data, [], false];
439443
}
440444

441-
let decoded = await decodeBySourceCode(address, data);
445+
let decoded = await decodeBySourceCode(to, data);
442446
let verified = true;
443447

444448
if (decoded === null) {
445449
// Could be a proxy.
446450

447-
const implAddress = await getImplementationAddress(address);
451+
const implAddress = await getImplementationAddress(to);
448452

449453
if (implAddress) {
450454
decoded = await decodeBySourceCode(implAddress, data);
@@ -476,7 +480,7 @@ async function decodeTransactionData(
476480
.replace(/^\[/, '(')
477481
.replace(/\]$/, ')');
478482

479-
const addresses = extractAddressesFromDecodedTransaction(decoded, address);
483+
const addresses = extractAddressesFromDecodedTransaction(decoded, [from, to]);
480484

481485
return [decodedData, addresses, verified];
482486

@@ -543,7 +547,7 @@ async function decodeTransactionData(
543547
}
544548

545549
async function getImplementationAddress(
546-
address: string,
550+
contractAddress: string,
547551
): Promise<string | undefined> {
548552
if (!provider) {
549553
return undefined;
@@ -553,7 +557,7 @@ async function decodeTransactionData(
553557
const implSlot =
554558
'0x360894A13BA1A3210667C828492DB98DCA3E2076CC3735A920A3CA505D382BBC';
555559

556-
const impl = await provider.getStorage(address, implSlot);
560+
const impl = await provider.getStorage(contractAddress, implSlot);
557561

558562
const implAddress = `0x${impl.slice(-40)}`;
559563

src/utils/abi.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {ethers} from 'ethers';
22

33
export function extractAddressesFromDecodedTransaction(
44
{fragment, args}: ethers.TransactionDescription,
5-
signerAddress: string,
5+
transactionAddresses: string[],
66
ignoreZeroAddress = true,
77
): string[] {
8-
signerAddress = ethers.getAddress(signerAddress);
8+
const transactionAddressSet = new Set(
9+
transactionAddresses.map(address => ethers.getAddress(address)),
10+
);
911

1012
const addressSet = new Set<string>();
1113

@@ -19,7 +21,7 @@ export function extractAddressesFromDecodedTransaction(
1921
return;
2022
}
2123

22-
if (value === signerAddress) {
24+
if (transactionAddressSet.has(value)) {
2325
return;
2426
}
2527

0 commit comments

Comments
 (0)