Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Handle authorization nonces
  • Loading branch information
matthewwalsh0 committed Dec 11, 2025
commit 499d0977bdce21ed4f8f8c416e91aa40149bce84
78 changes: 78 additions & 0 deletions packages/transaction-controller/src/utils/nonce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@ describe('nonce', () => {
},
status: TransactionStatus.confirmed,
},
{
id: '5',
chainId: '0x2',
networkClientId: 'testNetworkClientId',
isUserOperation: true,
time: 123460,
txParams: {
from: fromAddress,
gas: '0x104',
value: '0x204',
nonce: '0x5',
},
status: TransactionStatus.confirmed,
},
{
id: '5',
chainId: '0x2',
networkClientId: 'testNetworkClientId',
time: 123460,
txParams: {
from: fromAddress,
gas: '0x104',
value: '0x204',
},
status: TransactionStatus.confirmed,
},
];

const expectedResult: NonceTrackerTransaction[] = [
Expand All @@ -189,5 +215,57 @@ describe('nonce', () => {

expect(result).toStrictEqual(expectedResult);
});

it('includes authorization nonces from authorizationList', () => {
const fromAddress = '0x123';
const inputTransactions: TransactionMeta[] = [
{
id: '1',
chainId: '0x1',
networkClientId: 'testNetworkClientId',
time: 123456,
txParams: {
from: fromAddress,
gas: '0x100',
value: '0x200',
nonce: '0x1',
authorizationList: [
{
chainId: '0x1',
address: '0xabc',
nonce: '0x2',
r: '0x0',
s: '0x0',
yParity: '0x0',
},
{
chainId: '0x1',
address: '0xdef',
nonce: '0x3',
r: '0x0',
s: '0x0',
yParity: '0x0',
},
],
},
status: TransactionStatus.confirmed,
},
];

const result = getAndFormatTransactionsForNonceTracker(
'0x1',
fromAddress,
[TransactionStatus.confirmed],
inputTransactions,
);

expect(result).toHaveLength(3);
expect(result[0].txParams.nonce).toBe('0x1');
expect(result[1].txParams.nonce).toBe('0x2');
expect(result[2].txParams.nonce).toBe('0x3');
expect(result[0].status).toBe(TransactionStatus.confirmed);
expect(result[1].status).toBe(TransactionStatus.confirmed);
expect(result[2].status).toBe(TransactionStatus.confirmed);
});
});
});
50 changes: 33 additions & 17 deletions packages/transaction-controller/src/utils/nonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,43 @@ export function getAndFormatTransactionsForNonceTracker(
): NonceTrackerTransaction[] {
return transactions
.filter(
({ chainId, isTransfer, isUserOperation, status, txParams: { from } }) =>
({
chainId,
isTransfer,
isUserOperation,
status,
txParams: { from, nonce },
}) =>
!isTransfer &&
!isUserOperation &&
chainId === currentChainId &&
transactionStatuses.includes(status) &&
from.toLowerCase() === fromAddress.toLowerCase(),
from.toLowerCase() === fromAddress.toLowerCase() &&
nonce,
)
.map(({ status, txParams: { from, gas, value, nonce } }) => {
// the only value we care about is the nonce
// but we need to return the other values to satisfy the type
// TODO: refactor nonceTracker to not require this
/* istanbul ignore next */
return {
.flatMap(
({
status,
history: [{}],
txParams: {
from: from ?? '',
gas: gas ?? '',
value: value ?? '',
nonce: nonce ?? '',
},
};
});
txParams: { authorizationList, from, gas, value, nonce },
}) => {
const authorizationNonces = (authorizationList ?? [])
.map((authorization) => authorization.nonce)
.filter((authorizationNonce) => authorizationNonce !== undefined);

// the only value we care about is the nonce
// but we need to return the other values to satisfy the type
// TODO: refactor nonceTracker to not require this
/* istanbul ignore next */
return [nonce, ...authorizationNonces].map((currentNonce) => ({
status,
history: [{}],
txParams: {
from: from ?? '',
gas: gas ?? '',
value: value ?? '',
nonce: currentNonce ?? '',
},
}));
},
);
}
Loading