@metamask-previews/bridge-status-controller 75.4.0-preview-4f4c98e → 75.4.0-preview-3866c0ff1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,108 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _IntentManager_instances, _IntentManager_messenger, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
13
1
  import { StatusTypes } from '@metamask/bridge-controller';
14
2
  import { getJwt } from './utils/authentication.js';
15
3
  import { IntentApiImpl, translateIntentOrderToBridgeStatus, } from './utils/intent-api.js';
16
4
  import { getTransactionMetaById, updateTransaction, } from './utils/transaction.js';
17
5
  export class IntentManager {
6
+ #messenger;
7
+ intentApi;
8
+ #intentStatusesByBridgeTxMetaId = new Map();
18
9
  constructor({ messenger, customBridgeApiBaseUrl, fetchFn, }) {
19
- _IntentManager_instances.add(this);
20
- _IntentManager_messenger.set(this, void 0);
21
- _IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
22
- /**
23
- * Get the status of an intent order.
24
- *
25
- * @param bridgeTxMetaId - The bridge transaction meta ID.
26
- * @param protocol - The protocol of the intent.
27
- * @param clientId - The client ID.
28
- * @returns The intent order mapped status.
29
- */
30
- this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash) => {
31
- try {
32
- const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
33
- return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash);
34
- }
35
- catch (error) {
36
- if (error instanceof Error) {
37
- throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
38
- }
39
- return undefined;
40
- }
10
+ this.#messenger = messenger;
11
+ this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await getJwt(messenger));
12
+ }
13
+ /**
14
+ * Set the intent statuses for a given bridge transaction.
15
+ *
16
+ * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).
17
+ * @param order - The intent order.
18
+ * @param srcChainId - The source chain ID.
19
+ * @param txHash - The transaction hash.
20
+ * @returns The intent statuses.
21
+ */
22
+ #setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
23
+ const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
24
+ const intentStatuses = {
25
+ orderStatus: order.status,
26
+ bridgeStatus,
41
27
  };
42
- /**
43
- * Sync the transaction status from the intent status.
44
- *
45
- * @param bridgeTxMetaId - The bridge transaction meta ID.
46
- * @param historyItem - The history item.
47
- */
48
- this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
49
- // Update the actual transaction in TransactionController to sync with intent status
50
- // Use the original transaction ID (not the bridge history key)
51
- const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
52
- if (!originalTxId) {
53
- return;
28
+ this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);
29
+ return intentStatuses;
30
+ }
31
+ /**
32
+ * Get the status of an intent order.
33
+ *
34
+ * @param bridgeTxMetaId - The bridge transaction meta ID.
35
+ * @param protocol - The protocol of the intent.
36
+ * @param clientId - The client ID.
37
+ * @returns The intent order mapped status.
38
+ */
39
+ getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash) => {
40
+ try {
41
+ const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
42
+ return this.#setIntentStatuses(bridgeTxMetaId, orderStatus, srcChainId, txHash);
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Error) {
46
+ throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
54
47
  }
55
- const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
56
- if (!intentStatuses) {
48
+ return undefined;
49
+ }
50
+ };
51
+ /**
52
+ * Sync the transaction status from the intent status.
53
+ *
54
+ * @param bridgeTxMetaId - The bridge transaction meta ID.
55
+ * @param historyItem - The history item.
56
+ */
57
+ syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
58
+ // Update the actual transaction in TransactionController to sync with intent status
59
+ // Use the original transaction ID (not the bridge history key)
60
+ const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
61
+ if (!originalTxId) {
62
+ return;
63
+ }
64
+ const intentStatuses = this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);
65
+ if (!intentStatuses) {
66
+ return;
67
+ }
68
+ try {
69
+ // Merge with existing TransactionMeta to avoid wiping required fields
70
+ const existingTxMeta = getTransactionMetaById(this.#messenger, originalTxId);
71
+ if (!existingTxMeta) {
72
+ console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
57
73
  return;
58
74
  }
59
- try {
60
- // Merge with existing TransactionMeta to avoid wiping required fields
61
- const existingTxMeta = getTransactionMetaById(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), originalTxId);
62
- if (!existingTxMeta) {
63
- console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
64
- return;
75
+ const { bridgeStatus, orderStatus } = intentStatuses;
76
+ const txHash = bridgeStatus?.txHash;
77
+ const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;
78
+ const isFinalStatus = bridgeStatus?.status.status === StatusTypes.COMPLETE ||
79
+ bridgeStatus?.status.status === StatusTypes.FAILED;
80
+ const existingTxReceipt = existingTxMeta.txReceipt;
81
+ const txReceiptUpdate = txHash
82
+ ? {
83
+ txReceipt: {
84
+ ...existingTxReceipt,
85
+ transactionHash: txHash,
86
+ status: isComplete ? '0x1' : '0x0',
87
+ },
65
88
  }
66
- const { bridgeStatus, orderStatus } = intentStatuses;
67
- const txHash = bridgeStatus?.txHash;
68
- const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;
69
- const isFinalStatus = bridgeStatus?.status.status === StatusTypes.COMPLETE ||
70
- bridgeStatus?.status.status === StatusTypes.FAILED;
71
- const existingTxReceipt = existingTxMeta.txReceipt;
72
- const txReceiptUpdate = txHash
73
- ? {
74
- txReceipt: {
75
- ...existingTxReceipt,
76
- transactionHash: txHash,
77
- status: isComplete ? '0x1' : '0x0',
78
- },
79
- }
80
- : {};
81
- updateTransaction(__classPrivateFieldGet(this, _IntentManager_messenger, "f"), existingTxMeta, {
82
- status: bridgeStatus?.transactionStatus,
83
- ...(txHash ? { hash: txHash } : {}),
84
- ...txReceiptUpdate,
85
- }, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
86
- if (isFinalStatus) {
87
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
88
- }
89
- }
90
- catch (error) {
91
- console.error('[Intent polling] Failed to update transaction status', {
92
- originalTxId,
93
- bridgeHistoryKey: bridgeTxMetaId,
94
- error,
95
- });
89
+ : {};
90
+ updateTransaction(this.#messenger, existingTxMeta, {
91
+ status: bridgeStatus?.transactionStatus,
92
+ ...(txHash ? { hash: txHash } : {}),
93
+ ...txReceiptUpdate,
94
+ }, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
95
+ if (isFinalStatus) {
96
+ this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);
96
97
  }
97
- };
98
- __classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
99
- this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, async () => await getJwt(messenger));
100
- }
101
- }
102
- _IntentManager_messenger = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
103
- const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
104
- const intentStatuses = {
105
- orderStatus: order.status,
106
- bridgeStatus,
98
+ }
99
+ catch (error) {
100
+ console.error('[Intent polling] Failed to update transaction status', {
101
+ originalTxId,
102
+ bridgeHistoryKey: bridgeTxMetaId,
103
+ error,
104
+ });
105
+ }
107
106
  };
108
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
109
- return intentStatuses;
110
- };
107
+ }
111
108
  //# sourceMappingURL=bridge-status-controller.intent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.intent.js","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAO1E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAEL,aAAa,EAEb,kCAAkC,GACnC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAQhC,MAAM,OAAO,aAAa;IAQxB,YAAY,EACV,SAAS,EACT,sBAAsB,EACtB,OAAO,GAKR;;QAfQ,2CAA4C;QA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C,CAAC;QA5JA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAChC,sBAAsB,EACtB,OAAO,EACP,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CACpC,CAAC;IACJ,CAAC;CAuJF;gOA1IG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAe;IAEf,MAAM,YAAY,GAAG,kCAAkC,CACrD,KAAK,EACL,UAAU,EACV,MAAM,CACP,CAAC;IACF,MAAM,cAAc,GAAmB;QACrC,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,YAAY;KACb,CAAC;IACF,uBAAA,IAAI,qDAAgC,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { BridgeClientId, StatusTypes } from '@metamask/bridge-controller';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n} from './types.js';\nimport type { BridgeHistoryItem } from './types.js';\nimport { getJwt } from './utils/authentication.js';\nimport {\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api.js';\nimport {\n getTransactionMetaById,\n updateTransaction,\n} from './utils/transaction.js';\nimport { IntentStatusResponse, IntentOrderStatus } from './utils/validators.js';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n customBridgeApiBaseUrl,\n fetchFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n }) {\n this.#messenger = messenger;\n this.intentApi = new IntentApiImpl(\n customBridgeApiBaseUrl,\n fetchFn,\n async () => await getJwt(messenger),\n );\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentStatusResponse,\n srcChainId: number,\n txHash?: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash,\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n srcChainId: number,\n protocol: string,\n clientId: BridgeClientId,\n txHash?: string,\n ): Promise<IntentStatuses | undefined> => {\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId,\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash,\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const existingTxMeta = getTransactionMetaById(\n this.#messenger,\n originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash as `0x${string}` | undefined,\n status: isComplete ? '0x1' : '0x0',\n },\n }\n : {};\n\n updateTransaction(\n this.#messenger,\n existingTxMeta,\n {\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n },\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n}\n"]}
1
+ {"version":3,"file":"bridge-status-controller.intent.js","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAO1E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAEL,aAAa,EAEb,kCAAkC,GACnC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,EACtB,i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AmC;wBACpD,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;qBACnC;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;YAEP,iBAAiB,CACf,IAAI,CAAC,UAAU,EACf,cAAc,EACd;gBACE,MAAM,EAAE,YAAY,EAAE,iBAAiB;gBACvC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnC,GAAG,eAAe;aACnB,EACD,yDAAyD,WAAW,EAAE,CACvE,CAAC;YAEF,IAAI,aAAa,EAAE,CAAC;gBAClB,IAAI,CAAC,+BAA+B,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE;gBACpE,YAAY;gBACZ,gBAAgB,EAAE,cAAc;gBAChC,KAAK;aACN,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;CACH","sourcesContent":["import { BridgeClientId, StatusTypes } from '@metamask/bridge-controller';\n\nimport type {\n BridgeStatusControllerMessenger,\n FetchFunction,\n} from './types.js';\nimport type { BridgeHistoryItem } from './types.js';\nimport { getJwt } from './utils/authentication.js';\nimport {\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api.js';\nimport {\n getTransactionMetaById,\n updateTransaction,\n} from './utils/transaction.js';\nimport { IntentStatusResponse, IntentOrderStatus } from './utils/validators.js';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n customBridgeApiBaseUrl,\n fetchFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n }) {\n this.#messenger = messenger;\n this.intentApi = new IntentApiImpl(\n customBridgeApiBaseUrl,\n fetchFn,\n async () => await getJwt(messenger),\n );\n }\n\n /**\n * Set the intent statuses for a given bridge transaction.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID (key for storage).\n * @param order - The intent order.\n * @param srcChainId - The source chain ID.\n * @param txHash - The transaction hash.\n * @returns The intent statuses.\n */\n\n #setIntentStatuses(\n bridgeTxMetaId: string,\n order: IntentStatusResponse,\n srcChainId: number,\n txHash?: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash,\n );\n const intentStatuses: IntentStatuses = {\n orderStatus: order.status,\n bridgeStatus,\n };\n this.#intentStatusesByBridgeTxMetaId.set(bridgeTxMetaId, intentStatuses);\n return intentStatuses;\n }\n\n /**\n * Get the status of an intent order.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param protocol - The protocol of the intent.\n * @param clientId - The client ID.\n * @returns The intent order mapped status.\n */\n\n getIntentTransactionStatus = async (\n bridgeTxMetaId: string,\n srcChainId: number,\n protocol: string,\n clientId: BridgeClientId,\n txHash?: string,\n ): Promise<IntentStatuses | undefined> => {\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId,\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash,\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(\n `[Intent polling] Failed to get intent order status from API: ${error.message}`,\n );\n }\n return undefined;\n }\n };\n\n /**\n * Sync the transaction status from the intent status.\n *\n * @param bridgeTxMetaId - The bridge transaction meta ID.\n * @param historyItem - The history item.\n */\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n const intentStatuses =\n this.#intentStatusesByBridgeTxMetaId.get(bridgeTxMetaId);\n if (!intentStatuses) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const existingTxMeta = getTransactionMetaById(\n this.#messenger,\n originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '[Intent polling] Skipping update, transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n const { bridgeStatus, orderStatus } = intentStatuses;\n const txHash = bridgeStatus?.txHash;\n\n const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const isFinalStatus =\n bridgeStatus?.status.status === StatusTypes.COMPLETE ||\n bridgeStatus?.status.status === StatusTypes.FAILED;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash as `0x${string}` | undefined,\n status: isComplete ? '0x1' : '0x0',\n },\n }\n : {};\n\n updateTransaction(\n this.#messenger,\n existingTxMeta,\n {\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n },\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isFinalStatus) {\n this.#intentStatusesByBridgeTxMetaId.delete(bridgeTxMetaId);\n }\n } catch (error) {\n console.error('[Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n}\n"]}