@metamask-previews/bridge-status-controller 67.0.1-preview-0aca970c8 → 67.0.1-preview-b2b2c8f6a

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/bridge-status-controller.cjs +21 -26
  3. package/dist/bridge-status-controller.cjs.map +1 -1
  4. package/dist/bridge-status-controller.d.cts +6 -4
  5. package/dist/bridge-status-controller.d.cts.map +1 -1
  6. package/dist/bridge-status-controller.d.mts +6 -4
  7. package/dist/bridge-status-controller.d.mts.map +1 -1
  8. package/dist/bridge-status-controller.intent.cjs +18 -78
  9. package/dist/bridge-status-controller.intent.cjs.map +1 -1
  10. package/dist/bridge-status-controller.intent.d.cts +5 -38
  11. package/dist/bridge-status-controller.intent.d.cts.map +1 -1
  12. package/dist/bridge-status-controller.intent.d.mts +5 -38
  13. package/dist/bridge-status-controller.intent.d.mts.map +1 -1
  14. package/dist/bridge-status-controller.intent.mjs +16 -76
  15. package/dist/bridge-status-controller.intent.mjs.map +1 -1
  16. package/dist/bridge-status-controller.mjs +23 -28
  17. package/dist/bridge-status-controller.mjs.map +1 -1
  18. package/dist/types.cjs.map +1 -1
  19. package/dist/types.d.cts +1 -2
  20. package/dist/types.d.cts.map +1 -1
  21. package/dist/types.d.mts +1 -2
  22. package/dist/types.d.mts.map +1 -1
  23. package/dist/types.mjs.map +1 -1
  24. package/dist/utils/intent-api.cjs +6 -10
  25. package/dist/utils/intent-api.cjs.map +1 -1
  26. package/dist/utils/intent-api.d.cts +7 -8
  27. package/dist/utils/intent-api.d.cts.map +1 -1
  28. package/dist/utils/intent-api.d.mts +7 -8
  29. package/dist/utils/intent-api.d.mts.map +1 -1
  30. package/dist/utils/intent-api.mjs +6 -10
  31. package/dist/utils/intent-api.mjs.map +1 -1
  32. package/dist/utils/transaction.d.cts +1 -9
  33. package/dist/utils/transaction.d.cts.map +1 -1
  34. package/dist/utils/transaction.d.mts +1 -9
  35. package/dist/utils/transaction.d.mts.map +1 -1
  36. package/package.json +1 -2
@@ -10,69 +10,31 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
13
+ var _IntentStatusManager_messenger, _IntentStatusManager_updateTransactionFn;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.IntentManager = void 0;
15
+ exports.IntentStatusManager = void 0;
16
16
  const bridge_controller_1 = require("@metamask/bridge-controller");
17
- const intent_api_1 = require("./utils/intent-api.cjs");
18
- const validators_1 = require("./utils/validators.cjs");
19
- class IntentManager {
20
- constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }) {
21
- _IntentManager_instances.add(this);
22
- _IntentManager_messenger.set(this, void 0);
23
- _IntentManager_updateTransactionFn.set(this, void 0);
24
- _IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
25
- /**
26
- * Get the status of an intent order.
27
- *
28
- * @param bridgeTxMetaId - The bridge transaction meta ID.
29
- * @param protocol - The protocol of the intent.
30
- * @param clientId - The client ID.
31
- * @returns The intent order mapped status.
32
- */
33
- this.getIntentTransactionStatus = async (bridgeTxMetaId, historyItem, clientId) => {
34
- const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
35
- const txHash = statusObj?.srcChain?.txHash ?? '';
36
- const protocol = intent?.protocol ?? '';
37
- try {
38
- const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId.toString(), clientId);
39
- return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
40
- }
41
- catch (error) {
42
- if (error instanceof Error) {
43
- throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
44
- }
45
- return undefined;
46
- }
47
- };
48
- /**
49
- * Sync the transaction status from the intent status.
50
- *
51
- * @param bridgeTxMetaId - The bridge transaction meta ID.
52
- * @param historyItem - The history item.
53
- */
54
- this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
17
+ class IntentStatusManager {
18
+ constructor({ messenger, updateTransactionFn, }) {
19
+ _IntentStatusManager_messenger.set(this, void 0);
20
+ _IntentStatusManager_updateTransactionFn.set(this, void 0);
21
+ this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus) => {
55
22
  // Update the actual transaction in TransactionController to sync with intent status
56
23
  // Use the original transaction ID (not the bridge history key)
57
24
  const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
58
25
  if (!originalTxId) {
59
26
  return;
60
27
  }
61
- const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
62
- if (!intentStatuses) {
63
- return;
64
- }
65
28
  try {
66
29
  // Merge with existing TransactionMeta to avoid wiping required fields
67
- const { transactions } = __classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:getState');
30
+ const { transactions } = __classPrivateFieldGet(this, _IntentStatusManager_messenger, "f").call('TransactionController:getState');
68
31
  const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
69
32
  if (!existingTxMeta) {
70
- console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
33
+ console.warn('📝 [Intent polling] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
71
34
  return;
72
35
  }
73
- const { bridgeStatus, orderStatus } = intentStatuses;
74
- const txHash = bridgeStatus?.txHash;
75
- const isComplete = bridgeStatus?.status.status === bridge_controller_1.StatusTypes.COMPLETE;
36
+ const { txHash } = intentTranslation;
37
+ const isComplete = intentTranslation.status.status === bridge_controller_1.StatusTypes.COMPLETE;
76
38
  const existingTxReceipt = existingTxMeta.txReceipt;
77
39
  const txReceiptUpdate = txHash
78
40
  ? {
@@ -85,46 +47,24 @@ class IntentManager {
85
47
  : {};
86
48
  const updatedTxMeta = {
87
49
  ...existingTxMeta,
88
- status: bridgeStatus?.transactionStatus,
50
+ status: intentTranslation.transactionStatus,
89
51
  ...(txHash ? { hash: txHash } : {}),
90
52
  ...txReceiptUpdate,
91
53
  };
92
- __classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
93
- if (isComplete) {
94
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
95
- }
54
+ __classPrivateFieldGet(this, _IntentStatusManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`);
96
55
  }
97
56
  catch (error) {
98
- console.error('[Intent polling] Failed to update transaction status', {
57
+ console.error('📝 [Intent polling] Failed to update transaction status', {
99
58
  originalTxId,
100
59
  bridgeHistoryKey: bridgeTxMetaId,
101
60
  error,
102
61
  });
103
62
  }
104
63
  };
105
- /**
106
- * Submit an intent order.
107
- *
108
- * @param submissionParams - The submission parameters.
109
- * @param clientId - The client ID.
110
- * @returns The intent order.
111
- */
112
- this.submitIntent = async (submissionParams, clientId) => {
113
- return this.intentApi.submitIntent(submissionParams, clientId);
114
- };
115
- __classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
116
- __classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
117
- this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
64
+ __classPrivateFieldSet(this, _IntentStatusManager_messenger, messenger, "f");
65
+ __classPrivateFieldSet(this, _IntentStatusManager_updateTransactionFn, updateTransactionFn, "f");
118
66
  }
119
67
  }
120
- exports.IntentManager = IntentManager;
121
- _IntentManager_messenger = new WeakMap(), _IntentManager_updateTransactionFn = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
122
- const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash.toString());
123
- const intentStatuses = {
124
- orderStatus: order.status,
125
- bridgeStatus,
126
- };
127
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
128
- return intentStatuses;
129
- };
68
+ exports.IntentStatusManager = IntentStatusManager;
69
+ _IntentStatusManager_messenger = new WeakMap(), _IntentStatusManager_updateTransactionFn = new WeakMap();
130
70
  //# sourceMappingURL=bridge-status-controller.intent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0D;AAM1D,uDAO4B;AAC5B,uDAAoE;AAOpE,MAAa,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,WAA8B,EAC9B,QAAgB,EACqB,EAAE;YACvC,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAC9B,GAAG,WAAW,CAAC;YAChB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;YACjD,MAAM,QAAQ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QACH,iBAAY,GAAG,KAAK,EAClB,gBAAwC,EACxC,QAAgB,EACM,EAAE;YACxB,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QA3KA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CAyKF;AAnMD,sCAmMC;oRA5JG,cAAsB,EACtB,KAAkB,EAClB,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,IAAA,+CAAkC,EACrD,KAAK,EACL,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,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 { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentOrder, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\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: IntentOrder,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash.toString(),\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 historyItem: BridgeHistoryItem,\n clientId: string,\n ): Promise<IntentStatuses | undefined> => {\n const {\n status: statusObj,\n quote: { srcChainId, intent },\n } = historyItem;\n const txHash = statusObj?.srcChain?.txHash ?? '';\n const protocol = intent?.protocol ?? '';\n\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId.toString(),\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\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 { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === 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 const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isComplete) {\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 /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: string,\n ): Promise<IntentOrder> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
1
+ {"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0D;AAQ1D,MAAa,mBAAmB;IAK9B,YAAY,EACV,SAAS,EACT,mBAAmB,GAIpB;QAVQ,iDAA4C;QAE5C,2DAA+E;QAaxF,oCAA+B,GAAG,CAChC,cAAsB,EACtB,WAA8B,EAC9B,iBAA0C,EAC1C,iBAAyB,EACnB,EAAE;YACR,oFAAoF;YACpF,+DAA+D;YAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,qBAAqB,IAAI,WAAW,CAAC,QAAQ,CAAC;YAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sEAAsE;gBACtE,MAAM,EAAE,YAAY,EAAE,GAAG,uBAAA,IAAI,sCAAW,CAAC,IAAI,CAC3C,gCAAgC,CACjC,CAAC;gBACF,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CACtC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAChD,CAAC;gBACF,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CACV,4DAA4D,EAC5D,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,CACnD,CAAC;oBACF,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;gBACrC,MAAM,UAAU,GACd,iBAAiB,CAAC,MAAM,CAAC,MAAM,KAAK,+BAAW,CAAC,QAAQ,CAAC;gBAC3D,MAAM,iBAAiB,GACrB,cACD,CAAC,SAAS,CAAC;gBACZ,MAAM,eAAe,GAAG,MAAM;oBAC5B,CAAC,CAAC;wBACE,SAAS,EAAE;4BACT,GAAG,iBAAiB;4BACpB,eAAe,EAAE,MAAM;4BACvB,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAsB;yBAC1D;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;gBAEP,MAAM,aAAa,GAAoB;oBACrC,GAAG,cAAc;oBACjB,MAAM,EAAE,iBAAiB,CAAC,iBAAiB;oBAC3C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,GAAG,eAAe;iBACA,CAAC;gBAErB,uBAAA,IAAI,gDAAqB,MAAzB,IAAI,EACF,aAAa,EACb,yDAAyD,iBAAiB,EAAE,CAC7E,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE;oBACvE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QApEA,uBAAA,IAAI,kCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,4CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;CAmEF;AAjFD,kDAiFC","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { IntentStatusTranslation } from './utils/intent-api';\n\nexport class IntentStatusManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n constructor({\n messenger,\n updateTransactionFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n }\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n intentTranslation: IntentStatusTranslation,\n intentOrderStatus: string,\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 try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === 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\n const { txHash } = intentTranslation;\n const isComplete =\n intentTranslation.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: intentTranslation.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`,\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,46 +1,13 @@
1
1
  import type { TransactionController } from "@metamask/transaction-controller";
2
- import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
2
+ import type { BridgeStatusControllerMessenger } from "./types.cjs";
3
3
  import type { BridgeHistoryItem } from "./types.cjs";
4
- import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.cjs";
5
- import { IntentOrder, IntentOrderStatus } from "./utils/validators.cjs";
6
- type IntentStatuses = {
7
- orderStatus: IntentOrderStatus;
8
- bridgeStatus: IntentBridgeStatus | null;
9
- };
10
- export declare class IntentManager {
4
+ import { IntentStatusTranslation } from "./utils/intent-api.cjs";
5
+ export declare class IntentStatusManager {
11
6
  #private;
12
- readonly intentApi: IntentApi;
13
- constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
7
+ constructor({ messenger, updateTransactionFn, }: {
14
8
  messenger: BridgeStatusControllerMessenger;
15
9
  updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
16
- customBridgeApiBaseUrl: string;
17
- fetchFn: FetchFunction;
18
- getJwt: GetJwtFn;
19
10
  });
20
- /**
21
- * Get the status of an intent order.
22
- *
23
- * @param bridgeTxMetaId - The bridge transaction meta ID.
24
- * @param protocol - The protocol of the intent.
25
- * @param clientId - The client ID.
26
- * @returns The intent order mapped status.
27
- */
28
- getIntentTransactionStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, clientId: string) => Promise<IntentStatuses | undefined>;
29
- /**
30
- * Sync the transaction status from the intent status.
31
- *
32
- * @param bridgeTxMetaId - The bridge transaction meta ID.
33
- * @param historyItem - The history item.
34
- */
35
- syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
36
- /**
37
- * Submit an intent order.
38
- *
39
- * @param submissionParams - The submission parameters.
40
- * @param clientId - The client ID.
41
- * @returns The intent order.
42
- */
43
- submitIntent: (submissionParams: IntentSubmissionParams, clientId: string) => Promise<IntentOrder>;
11
+ syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, intentTranslation: IntentStatusTranslation, intentOrderStatus: string) => void;
44
12
  }
45
- export {};
46
13
  //# sourceMappingURL=bridge-status-controller.intent.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EACL,QAAQ,EACR,SAAS,EAET,kBAAkB,EAClB,sBAAsB,EAEvB,+BAA2B;AAC5B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,+BAA2B;AAEpE,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,iBAAiB,CAAC;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,qBAAa,aAAa;;IAKxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GACP,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAC9E,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,EAAE,QAAQ,CAAC;KAClB;IAmCD;;;;;;;OAOG;IAEH,0BAA0B,mBACR,MAAM,eACT,iBAAiB,YACpB,MAAM,KACf,QAAQ,cAAc,GAAG,SAAS,CAAC,CA8BpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAoEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,MAAM,KACf,QAAQ,WAAW,CAAC,CAErB;CACH"}
1
+ {"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,oBAAgB;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D,qBAAa,mBAAmB;;gBAKlB,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;KAC/E;IAKD,+BAA+B,mBACb,MAAM,eACT,iBAAiB,qBACX,uBAAuB,qBACvB,MAAM,KACxB,IAAI,CA2DL;CACH"}
@@ -1,46 +1,13 @@
1
1
  import type { TransactionController } from "@metamask/transaction-controller";
2
- import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
2
+ import type { BridgeStatusControllerMessenger } from "./types.mjs";
3
3
  import type { BridgeHistoryItem } from "./types.mjs";
4
- import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.mjs";
5
- import { IntentOrder, IntentOrderStatus } from "./utils/validators.mjs";
6
- type IntentStatuses = {
7
- orderStatus: IntentOrderStatus;
8
- bridgeStatus: IntentBridgeStatus | null;
9
- };
10
- export declare class IntentManager {
4
+ import { IntentStatusTranslation } from "./utils/intent-api.mjs";
5
+ export declare class IntentStatusManager {
11
6
  #private;
12
- readonly intentApi: IntentApi;
13
- constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
7
+ constructor({ messenger, updateTransactionFn, }: {
14
8
  messenger: BridgeStatusControllerMessenger;
15
9
  updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
16
- customBridgeApiBaseUrl: string;
17
- fetchFn: FetchFunction;
18
- getJwt: GetJwtFn;
19
10
  });
20
- /**
21
- * Get the status of an intent order.
22
- *
23
- * @param bridgeTxMetaId - The bridge transaction meta ID.
24
- * @param protocol - The protocol of the intent.
25
- * @param clientId - The client ID.
26
- * @returns The intent order mapped status.
27
- */
28
- getIntentTransactionStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, clientId: string) => Promise<IntentStatuses | undefined>;
29
- /**
30
- * Sync the transaction status from the intent status.
31
- *
32
- * @param bridgeTxMetaId - The bridge transaction meta ID.
33
- * @param historyItem - The history item.
34
- */
35
- syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
36
- /**
37
- * Submit an intent order.
38
- *
39
- * @param submissionParams - The submission parameters.
40
- * @param clientId - The client ID.
41
- * @returns The intent order.
42
- */
43
- submitIntent: (submissionParams: IntentSubmissionParams, clientId: string) => Promise<IntentOrder>;
11
+ syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, intentTranslation: IntentStatusTranslation, intentOrderStatus: string) => void;
44
12
  }
45
- export {};
46
13
  //# sourceMappingURL=bridge-status-controller.intent.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,aAAa,EAAE,oBAAgB;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EACL,QAAQ,EACR,SAAS,EAET,kBAAkB,EAClB,sBAAsB,EAEvB,+BAA2B;AAC5B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,+BAA2B;AAEpE,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,iBAAiB,CAAC;IAC/B,YAAY,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACzC,CAAC;AAEF,qBAAa,aAAa;;IAKxB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAKlB,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GACP,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAC9E,sBAAsB,EAAE,MAAM,CAAC;QAC/B,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,EAAE,QAAQ,CAAC;KAClB;IAmCD;;;;;;;OAOG;IAEH,0BAA0B,mBACR,MAAM,eACT,iBAAiB,YACpB,MAAM,KACf,QAAQ,cAAc,GAAG,SAAS,CAAC,CA8BpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAoEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,MAAM,KACf,QAAQ,WAAW,CAAC,CAErB;CACH"}
1
+ {"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,oBAAgB;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D,qBAAa,mBAAmB;;gBAKlB,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;KAC/E;IAKD,+BAA+B,mBACb,MAAM,eACT,iBAAiB,qBACX,uBAAuB,qBACvB,MAAM,KACxB,IAAI,CA2DL;CACH"}
@@ -9,67 +9,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
12
+ var _IntentStatusManager_messenger, _IntentStatusManager_updateTransactionFn;
13
13
  import { StatusTypes } from "@metamask/bridge-controller";
14
- import { IntentApiImpl, translateIntentOrderToBridgeStatus } from "./utils/intent-api.mjs";
15
- import { IntentOrderStatus } from "./utils/validators.mjs";
16
- export class IntentManager {
17
- constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }) {
18
- _IntentManager_instances.add(this);
19
- _IntentManager_messenger.set(this, void 0);
20
- _IntentManager_updateTransactionFn.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, historyItem, clientId) => {
31
- const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
32
- const txHash = statusObj?.srcChain?.txHash ?? '';
33
- const protocol = intent?.protocol ?? '';
34
- try {
35
- const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId.toString(), clientId);
36
- return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
37
- }
38
- catch (error) {
39
- if (error instanceof Error) {
40
- throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
41
- }
42
- return undefined;
43
- }
44
- };
45
- /**
46
- * Sync the transaction status from the intent status.
47
- *
48
- * @param bridgeTxMetaId - The bridge transaction meta ID.
49
- * @param historyItem - The history item.
50
- */
51
- this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
14
+ export class IntentStatusManager {
15
+ constructor({ messenger, updateTransactionFn, }) {
16
+ _IntentStatusManager_messenger.set(this, void 0);
17
+ _IntentStatusManager_updateTransactionFn.set(this, void 0);
18
+ this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus) => {
52
19
  // Update the actual transaction in TransactionController to sync with intent status
53
20
  // Use the original transaction ID (not the bridge history key)
54
21
  const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
55
22
  if (!originalTxId) {
56
23
  return;
57
24
  }
58
- const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
59
- if (!intentStatuses) {
60
- return;
61
- }
62
25
  try {
63
26
  // Merge with existing TransactionMeta to avoid wiping required fields
64
- const { transactions } = __classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:getState');
27
+ const { transactions } = __classPrivateFieldGet(this, _IntentStatusManager_messenger, "f").call('TransactionController:getState');
65
28
  const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
66
29
  if (!existingTxMeta) {
67
- console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
30
+ console.warn('📝 [Intent polling] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
68
31
  return;
69
32
  }
70
- const { bridgeStatus, orderStatus } = intentStatuses;
71
- const txHash = bridgeStatus?.txHash;
72
- const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;
33
+ const { txHash } = intentTranslation;
34
+ const isComplete = intentTranslation.status.status === StatusTypes.COMPLETE;
73
35
  const existingTxReceipt = existingTxMeta.txReceipt;
74
36
  const txReceiptUpdate = txHash
75
37
  ? {
@@ -82,45 +44,23 @@ export class IntentManager {
82
44
  : {};
83
45
  const updatedTxMeta = {
84
46
  ...existingTxMeta,
85
- status: bridgeStatus?.transactionStatus,
47
+ status: intentTranslation.transactionStatus,
86
48
  ...(txHash ? { hash: txHash } : {}),
87
49
  ...txReceiptUpdate,
88
50
  };
89
- __classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
90
- if (isComplete) {
91
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
92
- }
51
+ __classPrivateFieldGet(this, _IntentStatusManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`);
93
52
  }
94
53
  catch (error) {
95
- console.error('[Intent polling] Failed to update transaction status', {
54
+ console.error('📝 [Intent polling] Failed to update transaction status', {
96
55
  originalTxId,
97
56
  bridgeHistoryKey: bridgeTxMetaId,
98
57
  error,
99
58
  });
100
59
  }
101
60
  };
102
- /**
103
- * Submit an intent order.
104
- *
105
- * @param submissionParams - The submission parameters.
106
- * @param clientId - The client ID.
107
- * @returns The intent order.
108
- */
109
- this.submitIntent = async (submissionParams, clientId) => {
110
- return this.intentApi.submitIntent(submissionParams, clientId);
111
- };
112
- __classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
113
- __classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
114
- this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
61
+ __classPrivateFieldSet(this, _IntentStatusManager_messenger, messenger, "f");
62
+ __classPrivateFieldSet(this, _IntentStatusManager_updateTransactionFn, updateTransactionFn, "f");
115
63
  }
116
64
  }
117
- _IntentManager_messenger = new WeakMap(), _IntentManager_updateTransactionFn = new WeakMap(), _IntentManager_intentStatusesByBridgeTxMetaId = new WeakMap(), _IntentManager_instances = new WeakSet(), _IntentManager_setIntentStatuses = function _IntentManager_setIntentStatuses(bridgeTxMetaId, order, srcChainId, txHash) {
118
- const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash.toString());
119
- const intentStatuses = {
120
- orderStatus: order.status,
121
- bridgeStatus,
122
- };
123
- __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
124
- return intentStatuses;
125
- };
65
+ _IntentStatusManager_messenger = new WeakMap(), _IntentStatusManager_updateTransactionFn = new WeakMap();
126
66
  //# sourceMappingURL=bridge-status-controller.intent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oCAAoC;AAM1D,OAAO,EAGL,aAAa,EAGb,kCAAkC,EACnC,+BAA2B;AAC5B,OAAO,EAAe,iBAAiB,EAAE,+BAA2B;AAOpE,MAAM,OAAO,aAAa;IAUxB,YAAY,EACV,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,OAAO,EACP,MAAM,GAOP;;QArBQ,2CAA4C;QAE5C,qDAA+E;QAI/E,wDACP,IAAI,GAAG,EAAE,EAAC;QAiDZ;;;;;;;WAOG;QAEH,+BAA0B,GAAG,KAAK,EAChC,cAAsB,EACtB,WAA8B,EAC9B,QAAgB,EACqB,EAAE;YACvC,MAAM,EACJ,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,GAC9B,GAAG,WAAW,CAAC;YAChB,MAAM,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;YAExC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,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AAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QA3KA,uBAAA,IAAI,4BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,sCAAwB,mBAAmB,MAAA,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,sBAAsB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;CAyKF;oRA5JG,cAAsB,EACtB,KAAkB,EAClB,UAAkB,EAClB,MAAc;IAEd,MAAM,YAAY,GAAG,kCAAkC,CACrD,KAAK,EACL,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,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 { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger, FetchFunction } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport {\n GetJwtFn,\n IntentApi,\n IntentApiImpl,\n IntentBridgeStatus,\n IntentSubmissionParams,\n translateIntentOrderToBridgeStatus,\n} from './utils/intent-api';\nimport { IntentOrder, IntentOrderStatus } from './utils/validators';\n\ntype IntentStatuses = {\n orderStatus: IntentOrderStatus;\n bridgeStatus: IntentBridgeStatus | null;\n};\n\nexport class IntentManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n readonly intentApi: IntentApi;\n\n readonly #intentStatusesByBridgeTxMetaId: Map<string, IntentStatuses> =\n new Map();\n\n constructor({\n messenger,\n updateTransactionFn,\n customBridgeApiBaseUrl,\n fetchFn,\n getJwt,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n customBridgeApiBaseUrl: string;\n fetchFn: FetchFunction;\n getJwt: GetJwtFn;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);\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: IntentOrder,\n srcChainId: number,\n txHash: string,\n ): IntentStatuses {\n const bridgeStatus = translateIntentOrderToBridgeStatus(\n order,\n srcChainId,\n txHash.toString(),\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 historyItem: BridgeHistoryItem,\n clientId: string,\n ): Promise<IntentStatuses | undefined> => {\n const {\n status: statusObj,\n quote: { srcChainId, intent },\n } = historyItem;\n const txHash = statusObj?.srcChain?.txHash ?? '';\n const protocol = intent?.protocol ?? '';\n\n try {\n const orderStatus = await this.intentApi.getOrderStatus(\n bridgeTxMetaId,\n protocol,\n srcChainId.toString(),\n clientId,\n );\n\n return this.#setIntentStatuses(\n bridgeTxMetaId,\n orderStatus,\n srcChainId,\n txHash.toString(),\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 { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === 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 const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: bridgeStatus?.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${orderStatus}`,\n );\n\n if (isComplete) {\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 /**\n * Submit an intent order.\n *\n * @param submissionParams - The submission parameters.\n * @param clientId - The client ID.\n * @returns The intent order.\n */\n submitIntent = async (\n submissionParams: IntentSubmissionParams,\n clientId: string,\n ): Promise<IntentOrder> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
1
+ {"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oCAAoC;AAQ1D,MAAM,OAAO,mBAAmB;IAK9B,YAAY,EACV,SAAS,EACT,mBAAmB,GAIpB;QAVQ,iDAA4C;QAE5C,2DAA+E;QAaxF,oCAA+B,GAAG,CAChC,cAAsB,EACtB,WAA8B,EAC9B,iBAA0C,EAC1C,iBAAyB,EACnB,EAAE;YACR,oFAAoF;YACpF,+DAA+D;YAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,qBAAqB,IAAI,WAAW,CAAC,QAAQ,CAAC;YAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sEAAsE;gBACtE,MAAM,EAAE,YAAY,EAAE,GAAG,uBAAA,IAAI,sCAAW,CAAC,IAAI,CAC3C,gCAAgC,CACjC,CAAC;gBACF,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CACtC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAChD,CAAC;gBACF,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CACV,4DAA4D,EAC5D,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,CACnD,CAAC;oBACF,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;gBACrC,MAAM,UAAU,GACd,iBAAiB,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,QAAQ,CAAC;gBAC3D,MAAM,iBAAiB,GACrB,cACD,CAAC,SAAS,CAAC;gBACZ,MAAM,eAAe,GAAG,MAAM;oBAC5B,CAAC,CAAC;wBACE,SAAS,EAAE;4BACT,GAAG,iBAAiB;4BACpB,eAAe,EAAE,MAAM;4BACvB,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAsB;yBAC1D;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;gBAEP,MAAM,aAAa,GAAoB;oBACrC,GAAG,cAAc;oBACjB,MAAM,EAAE,iBAAiB,CAAC,iBAAiB;oBAC3C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,GAAG,eAAe;iBACA,CAAC;gBAErB,uBAAA,IAAI,gDAAqB,MAAzB,IAAI,EACF,aAAa,EACb,yDAAyD,iBAAiB,EAAE,CAC7E,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE;oBACvE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QApEA,uBAAA,IAAI,kCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,4CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;CAmEF","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { IntentStatusTranslation } from './utils/intent-api';\n\nexport class IntentStatusManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n constructor({\n messenger,\n updateTransactionFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n }\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n intentTranslation: IntentStatusTranslation,\n intentOrderStatus: string,\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 try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === 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\n const { txHash } = intentTranslation;\n const isComplete =\n intentTranslation.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: intentTranslation.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`,\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"]}