Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `predictAcrossWithdraw` to the `TransactionType` enum ([#8759](https://github.com/MetaMask/core/pull/8759))

### Fixed

- Respect `excludeNativeTokenForFee` when publishing transactions with a selected gas fee token ([#8762](https://github.com/MetaMask/core/pull/8762))

## [65.3.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,36 @@ describe('Gas Fee Tokens Utils', () => {
expect(request.transaction.txParams.nonce).toBeUndefined();
});

it('sets external sign when native token is excluded for fees', async () => {
request.transaction.excludeNativeTokenForFee = true;
request.transaction.isGasFeeTokenIgnoredIfBalance = false;
request.transaction.selectedGasFeeToken = TOKEN_ADDRESS_1_MOCK;
request.transaction.gasFeeTokens = [];
request.transaction.isExternalSign = false;
request.transaction.txParams.nonce = '0x1';

jest.mocked(request.fetchGasFeeTokens).mockResolvedValueOnce([
{
tokenAddress: TOKEN_ADDRESS_1_MOCK,
} as GasFeeToken,
]);

await checkGasFeeTokenBeforePublish(request);

jest
.mocked(request.updateTransaction)
.mock.calls[0][1](request.transaction);

expect(isNativeBalanceSufficientForGasMock).not.toHaveBeenCalled();
expect(request.fetchGasFeeTokens).toHaveBeenCalledWith(
expect.objectContaining({
isExternalSign: true,
}),
);
expect(request.transaction.isExternalSign).toBe(true);
expect(request.transaction.txParams.nonce).toBeUndefined();
});

it('removes selected gas fee token if native balance sufficient', async () => {
request.transaction.isGasFeeTokenIgnoredIfBalance = true;
request.transaction.selectedGasFeeToken = TOKEN_ADDRESS_1_MOCK;
Expand All @@ -503,7 +533,7 @@ describe('Gas Fee Tokens Utils', () => {
expect(request.updateTransaction).not.toHaveBeenCalled();
});

it('does nothing if not ignoring gas fee token when native balance sufficient', async () => {
it('does nothing if not ignoring gas fee token and native token is allowed for fees', async () => {
request.transaction.selectedGasFeeToken = TOKEN_ADDRESS_1_MOCK;
request.transaction.isGasFeeTokenIgnoredIfBalance = false;

Expand Down
41 changes: 25 additions & 16 deletions packages/transaction-controller/src/utils/gas-fee-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,40 @@ export async function checkGasFeeTokenBeforePublish({
fn: (tx: TransactionMeta) => void,
) => void;
}): Promise<void> {
const { isGasFeeTokenIgnoredIfBalance, selectedGasFeeToken } = transaction;
const {
excludeNativeTokenForFee,
isGasFeeTokenIgnoredIfBalance,
selectedGasFeeToken,
} = transaction;

if (!selectedGasFeeToken || !isGasFeeTokenIgnoredIfBalance) {
if (
!selectedGasFeeToken ||
(!isGasFeeTokenIgnoredIfBalance && !excludeNativeTokenForFee)
) {
return;
}

log('Checking gas fee token before publish', { selectedGasFeeToken });

const hasNativeBalance = await isNativeBalanceSufficientForGas(
transaction,
messenger,
networkClientId,
);

if (hasNativeBalance) {
log(
'Ignoring gas fee token before publish due to sufficient native balance',
if (!excludeNativeTokenForFee) {
const hasNativeBalance = await isNativeBalanceSufficientForGas(
transaction,
messenger,
networkClientId,
);

updateTransaction(transaction.id, (tx) => {
tx.isExternalSign = false;
tx.selectedGasFeeToken = undefined;
});
if (hasNativeBalance) {
log(
'Ignoring gas fee token before publish due to sufficient native balance',
);

return;
updateTransaction(transaction.id, (tx) => {
tx.isExternalSign = false;
tx.selectedGasFeeToken = undefined;
});

return;
}
}

const gasFeeTokens = await fetchGasFeeTokens({
Expand Down
4 changes: 4 additions & 0 deletions packages/transaction-pay-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add Across quote support for post-quote Predict withdraw flows ([#8760](https://github.com/MetaMask/core/pull/8760))
- Add Across strategy plumbing to identify post-quote Predict withdraw requests ([#8759](https://github.com/MetaMask/core/pull/8759))

### Fixed

- Handle gas-station and prefunded gas-estimate edge cases for Across Predict withdraw quotes ([#8762](https://github.com/MetaMask/core/pull/8762))

## [22.2.0]

### Changed
Expand Down
Loading
Loading