Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5bfa16c
feat: add accountOverride to override default recipient or delegator …
jpuri Apr 14, 2026
1d0bce3
update
jpuri Apr 15, 2026
7f9ce88
update
jpuri Apr 15, 2026
a969dd0
merge
jpuri Apr 15, 2026
f6a4071
Merge branch 'main' into acc_override_support
jpuri Apr 15, 2026
7a28240
update
jpuri Apr 15, 2026
dae645e
Merge branch 'acc_override_support' of https://github.com/MetaMask/co…
jpuri Apr 15, 2026
db25703
update
jpuri Apr 15, 2026
868b17d
update
jpuri Apr 15, 2026
68f6ac3
update
jpuri Apr 15, 2026
f83bf0f
update
jpuri Apr 15, 2026
bd9f3a0
update
jpuri Apr 15, 2026
1b7f538
update
jpuri Apr 15, 2026
45a11d7
update
jpuri Apr 15, 2026
7c350b3
Merge branch 'main' into acc_override_support
jpuri Apr 15, 2026
7e3d54f
Merge branch 'main' into acc_override_support
jpuri Apr 16, 2026
0b893bb
update
jpuri Apr 16, 2026
ef7089e
Merge branch 'acc_override_support' of https://github.com/MetaMask/co…
jpuri Apr 16, 2026
d6d0050
Merge branch 'main' into acc_override_support
jpuri Apr 16, 2026
350ff2c
update
jpuri Apr 16, 2026
2a0467b
Merge branch 'acc_override_support' of https://github.com/MetaMask/co…
jpuri Apr 16, 2026
ac28b25
update
jpuri Apr 17, 2026
9a55495
Merge branch 'main' into acc_override_support
jpuri Apr 17, 2026
14693e5
update
jpuri Apr 17, 2026
193cc90
Merge branch 'acc_override_support' of https://github.com/MetaMask/co…
jpuri Apr 17, 2026
722493b
merge
jpuri Apr 20, 2026
fe7577d
update
jpuri Apr 22, 2026
f526d8c
Merge branch 'main' into acc_override_support
jpuri Apr 22, 2026
d2a8ad4
update
jpuri Apr 22, 2026
d770b87
Merge branch 'acc_override_support' of https://github.com/MetaMask/co…
jpuri Apr 22, 2026
2383954
Merge branch 'main' into acc_override_support
jpuri Apr 22, 2026
07c7f81
fix: quote request should not be sent of amount of token requested by…
jpuri Apr 23, 2026
1122a77
update
jpuri Apr 23, 2026
58390c2
update
jpuri Apr 23, 2026
7dc9631
update
jpuri Apr 23, 2026
612e71d
Merge branch 'main' into quote_check
jpuri Apr 23, 2026
cc70919
Merge branch 'main' into quote_check
jpuri Apr 24, 2026
9db2698
update
jpuri Apr 24, 2026
6efd589
update
jpuri Apr 24, 2026
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
4 changes: 4 additions & 0 deletions packages/transaction-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- API call for quotes should not be done unless user has requested non-zero token amount. ([#8554](https://github.com/MetaMask/core/pull/8554))

## [19.3.0]

### Added
Expand Down
73 changes: 70 additions & 3 deletions packages/transaction-pay-controller/src/utils/quotes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { TransactionStatus } from '@metamask/transaction-controller';
import type { TransactionMeta } from '@metamask/transaction-controller';
import type { BatchTransaction } from '@metamask/transaction-controller';
import type {
TransactionMeta,
BatchTransaction,
} from '@metamask/transaction-controller';
import type { Hex, Json } from '@metamask/utils';
import { cloneDeep } from 'lodash';

Expand Down Expand Up @@ -51,7 +53,12 @@ const TRANSACTION_DATA_MOCK: TransactionData = {
sourceAmountRaw: '1000000000000000000',
} as TransactionPaySourceAmount,
],
tokens: [{} as TransactionPayRequiredToken],
tokens: [
{
amountRaw: '1000000',
skipIfBalance: false,
} as TransactionPayRequiredToken,
],
};

const TRANSACTION_META_MOCK = {
Expand Down Expand Up @@ -619,6 +626,66 @@ describe('Quotes Utils', () => {
expect(result).toBe(false);
});

it('does not request quotes if all required token amounts are zero', async () => {
const result = await run({
transactionData: {
...TRANSACTION_DATA_MOCK,
tokens: [
{
...TRANSACTION_DATA_MOCK.tokens[0],
amountRaw: '0',
skipIfBalance: false,
} as TransactionPayRequiredToken,
],
},
});

expect(updateTransactionDataMock).not.toHaveBeenCalled();
expect(getQuotesMock).not.toHaveBeenCalled();
expect(result).toBe(false);
});

it('requests quotes if a required token has a non-zero amount', async () => {
await run({
transactionData: {
...TRANSACTION_DATA_MOCK,
tokens: [
{
...TRANSACTION_DATA_MOCK.tokens[0],
amountRaw: '0',
skipIfBalance: false,
} as TransactionPayRequiredToken,
{
...TRANSACTION_DATA_MOCK.tokens[0],
amountRaw: '1000',
skipIfBalance: false,
} as TransactionPayRequiredToken,
],
},
});

expect(updateTransactionDataMock).toHaveBeenCalled();
});

it('requests quotes if all required token amounts are zero but isMaxAmount is true', async () => {
await run({
transactionData: {
...TRANSACTION_DATA_MOCK,
isMaxAmount: true,
tokens: [
{
...TRANSACTION_DATA_MOCK.tokens[0],
amountRaw: '0',
skipIfBalance: false,
} as TransactionPayRequiredToken,
],
},
});

expect(updateTransactionDataMock).toHaveBeenCalled();
expect(getQuotesMock).toHaveBeenCalled();
});

it('refreshes payment token balance with live on-chain balance after quotes update', async () => {
getLiveTokenBalanceMock.mockResolvedValue('9000000');

Expand Down
14 changes: 12 additions & 2 deletions packages/transaction-pay-controller/src/utils/quotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export async function updateQuotes(
return false;
}

log('Updating quotes', { transactionId });

const {
accountOverride,
isMaxAmount,
Expand All @@ -78,6 +76,18 @@ export async function updateQuotes(
tokens,
} = transactionData;

const hasNonZeroTokenAmount =
!tokens?.length ||
isMaxAmount === true ||
tokens.some((token) => !token.skipIfBalance && token.amountRaw !== '0');
Comment thread
jpuri marked this conversation as resolved.

if (!hasNonZeroTokenAmount) {
log('Skipping quotes, all token amounts are zero', { transactionId });
return false;
}

log('Updating quotes', { transactionId });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On money account page token / accountOverride can be updated few times. We need to ensure that quotes is not refetched unless user enters a non-zero token amount. Thus this change is made.

Another approach could be to change methods setTransactionConfig, 'setPaymentToken' to not refresh quote is amount of token requested is zero.

const from = accountOverride ?? (transaction.txParams.from as Hex);

updateTransactionData(transactionId, (data) => {
Expand Down
Loading