Skip to content

Commit bffb7ca

Browse files
committed
wip
1 parent 312e0b2 commit bffb7ca

File tree

6 files changed

+102
-41
lines changed

6 files changed

+102
-41
lines changed

packages/bridge-status-controller/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [53.0.0]
11+
12+
### Changed
13+
14+
- **BREAKING** Use CrossChain API instead of the intent manager package for intent order submission
15+
1016
## [52.0.0]
1117

1218
### Changed

packages/bridge-status-controller/src/bridge-status-controller.ts

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ import {
1919
} from '@metamask/bridge-controller';
2020
import type { TraceCallback } from '@metamask/controller-utils';
2121
import { toHex } from '@metamask/controller-utils';
22-
import type {
23-
IntentOrder,
24-
IntentSubmissionParams,
25-
} from '@metamask/intent-manager';
26-
import { IntentManager } from '@metamask/intent-manager';
27-
import { IntentOrderStatus } from '@metamask/intent-manager';
2822
import { StaticIntervalPollingController } from '@metamask/polling-controller';
2923
import type {
3024
TransactionController,
@@ -54,6 +48,9 @@ import type {
5448
} from './types';
5549
import { type BridgeStatusControllerMessenger } from './types';
5650
import { BridgeClientId } from './types';
51+
import { IntentApiImpl } from './intent-api';
52+
import { IntentOrderStatus } from './intent-order-status';
53+
import type { IntentOrder } from './intent-order';
5754
import {
5855
fetchBridgeTxStatus,
5956
getStatusRequestWithSrcTxHash,
@@ -121,8 +118,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
121118

122119
readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
123120

124-
#intentManager?: IntentManager;
125-
126121
readonly #estimateGasFeeFn: typeof TransactionController.prototype.estimateGasFee;
127122

128123
readonly #trace: TraceCallback;
@@ -205,7 +200,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
205200
this.getBridgeHistoryItemByTxMetaId.bind(this),
206201
);
207202

208-
this.#intentManager = new IntentManager();
209203
// Set interval
210204
this.setIntervalLength(REFRESH_INTERVAL_MS);
211205

@@ -294,15 +288,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
294288
});
295289
};
296290

297-
/**
298-
* Set the intent manager instance for handling intent operations
299-
*
300-
* @param intentManager - The intent manager instance
301-
*/
302-
setIntentManager(intentManager: IntentManager): void {
303-
this.#intentManager = intentManager;
304-
}
305-
306291
wipeBridgeStatus = ({
307292
address,
308293
ignoreNetwork,
@@ -710,11 +695,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
710695
readonly #fetchIntentOrderStatus = async ({
711696
bridgeTxMetaId,
712697
}: FetchBridgeTxStatusArgs) => {
713-
if (!this.#intentManager) {
714-
console.warn('Intent manager not available for status polling');
715-
return;
716-
}
717-
718698
const { txHistory } = this.state;
719699
const historyItem = txHistory[bridgeTxMetaId];
720700
if (!historyItem) {
@@ -730,13 +710,17 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
730710
const orderUid = bridgeTxMetaId.replace(/^intent:/u, '');
731711
const { srcChainId } = historyItem.quote;
732712

733-
// Extract provider name from order metadata or default to empty and let intent manager throw error
713+
// Extract provider name from order metadata or default to empty
734714
const providerName = historyItem.quote.intent?.protocol || '';
735715

736-
const intentOrder = await this.#intentManager.getOrderStatus(
716+
const intentApi = new IntentApiImpl(
717+
this.#config.customBridgeApiBaseUrl,
718+
this.#fetchFn,
719+
);
720+
const intentOrder = await intentApi.getOrderStatus(
737721
orderUid,
738722
providerName,
739-
srcChainId,
723+
srcChainId.toString(),
740724
);
741725

742726
// Update bridge history with intent order status
@@ -1511,10 +1495,6 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
15111495
}): Promise<Pick<TransactionMeta, 'id' | 'chainId' | 'type' | 'status'>> => {
15121496
const { quoteResponse, signature, accountAddress } = params;
15131497

1514-
if (!this.#intentManager) {
1515-
throw new Error('Intent manager not initialized');
1516-
}
1517-
15181498
// Build pre-confirmation properties for error tracking parity with submitTx
15191499
const account = this.messagingSystem.call(
15201500
'AccountsController:getAccountByAddress',
@@ -1576,16 +1556,21 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
15761556
intent,
15771557
);
15781558

1579-
// Submit intent order using the intent manager
1559+
const chainId = quoteResponse.quote.srcChainId;
1560+
15801561
const submissionParams = {
1581-
quote: intentQuote,
1562+
chainId: chainId.toString(),
1563+
quoteId: intentQuote.id,
15821564
signature,
1565+
order: intentQuote.metadata.order,
15831566
userAddress: accountAddress,
1584-
} as IntentSubmissionParams;
1585-
const intentOrder =
1586-
await this.#intentManager.submitIntent(submissionParams);
1567+
};
1568+
const intentApi = new IntentApiImpl(
1569+
this.#config.customBridgeApiBaseUrl,
1570+
this.#fetchFn,
1571+
);
1572+
const intentOrder = await intentApi.submitIntent(submissionParams);
15871573

1588-
const chainId = quoteResponse.quote.srcChainId;
15891574
const orderUid = intentOrder.id;
15901575

15911576
// Determine transaction type: swap for same-chain, bridge for cross-chain
@@ -1673,7 +1658,7 @@ export class BridgeStatusController extends StaticIntervalPollingController<Brid
16731658

16741659
// Record in bridge history with actual transaction metadata
16751660
try {
1676-
// Use intent: prefix for intent transactions to route to intent manager
1661+
// Use 'intent:' prefix for intent transactions
16771662
const bridgeHistoryKey = `intent:${orderUid}`;
16781663

16791664
// Create a bridge transaction metadata that includes the original txId
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { FetchFunction } from './types';
2+
3+
export interface IntentSubmissionParams {
4+
chainId: string;
5+
quoteId: string;
6+
signature: string;
7+
order: any;
8+
userAddress: string;
9+
}
10+
11+
export interface IntentApi {
12+
submitIntent(params: IntentSubmissionParams): Promise<any>;
13+
}
14+
15+
export class IntentApiImpl implements IntentApi {
16+
private baseUrl: string;
17+
private fetchFn: FetchFunction;
18+
19+
constructor(baseUrl: string, fetchFn: FetchFunction) {
20+
this.baseUrl = baseUrl;
21+
this.fetchFn = fetchFn;
22+
}
23+
24+
async submitIntent(params: IntentSubmissionParams): Promise<any> {
25+
const endpoint = `${this.baseUrl}/submitOrder`;
26+
const response = (await this.fetchFn(endpoint, {
27+
method: 'POST',
28+
headers: { 'Content-Type': 'application/json' },
29+
body: JSON.stringify(params),
30+
})) as Response;
31+
if (!response.ok) {
32+
throw new Error(`Failed to submit intent: ${response.statusText}`);
33+
}
34+
return response.json();
35+
}
36+
37+
async getOrderStatus(
38+
orderUid: string,
39+
providerName: string,
40+
srcChainId: string,
41+
): Promise<any> {
42+
const endpoint = `${this.baseUrl}/getOrderStatus?orderUid=${orderUid}&providerName=${encodeURIComponent(providerName)}&srcChainId=${srcChainId}`;
43+
const response = (await this.fetchFn(endpoint, {
44+
method: 'GET',
45+
})) as Response;
46+
if (!response.ok) {
47+
throw new Error(`Failed to get order status: ${response.statusText}`);
48+
}
49+
return response.json();
50+
}
51+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export enum IntentOrderStatus {
2+
PENDING = 'pending',
3+
SUBMITTED = 'submitted',
4+
CONFIRMED = 'confirmed',
5+
COMPLETED = 'completed',
6+
FAILED = 'failed',
7+
CANCELLED = 'cancelled',
8+
EXPIRED = 'expired',
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { IntentOrderStatus } from './intent-order-status';
2+
3+
export interface IntentOrder {
4+
id: string;
5+
status: IntentOrderStatus;
6+
txHash?: string;
7+
metadata: {
8+
txHashes?: string[] | string;
9+
};
10+
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,25 +3822,25 @@ __metadata:
38223822

38233823
"@metamask/intent-manager@file:../Intent-manager::locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller":
38243824
version: 1.0.0
3825-
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=d3eeb0&locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller"
3825+
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=bf88dd&locator=%40metamask%2Fbridge-controller%40workspace%3Apackages%2Fbridge-controller"
38263826
dependencies:
38273827
"@metamask/base-controller": "npm:^8.3.0"
38283828
"@metamask/controller-utils": "npm:^11.12.0"
38293829
"@metamask/superstruct": "npm:^3.1.0"
38303830
"@metamask/utils": "npm:^11.4.2"
3831-
checksum: 10/e2b4bc4c21e3ec29c5db997e6255eab08beb5c4f2180423842acc9268b45ac3906e3fee2b418ec737033ccbe2de6ba52551352111ac55edf526614e8a734cce9
3831+
checksum: 10/45f9c1dcf7da910d866f675473313fdce5d9e1e67008861c43912345d2e0903a44a8167763b74c7a86c89fe9d818d06c3d99788d102f81893104b23773a94acd
38323832
languageName: node
38333833
linkType: hard
38343834

38353835
"@metamask/intent-manager@file:../Intent-manager::locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller":
38363836
version: 1.0.0
3837-
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=d3eeb0&locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller"
3837+
resolution: "@metamask/intent-manager@file:../Intent-manager#../Intent-manager::hash=bf88dd&locator=%40metamask%2Fbridge-status-controller%40workspace%3Apackages%2Fbridge-status-controller"
38383838
dependencies:
38393839
"@metamask/base-controller": "npm:^8.3.0"
38403840
"@metamask/controller-utils": "npm:^11.12.0"
38413841
"@metamask/superstruct": "npm:^3.1.0"
38423842
"@metamask/utils": "npm:^11.4.2"
3843-
checksum: 10/e2b4bc4c21e3ec29c5db997e6255eab08beb5c4f2180423842acc9268b45ac3906e3fee2b418ec737033ccbe2de6ba52551352111ac55edf526614e8a734cce9
3843+
checksum: 10/45f9c1dcf7da910d866f675473313fdce5d9e1e67008861c43912345d2e0903a44a8167763b74c7a86c89fe9d818d06c3d99788d102f81893104b23773a94acd
38443844
languageName: node
38453845
linkType: hard
38463846

0 commit comments

Comments
 (0)