Skip to content

chore: stop quote polling when tx submission has started #5994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 18, 2025
Merged
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/bridge-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]

### Added

- Add `stopPollingForQuotes` handler that stops quote polling without resetting the bridge controller's state ([#5994](https://github.com/MetaMask/core/pull/5994))

## [32.2.0]

### Changed
Expand Down
12 changes: 10 additions & 2 deletions packages/bridge-controller/src/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
`${BRIDGE_CONTROLLER_NAME}:trackUnifiedSwapBridgeEvent`,
this.trackUnifiedSwapBridgeEvent.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:stopPollingForQuotes`,
this.stopPollingForQuotes.bind(this),
);
}

_executePoll = async (pollingInput: BridgePollingInput) => {
Expand Down Expand Up @@ -413,9 +417,13 @@ export class BridgeController extends StaticIntervalPollingController<BridgePoll
);
};

resetState = () => {
stopPollingForQuotes = (reason?: string) => {
this.stopAllPolling();
this.#abortController?.abort(RESET_STATE_ABORT_MESSAGE);
this.#abortController?.abort(reason);
};

resetState = () => {
this.stopPollingForQuotes(RESET_STATE_ABORT_MESSAGE);

this.update((state) => {
// Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export enum BridgeBackgroundAction {
RESET_STATE = 'resetState',
GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',
TRACK_METAMETRICS_EVENT = 'trackUnifiedSwapBridgeEvent',
STOP_POLLING_FOR_QUOTES = 'stopPollingForQuotes',
}

export type BridgeControllerState = {
Expand Down Expand Up @@ -382,6 +383,7 @@ export type BridgeControllerActions =
| BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>
| BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>
| BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>
| BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>
| BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;

export type BridgeControllerEvents = ControllerStateChangeEvent<
Expand Down
8 changes: 8 additions & 0 deletions packages/bridge-status-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **BREAKING:** BridgeStatusController now requires the `BridgeController:stopPollingForQuotes` action permission ([#5994](https://github.com/MetaMask/core/pull/5994))

### Changed

- **BREAKING:** Adds a call to bridge-controller's `stopPollingForQuotes` handler to prevent quotes from refreshing during tx submission. This enables "pausing" the quote polling loop without resetting the entire state. Without this, it's possible for the activeQuote to change while the UI's tx submission is in-progress ([#5994](https://github.com/MetaMask/core/pull/5994))

## [30.0.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ Object {

exports[`BridgeStatusController submitTx: EVM bridge should delay after submitting linea approval 3`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -716,6 +719,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should handle smart accounts (4337) 4`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand All @@ -735,7 +741,7 @@ Array [
],
Array [
"AccountsController:getAccountByAddress",
"",
"0xaccount1",
],
Array [
"BridgeController:trackUnifiedSwapBridgeEvent",
Expand Down Expand Up @@ -979,6 +985,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should handle smart transactions 5`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -1273,6 +1282,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should reset USDT allowance 5`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"BridgeController:getBridgeERC20Allowance",
"0x0000000000000000000000000000000000000000",
Expand Down Expand Up @@ -1533,6 +1545,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should successfully submit an EVM bridge transaction with approval 4`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -1774,6 +1789,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should successfully submit an EVM bridge transaction with no approval 5`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -1861,6 +1879,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should throw an error if approval tx fails 2`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -1902,6 +1923,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM bridge should throw an error if approval tx meta is undefined 2`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -2061,6 +2085,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM swap should handle smart accounts (4337) 4`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -2324,6 +2351,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM swap should handle smart transactions 5`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -2548,6 +2578,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM swap should successfully submit an EVM swap transaction with approval 4`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -2789,6 +2822,9 @@ Array [

exports[`BridgeStatusController submitTx: EVM swap should successfully submit an EVM swap transaction with no approval 5`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getAccountByAddress",
"0xaccount1",
Expand Down Expand Up @@ -2851,6 +2887,9 @@ Array [

exports[`BridgeStatusController submitTx: Solana should successfully submit a Solana transaction 1`] = `
Array [
Array [
"BridgeController:stopPollingForQuotes",
],
Array [
"AccountsController:getSelectedMultichainAccount",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ describe('BridgeStatusController', () => {
});

it('should successfully submit a Solana transaction', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce(mockSolanaAccount);
mockMessengerCall.mockResolvedValueOnce('signature');

Expand All @@ -1482,6 +1483,7 @@ describe('BridgeStatusController', () => {
});

it('should throw error when snap ID is missing', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // stopPollingForQuotes
const accountWithoutSnap = {
...mockSelectedAccount,
metadata: { snap: undefined },
Expand Down Expand Up @@ -1514,6 +1516,7 @@ describe('BridgeStatusController', () => {
});

it('should handle snap controller errors', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce(mockSolanaAccount);
// Mock the RemoteFeatureFlagController:getState call that happens in getBridgeFeatureFlags
mockMessengerCall.mockReturnValueOnce({
Expand Down Expand Up @@ -1675,10 +1678,10 @@ describe('BridgeStatusController', () => {
});

mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
};

it('should successfully submit an EVM bridge transaction with approval', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupApprovalMocks();
setupBridgeMocks();

Expand All @@ -1704,6 +1707,7 @@ describe('BridgeStatusController', () => {
});

it('should successfully submit an EVM bridge transaction with no approval', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupBridgeMocks();

const { controller, startPollingForBridgeTxStatusSpy } =
Expand Down Expand Up @@ -1748,6 +1752,7 @@ describe('BridgeStatusController', () => {
});

it('should handle smart transactions', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupBridgeMocks();

const { controller, startPollingForBridgeTxStatusSpy } =
Expand All @@ -1774,6 +1779,7 @@ describe('BridgeStatusController', () => {
});

it('should handle smart accounts (4337)', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce({
...mockSelectedAccount,
type: EthAccountType.Erc4337,
Expand All @@ -1791,7 +1797,10 @@ describe('BridgeStatusController', () => {
mockMessengerCall.mockReturnValueOnce({
transactions: [mockEvmTxMeta],
});
estimateGasFeeFn.mockResolvedValueOnce(mockEstimateGasFeeResult);
mockMessengerCall.mockReturnValueOnce({
...mockSelectedAccount,
type: EthAccountType.Erc4337,
});

const { controller, startPollingForBridgeTxStatusSpy } =
getController(mockMessengerCall);
Expand Down Expand Up @@ -1836,6 +1845,7 @@ describe('BridgeStatusController', () => {
});

it('should reset USDT allowance', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockIsEthUsdt.mockReturnValueOnce(true);

// USDT approval reset
Expand Down Expand Up @@ -1870,6 +1880,7 @@ describe('BridgeStatusController', () => {
});

it('should throw an error if approval tx fails', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
mockMessengerCall.mockReturnValueOnce('arbitrum-client-id');
mockMessengerCall.mockReturnValueOnce({
Expand All @@ -1892,6 +1903,7 @@ describe('BridgeStatusController', () => {
});

it('should throw an error if approval tx meta is undefined', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
mockMessengerCall.mockReturnValueOnce('arbitrum-client-id');
mockMessengerCall.mockReturnValueOnce({
Expand Down Expand Up @@ -1922,6 +1934,7 @@ describe('BridgeStatusController', () => {
});

it('should delay after submitting linea approval', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
const handleLineaDelaySpy = jest
.spyOn(transactionUtils, 'handleLineaDelay')
.mockResolvedValueOnce();
Expand Down Expand Up @@ -2080,10 +2093,10 @@ describe('BridgeStatusController', () => {
});

mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
mockMessengerCall.mockReturnValueOnce(mockSelectedAccount);
};

it('should successfully submit an EVM swap transaction with approval', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupApprovalMocks();
setupBridgeMocks();

Expand All @@ -2109,6 +2122,7 @@ describe('BridgeStatusController', () => {
});

it('should successfully submit an EVM swap transaction with no approval', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupBridgeMocks();

const { controller, startPollingForBridgeTxStatusSpy } =
Expand Down Expand Up @@ -2153,6 +2167,7 @@ describe('BridgeStatusController', () => {
});

it('should handle smart transactions', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
setupBridgeMocks();

const { controller, startPollingForBridgeTxStatusSpy } =
Expand All @@ -2179,6 +2194,7 @@ describe('BridgeStatusController', () => {
});

it('should handle smart accounts (4337)', async () => {
mockMessengerCall.mockImplementationOnce(jest.fn()); // BridgeController:stopPollingForQuotes
mockMessengerCall.mockReturnValueOnce({
...mockSelectedAccount,
type: EthAccountType.Erc4337,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
quoteResponse: QuoteResponse<TxData | string> & QuoteMetadata,
isStxEnabledOnClient: boolean,
): Promise<TransactionMeta & Partial<SolanaTransactionMeta>> => {
this.messagingSystem.call('BridgeController:stopPollingForQuotes');

let txMeta: (TransactionMeta & Partial<SolanaTransactionMeta>) | undefined;

const isBridgeTx = isCrossChain(
Expand Down
1 change: 1 addition & 0 deletions packages/bridge-status-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ type AllowedActions =
| TransactionControllerGetStateAction
| BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>
| BridgeControllerAction<BridgeBackgroundAction.TRACK_METAMETRICS_EVENT>
| BridgeControllerAction<BridgeBackgroundAction.STOP_POLLING_FOR_QUOTES>
| GetGasFeeState
| AccountsControllerGetAccountByAddressAction
| RemoteFeatureFlagControllerGetStateAction;
Expand Down
Loading