Skip to content

refactor: extract more bridge-status-controller calls to utils#8215

Open
micaelae wants to merge 17 commits intomainfrom
swaps4229-extract-controller-calls
Open

refactor: extract more bridge-status-controller calls to utils#8215
micaelae wants to merge 17 commits intomainfrom
swaps4229-extract-controller-calls

Conversation

@micaelae
Copy link
Member

@micaelae micaelae commented Mar 17, 2026

Explanation

Changes

  • Move more code out of bridge-status-controller.ts
  • Replace IntentApi.submitOrder with a pure function postSubmitOrder
  • Update tests to serve as a baseline for the submitTx + submitIntent refactor

References

Fixes https://consensyssoftware.atlassian.net/browse/SWAPS-4229

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Medium risk because it refactors transaction submission, history keying, and intent-order submission/polling paths; behavior changes around txHash/action IDs and batching could affect bridge/swap tracking if edge cases are missed.

Overview
Refactors bridge-status-controller by moving more transaction-handling logic into utils/transaction (e.g., submitEvmTransaction, addTransactionBatch, tx lookup/update helpers, delegated-account check) and shifting gas-fee estimation helpers out of utils/gas.

Intent order submission is changed from IntentApiImpl.submitIntent to a pure postSubmitOrder function, and intent polling/translation now treats missing hashes as undefined (not empty string) while updating transactions via shared transaction helpers.

History handling is tightened: StartPollingForBridgeTxStatusArgs no longer requires a statusRequest, history keys can fall back to originalTransactionId, and new utils/history tests cover rekeying and key selection; snapshots/tests are updated accordingly (including added coverage for handleNonEvmTx response shapes and updated metrics tracking expectations).

Written by Cursor Bugbot for commit 3ab2f3b. This will update automatically on new commits. Configure here.

@micaelae micaelae force-pushed the swaps4229-extract-controller-calls branch 7 times, most recently from 8eca356 to 682da9c Compare March 18, 2026 19:36
Base automatically changed from swaps3560-submitTx-handlers to main March 19, 2026 17:16
@micaelae micaelae force-pushed the swaps4229-extract-controller-calls branch 3 times, most recently from 4f33f5d to 8cade9a Compare March 19, 2026 21:32
@micaelae micaelae force-pushed the swaps4229-extract-controller-calls branch 3 times, most recently from 71783df to 72a6c00 Compare March 19, 2026 23:32
@micaelae micaelae changed the title Swaps4229 extract controller calls refactor: extract more bridge-status-controller calls to utils Mar 19, 2026
Comment on lines +2057 to +2058
jest.spyOn(Date, 'now').mockReturnValueOnce(1234567890);
jest.spyOn(Date, 'now').mockReturnValueOnce(1234567891);
Copy link
Member Author

Choose a reason for hiding this comment

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

Added Date.now mocks for more accurate actionId snapshot tests, and to make sure actionId usage is preserved after submitTx and submiIntent are unified

StatusResponse,
} from '../types';

describe('History Utils', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved these tests from transaction.test.ts


describe('getIntentFromQuote', () => {
it('returns intent when present in quote response', () => {
const mockIntent = { protocol: 'cowswap', order: { some: 'data' } };
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved from transaction.test.ts

clientId: BridgeClientId,
): Promise<IntentStatusResponse> {
const endpoint = `${this.#baseUrl}/submitOrder`;
try {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced this with a pure function postSubmitOrder to decouple it from the IntentApi classes. This is in preparation for submitTx+submitIntent unification

bridgeTxMeta: txMeta, // Only the id field is used by the BridgeStatusController
statusRequest: {
...getStatusRequestParams(quoteResponse),
srcTxHash: txMeta.hash,
Copy link
Member Author

Choose a reason for hiding this comment

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

The statusRequest's data is also present in quoteResponse and bridgeTxMeta so this is ok to remove

@micaelae micaelae marked this pull request as ready for review March 20, 2026 00:22
@micaelae micaelae requested review from a team as code owners March 20, 2026 00:22
@micaelae micaelae enabled auto-merge March 20, 2026 00:25
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants