@metamask/bridge-status-controller 68.0.2 → 69.0.0
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.
- package/CHANGELOG.md +33 -1
- package/dist/bridge-status-controller.cjs +73 -42
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +12 -3
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +12 -3
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +3 -6
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +4 -3
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +4 -3
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +4 -7
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +73 -42
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +13 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +13 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/bridge-status.cjs +2 -4
- package/dist/utils/bridge-status.cjs.map +1 -1
- package/dist/utils/bridge-status.d.cts.map +1 -1
- package/dist/utils/bridge-status.d.mts.map +1 -1
- package/dist/utils/bridge-status.mjs +2 -4
- package/dist/utils/bridge-status.mjs.map +1 -1
- package/dist/utils/gas.cjs +2 -2
- package/dist/utils/gas.cjs.map +1 -1
- package/dist/utils/gas.d.cts +1 -1
- package/dist/utils/gas.d.cts.map +1 -1
- package/dist/utils/gas.d.mts +1 -1
- package/dist/utils/gas.d.mts.map +1 -1
- package/dist/utils/gas.mjs +2 -2
- package/dist/utils/gas.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +2 -2
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +8 -7
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +8 -7
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +4 -4
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/metrics.cjs +11 -3
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +10 -2
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +10 -2
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +11 -3
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/transaction.cjs +23 -14
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +4 -2
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +4 -2
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +23 -14
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.cjs +5 -5
- package/dist/utils/validators.cjs.map +1 -1
- package/dist/utils/validators.d.cts +5 -10
- package/dist/utils/validators.d.cts.map +1 -1
- package/dist/utils/validators.d.mts +5 -10
- package/dist/utils/validators.d.mts.map +1 -1
- package/dist/utils/validators.mjs +3 -3
- package/dist/utils/validators.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,8BAA8B,EAE9B,aAAa,EACb,KAAK,
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,8BAA8B,EAE9B,aAAa,EACb,KAAK,EAEN,oCAAoC;AAC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,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CA2LtE;CAiIH"}
|
|
@@ -30,12 +30,9 @@ class IntentManager {
|
|
|
30
30
|
* @param clientId - The client ID.
|
|
31
31
|
* @returns The intent order mapped status.
|
|
32
32
|
*/
|
|
33
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId,
|
|
34
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
35
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
36
|
-
const protocol = intent?.protocol ?? '';
|
|
33
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash = '') => {
|
|
37
34
|
try {
|
|
38
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId
|
|
35
|
+
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
39
36
|
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
40
37
|
}
|
|
41
38
|
catch (error) {
|
|
@@ -121,7 +118,7 @@ class IntentManager {
|
|
|
121
118
|
}
|
|
122
119
|
exports.IntentManager = IntentManager;
|
|
123
120
|
_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) {
|
|
124
|
-
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash
|
|
121
|
+
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash);
|
|
125
122
|
const intentStatuses = {
|
|
126
123
|
orderStatus: order.status,
|
|
127
124
|
bridgeStatus,
|
|
@@ -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,GAAG,MAAM,EAAE,QAAQ,IAAI,EAAE,CAAC;YAExC,IAAI,CAAC;gBACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CACrD,cAAc,EACd,QAAQ,EACR,UAAU,CAAC,QAAQ,EAAE,EACrB,QAAQ,CACT,CAAC;gBAEF,OAAO,uBAAA,IAAI,kEAAmB,MAAvB,IAAI,EACT,cAAc,EACd,WAAW,EACX,UAAU,EACV,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC;YACJ,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,MAAM,IAAI,KAAK,CACb,gEAAgE,KAAK,CAAC,OAAO,EAAE,CAChF,CAAC;gBACJ,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC,CAAC;QAEF;;;;;WAKG;QAEH,oCAA+B,GAAG,CAChC,cAAsB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AAM,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 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,\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 (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 /**\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/b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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 { IntentStatusResponse, 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: 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.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 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,\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 (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 /**\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: BridgeClientId,\n ): Promise<IntentStatusResponse> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
1
2
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
3
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
|
|
3
4
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
4
5
|
import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.cjs";
|
|
5
|
-
import {
|
|
6
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.cjs";
|
|
6
7
|
type IntentStatuses = {
|
|
7
8
|
orderStatus: IntentOrderStatus;
|
|
8
9
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -25,7 +26,7 @@ export declare class IntentManager {
|
|
|
25
26
|
* @param clientId - The client ID.
|
|
26
27
|
* @returns The intent order mapped status.
|
|
27
28
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
29
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
30
|
/**
|
|
30
31
|
* Sync the transaction status from the intent status.
|
|
31
32
|
*
|
|
@@ -40,7 +41,7 @@ export declare class IntentManager {
|
|
|
40
41
|
* @param clientId - The client ID.
|
|
41
42
|
* @returns The intent order.
|
|
42
43
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
44
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
45
|
}
|
|
45
46
|
export {};
|
|
46
47
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;AAC1E,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,oBAAoB,EAAE,iBAAiB,EAAE,+BAA2B;AAE7E,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,cACV,MAAM,YACR,MAAM,YACN,cAAc,WAChB,MAAM,KACb,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { BridgeClientId } from "@metamask/bridge-controller";
|
|
1
2
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
3
|
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
|
|
3
4
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
4
5
|
import { GetJwtFn, IntentApi, IntentBridgeStatus, IntentSubmissionParams } from "./utils/intent-api.mjs";
|
|
5
|
-
import {
|
|
6
|
+
import { IntentStatusResponse, IntentOrderStatus } from "./utils/validators.mjs";
|
|
6
7
|
type IntentStatuses = {
|
|
7
8
|
orderStatus: IntentOrderStatus;
|
|
8
9
|
bridgeStatus: IntentBridgeStatus | null;
|
|
@@ -25,7 +26,7 @@ export declare class IntentManager {
|
|
|
25
26
|
* @param clientId - The client ID.
|
|
26
27
|
* @returns The intent order mapped status.
|
|
27
28
|
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string,
|
|
29
|
+
getIntentTransactionStatus: (bridgeTxMetaId: string, srcChainId: number, protocol: string, clientId: BridgeClientId, txHash?: string) => Promise<IntentStatuses | undefined>;
|
|
29
30
|
/**
|
|
30
31
|
* Sync the transaction status from the intent status.
|
|
31
32
|
*
|
|
@@ -40,7 +41,7 @@ export declare class IntentManager {
|
|
|
40
41
|
* @param clientId - The client ID.
|
|
41
42
|
* @returns The intent order.
|
|
42
43
|
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId:
|
|
44
|
+
submitIntent: (submissionParams: IntentSubmissionParams, clientId: BridgeClientId) => Promise<IntentStatusResponse>;
|
|
44
45
|
}
|
|
45
46
|
export {};
|
|
46
47
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,oCAAoC;AAC1E,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,oBAAoB,EAAE,iBAAiB,EAAE,+BAA2B;AAE7E,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,cACV,MAAM,YACR,MAAM,YACN,cAAc,WAChB,MAAM,KACb,QAAQ,cAAc,GAAG,SAAS,CAAC,CAuBpC;IAEF;;;;;OAKG;IAEH,+BAA+B,mBACb,MAAM,eACT,iBAAiB,KAC7B,IAAI,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,cAAc,KACvB,QAAQ,oBAAoB,CAAC,CAE9B;CACH"}
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
13
|
-
import { StatusTypes } from "@metamask/bridge-controller";
|
|
13
|
+
import { BridgeClientId, StatusTypes } from "@metamask/bridge-controller";
|
|
14
14
|
import { IntentApiImpl, translateIntentOrderToBridgeStatus } from "./utils/intent-api.mjs";
|
|
15
15
|
import { IntentOrderStatus } from "./utils/validators.mjs";
|
|
16
16
|
export class IntentManager {
|
|
@@ -27,12 +27,9 @@ export class IntentManager {
|
|
|
27
27
|
* @param clientId - The client ID.
|
|
28
28
|
* @returns The intent order mapped status.
|
|
29
29
|
*/
|
|
30
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId,
|
|
31
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
32
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
33
|
-
const protocol = intent?.protocol ?? '';
|
|
30
|
+
this.getIntentTransactionStatus = async (bridgeTxMetaId, srcChainId, protocol, clientId, txHash = '') => {
|
|
34
31
|
try {
|
|
35
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId
|
|
32
|
+
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId, clientId);
|
|
36
33
|
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
37
34
|
}
|
|
38
35
|
catch (error) {
|
|
@@ -117,7 +114,7 @@ export class IntentManager {
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
_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) {
|
|
120
|
-
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash
|
|
117
|
+
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash);
|
|
121
118
|
const intentStatuses = {
|
|
122
119
|
orderStatus: order.status,
|
|
123
120
|
bridgeStatus,
|
|
@@ -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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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 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,\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 (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 /**\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,cAAc,EAAE,WAAW,EAAE,oCAAoC;AAM1E,OAAO,EAGL,aAAa,EAGb,kCAAkC,EACnC,+BA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AC;oBACnC,GAAG,eAAe;iBACA,CAAC;gBAErB,uBAAA,IAAI,0CAAqB,MAAzB,IAAI,EACF,aAAa,EACb,yDAAyD,WAAW,EAAE,CACvE,CAAC;gBAEF,IAAI,aAAa,EAAE,CAAC;oBAClB,uBAAA,IAAI,qDAAgC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;gBAC9D,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE;oBACpE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QAEF;;;;;;WAMG;QACH,iBAAY,GAAG,KAAK,EAClB,gBAAwC,EACxC,QAAwB,EACO,EAAE;YACjC,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QAzKA,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;CAuKF;oRA1JG,cAAsB,EACtB,KAA2B,EAC3B,UAAkB,EAClB,MAAc;IAEd,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';\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 { IntentStatusResponse, 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: 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.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 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,\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 (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 /**\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: BridgeClientId,\n ): Promise<IntentStatusResponse> => {\n return this.intentApi.submitIntent(submissionParams, clientId);\n };\n}\n"]}
|
|
@@ -205,7 +205,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
205
205
|
});
|
|
206
206
|
});
|
|
207
207
|
_BridgeStatusController_addTxToHistory.set(this, (startPollingForBridgeTxStatusArgs, actionId) => {
|
|
208
|
-
const { bridgeTxMeta, statusRequest, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, accountAddress: selectedAddress, } = startPollingForBridgeTxStatusArgs;
|
|
208
|
+
const { bridgeTxMeta, statusRequest, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, activeAbTests, accountAddress: selectedAddress, } = startPollingForBridgeTxStatusArgs;
|
|
209
209
|
// Determine the key for this history item:
|
|
210
210
|
// - For pre-submission (non-batch EVM): use actionId
|
|
211
211
|
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
@@ -243,10 +243,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
243
243
|
},
|
|
244
244
|
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
245
245
|
approvalTxId,
|
|
246
|
-
isStxEnabled: isStxEnabled
|
|
246
|
+
isStxEnabled: Boolean(isStxEnabled),
|
|
247
247
|
featureId: quoteResponse.featureId,
|
|
248
248
|
location,
|
|
249
249
|
...(abTests && { abTests }),
|
|
250
|
+
...(activeAbTests && { activeAbTests }),
|
|
250
251
|
};
|
|
251
252
|
this.update((state) => {
|
|
252
253
|
// Use actionId as key for pre-submission, or txMeta.id for post-submission
|
|
@@ -378,9 +379,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
378
379
|
try {
|
|
379
380
|
let status;
|
|
380
381
|
let validationFailures = [];
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
382
|
+
if (historyItem.quote.intent) {
|
|
383
|
+
const intentTxStatus = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").getIntentTransactionStatus(bridgeTxMetaId, historyItem.quote.srcChainId, historyItem.quote.intent.protocol, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"), historyItem.status.srcChain.txHash);
|
|
384
384
|
if (intentTxStatus?.bridgeStatus === null ||
|
|
385
385
|
intentTxStatus?.bridgeStatus === undefined) {
|
|
386
386
|
return;
|
|
@@ -425,7 +425,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
425
425
|
this.update((state) => {
|
|
426
426
|
state.txHistory[bridgeTxMetaId] = newBridgeHistoryItem;
|
|
427
427
|
});
|
|
428
|
-
if (
|
|
428
|
+
if (historyItem.quote.intent) {
|
|
429
429
|
__classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").syncTransactionFromIntentStatus(bridgeTxMetaId, historyItem);
|
|
430
430
|
}
|
|
431
431
|
// 5. After effects
|
|
@@ -559,7 +559,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
559
559
|
});
|
|
560
560
|
});
|
|
561
561
|
_BridgeStatusController_handleApprovalTx.set(this, async (isBridgeTx, srcChainId, approval, resetApproval, requireApproval) => {
|
|
562
|
-
if (approval) {
|
|
562
|
+
if (approval && isEvmTxData(approval)) {
|
|
563
563
|
const approveTx = async () => {
|
|
564
564
|
await __classPrivateFieldGet(this, _BridgeStatusController_handleUSDTAllowanceReset, "f").call(this, resetApproval);
|
|
565
565
|
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransaction, "f").call(this, {
|
|
@@ -646,8 +646,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
646
646
|
// Convert to hex since txFee values from the quote are decimal strings
|
|
647
647
|
if (txFee) {
|
|
648
648
|
return {
|
|
649
|
-
maxFeePerGas: toHex(txFee.maxFeePerGas
|
|
650
|
-
maxPriorityFeePerGas: toHex(txFee.maxPriorityFeePerGas
|
|
649
|
+
maxFeePerGas: toHex(txFee.maxFeePerGas),
|
|
650
|
+
maxPriorityFeePerGas: toHex(txFee.maxPriorityFeePerGas),
|
|
651
651
|
gas: gas ? toHex(gas) : undefined,
|
|
652
652
|
};
|
|
653
653
|
}
|
|
@@ -711,10 +711,11 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
711
711
|
* @param isStxEnabledOnClient - Whether smart transactions are enabled on the client, for example the getSmartTransactionsEnabled selector value from the extension
|
|
712
712
|
* @param quotesReceivedContext - The context for the QuotesReceived event
|
|
713
713
|
* @param location - The entry point from which the user initiated the swap or bridge (e.g. Main View, Token View, Trending Explore)
|
|
714
|
-
* @param abTests - A/B test context
|
|
714
|
+
* @param abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
715
|
+
* @param activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
715
716
|
* @returns The transaction meta
|
|
716
717
|
*/
|
|
717
|
-
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = MetaMetricsSwapsEventSource.MainView, abTests) => {
|
|
718
|
+
this.submitTx = async (accountAddress, quoteResponse, isStxEnabledOnClient, quotesReceivedContext, location = MetaMetricsSwapsEventSource.MainView, abTests, activeAbTests) => {
|
|
718
719
|
this.messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted,
|
|
719
720
|
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
720
721
|
// If the trade has a featureId, it means it was submitted outside of the Unified Swap and Bridge experience, so no QuotesReceived event is published
|
|
@@ -724,12 +725,13 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
724
725
|
throw new Error('Failed to submit cross-chain swap transaction: undefined multichain account');
|
|
725
726
|
}
|
|
726
727
|
const isHardwareAccount = isHardwareWallet(selectedAccount);
|
|
727
|
-
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, isStxEnabledOnClient, isHardwareAccount, location, abTests);
|
|
728
|
+
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, isStxEnabledOnClient, isHardwareAccount, location, abTests, activeAbTests);
|
|
728
729
|
// Emit Submitted event after submit button is clicked
|
|
729
730
|
!quoteResponse.featureId &&
|
|
730
731
|
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Submitted, undefined, preConfirmationProperties);
|
|
731
732
|
let txMeta;
|
|
732
733
|
let approvalTxId;
|
|
734
|
+
let isDelegatedAccount = false;
|
|
733
735
|
const startTime = Date.now();
|
|
734
736
|
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
735
737
|
const isTronTx = isTronChainId(quoteResponse.quote.srcChainId);
|
|
@@ -750,7 +752,9 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
750
752
|
return quoteResponse.approval &&
|
|
751
753
|
isTronTrade(quoteResponse.approval)
|
|
752
754
|
? await __classPrivateFieldGet(this, _BridgeStatusController_handleNonEvmTx, "f").call(this, quoteResponse.approval, quoteResponse, selectedAccount)
|
|
753
|
-
:
|
|
755
|
+
: /* c8 ignore start */
|
|
756
|
+
undefined;
|
|
757
|
+
/* c8 ignore end */
|
|
754
758
|
}
|
|
755
759
|
catch (error) {
|
|
756
760
|
!quoteResponse.featureId &&
|
|
@@ -784,7 +788,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
784
788
|
}
|
|
785
789
|
catch (error) {
|
|
786
790
|
!quoteResponse.featureId &&
|
|
787
|
-
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed,
|
|
791
|
+
__classPrivateFieldGet(this, _BridgeStatusController_trackUnifiedSwapBridgeEvent, "f").call(this, UnifiedSwapBridgeEventName.Failed, undefined, {
|
|
788
792
|
error_message: error?.message,
|
|
789
793
|
...preConfirmationProperties,
|
|
790
794
|
});
|
|
@@ -810,7 +814,25 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
810
814
|
if (!isEvmTxData(quoteResponse.trade)) {
|
|
811
815
|
throw new Error('Failed to submit cross-chain swap transaction: trade is not an EVM transaction');
|
|
812
816
|
}
|
|
813
|
-
if
|
|
817
|
+
// Check if the account is an EIP-7702 delegated account
|
|
818
|
+
// Delegated accounts only allow 1 in-flight tx, so approve + swap
|
|
819
|
+
// must be batched into a single transaction
|
|
820
|
+
const hexChainId = formatChainIdToHex(quoteResponse.quote.srcChainId);
|
|
821
|
+
isDelegatedAccount = await (async () => {
|
|
822
|
+
try {
|
|
823
|
+
const atomicBatchSupport = await this.messenger.call('TransactionController:isAtomicBatchSupported', {
|
|
824
|
+
address: quoteResponse.trade.from,
|
|
825
|
+
chainIds: [hexChainId],
|
|
826
|
+
});
|
|
827
|
+
return atomicBatchSupport.some((entry) => entry.isSupported && entry.delegationAddress);
|
|
828
|
+
}
|
|
829
|
+
catch {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
})();
|
|
833
|
+
if (isStxEnabledOnClient ||
|
|
834
|
+
quoteResponse.quote.gasIncluded7702 ||
|
|
835
|
+
isDelegatedAccount) {
|
|
814
836
|
const { tradeMeta, approvalMeta } = await __classPrivateFieldGet(this, _BridgeStatusController_handleEvmTransactionBatch, "f").call(this, {
|
|
815
837
|
isBridgeTx,
|
|
816
838
|
resetApproval: quoteResponse.resetApproval,
|
|
@@ -820,6 +842,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
820
842
|
trade: quoteResponse.trade,
|
|
821
843
|
quoteResponse,
|
|
822
844
|
requireApproval,
|
|
845
|
+
isDelegatedAccount,
|
|
823
846
|
});
|
|
824
847
|
approvalTxId = approvalMeta?.id;
|
|
825
848
|
return tradeMeta;
|
|
@@ -847,6 +870,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
847
870
|
approvalTxId,
|
|
848
871
|
location,
|
|
849
872
|
abTests,
|
|
873
|
+
activeAbTests,
|
|
850
874
|
}, actionId);
|
|
851
875
|
// Pass txFee when gasIncluded is true to use the quote's gas fees
|
|
852
876
|
// instead of re-estimating (which would fail for max native token swaps)
|
|
@@ -871,7 +895,8 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
871
895
|
// Only add history here for non-EVM and batch EVM transactions
|
|
872
896
|
const isNonBatchEvm = !isNonEvmChainId(quoteResponse.quote.srcChainId) &&
|
|
873
897
|
!isStxEnabledOnClient &&
|
|
874
|
-
!quoteResponse.quote.gasIncluded7702
|
|
898
|
+
!quoteResponse.quote.gasIncluded7702 &&
|
|
899
|
+
!isDelegatedAccount;
|
|
875
900
|
if (!isNonBatchEvm) {
|
|
876
901
|
// Add swap or bridge tx to history
|
|
877
902
|
__classPrivateFieldGet(this, _BridgeStatusController_addTxToHistory, "f").call(this, {
|
|
@@ -888,6 +913,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
888
913
|
approvalTxId,
|
|
889
914
|
location,
|
|
890
915
|
abTests,
|
|
916
|
+
activeAbTests,
|
|
891
917
|
});
|
|
892
918
|
}
|
|
893
919
|
if (isNonEvmChainId(quoteResponse.quote.srcChainId)) {
|
|
@@ -912,40 +938,36 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
912
938
|
* @param params.quoteResponse - Quote carrying intent data
|
|
913
939
|
* @param params.accountAddress - The EOA submitting the order
|
|
914
940
|
* @param params.location - The entry point from which the user initiated the swap or bridge
|
|
915
|
-
* @param params.abTests - A/B test context
|
|
941
|
+
* @param params.abTests - Legacy A/B test context for `ab_tests` (backward compatibility)
|
|
942
|
+
* @param params.activeAbTests - New A/B test context for `active_ab_tests` (migration target). Attributes events to specific experiments.
|
|
916
943
|
* @returns A lightweight TransactionMeta-like object for history linking
|
|
917
944
|
*/
|
|
918
945
|
this.submitIntent = async (params) => {
|
|
919
|
-
const { quoteResponse, accountAddress, location, abTests } = params;
|
|
946
|
+
const { quoteResponse, accountAddress, location, abTests, activeAbTests } = params;
|
|
920
947
|
this.messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted);
|
|
921
948
|
// Build pre-confirmation properties for error tracking parity with submitTx
|
|
922
949
|
const account = __classPrivateFieldGet(this, _BridgeStatusController_instances, "m", _BridgeStatusController_getMultichainSelectedAccount).call(this, accountAddress);
|
|
923
950
|
const isHardwareAccount = Boolean(account) && isHardwareWallet(account);
|
|
924
|
-
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, false, isHardwareAccount, location, abTests);
|
|
951
|
+
const preConfirmationProperties = getPreConfirmationPropertiesFromQuote(quoteResponse, false, isHardwareAccount, location, abTests, activeAbTests);
|
|
925
952
|
try {
|
|
926
953
|
const intent = getIntentFromQuote(quoteResponse);
|
|
927
954
|
// If backend provided an approval tx for this intent quote, submit it first (on-chain),
|
|
928
955
|
// then proceed with off-chain intent submission.
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
/* requireApproval */ false);
|
|
937
|
-
approvalTxId = approvalTxMeta?.id;
|
|
938
|
-
if (approvalTxId) {
|
|
939
|
-
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
940
|
-
}
|
|
956
|
+
const isBridgeTx = isCrossChain(quoteResponse.quote.srcChainId, quoteResponse.quote.destChainId);
|
|
957
|
+
const requireApproval = isHardwareAccount && __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f") === BridgeClientId.MOBILE;
|
|
958
|
+
// Handle approval silently for better UX in intent flows
|
|
959
|
+
const approvalTxMeta = await __classPrivateFieldGet(this, _BridgeStatusController_handleApprovalTx, "f").call(this, isBridgeTx, quoteResponse.quote.srcChainId, quoteResponse.approval, quoteResponse.resetApproval, requireApproval);
|
|
960
|
+
const approvalTxId = approvalTxMeta?.id;
|
|
961
|
+
if (approvalTxId) {
|
|
962
|
+
await __classPrivateFieldGet(this, _BridgeStatusController_waitForTxConfirmation, "f").call(this, approvalTxId);
|
|
941
963
|
}
|
|
942
|
-
const { srcChainId
|
|
964
|
+
const { srcChainId, requestId } = quoteResponse.quote;
|
|
943
965
|
const signature = await this.messenger.call('KeyringController:signTypedMessage', {
|
|
944
966
|
from: accountAddress,
|
|
945
967
|
data: intent.typedData,
|
|
946
968
|
}, SignTypedDataVersion.V4);
|
|
947
969
|
const submissionParams = {
|
|
948
|
-
srcChainId
|
|
970
|
+
srcChainId,
|
|
949
971
|
quoteId: requestId,
|
|
950
972
|
signature,
|
|
951
973
|
order: intent.order,
|
|
@@ -955,16 +977,17 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
955
977
|
const intentOrder = await __classPrivateFieldGet(this, _BridgeStatusController_intentManager, "f").submitIntent(submissionParams, __classPrivateFieldGet(this, _BridgeStatusController_clientId, "f"));
|
|
956
978
|
const orderUid = intentOrder.id;
|
|
957
979
|
// Determine transaction type: swap for same-chain, bridge for cross-chain
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
:
|
|
980
|
+
const transactionType = isBridgeTx
|
|
981
|
+
? /* c8 ignore start */
|
|
982
|
+
TransactionType.bridge
|
|
983
|
+
: /* c8 ignore end */
|
|
984
|
+
TransactionType.swap;
|
|
962
985
|
// Create actual transaction in Transaction Controller first
|
|
963
|
-
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', formatChainIdToHex(
|
|
986
|
+
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', formatChainIdToHex(srcChainId));
|
|
964
987
|
// This is a synthetic transaction whose purpose is to be able
|
|
965
988
|
// to track the order status via the history
|
|
966
989
|
const intentTransactionParams = {
|
|
967
|
-
chainId: formatChainIdToHex(
|
|
990
|
+
chainId: formatChainIdToHex(srcChainId),
|
|
968
991
|
from: accountAddress,
|
|
969
992
|
to: intent.settlementContract ??
|
|
970
993
|
'0x9008D19f58AAbd9eD0D60971565AA8510560ab41', // Default settlement contract
|
|
@@ -994,7 +1017,6 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
994
1017
|
...statusUpdatedTxMeta,
|
|
995
1018
|
isIntentTx: true,
|
|
996
1019
|
orderUid,
|
|
997
|
-
intentType: isCrossChainTx ? 'bridge' : 'swap',
|
|
998
1020
|
};
|
|
999
1021
|
// Record in bridge history with actual transaction metadata
|
|
1000
1022
|
try {
|
|
@@ -1021,6 +1043,7 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1021
1043
|
startTime,
|
|
1022
1044
|
location,
|
|
1023
1045
|
abTests,
|
|
1046
|
+
activeAbTests,
|
|
1024
1047
|
});
|
|
1025
1048
|
// Start polling using the orderId key to route to intent manager
|
|
1026
1049
|
__classPrivateFieldGet(this, _BridgeStatusController_startPollingForTxId, "f").call(this, bridgeHistoryKey);
|
|
@@ -1047,11 +1070,15 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1047
1070
|
* @param eventProperties - The properties for the event
|
|
1048
1071
|
*/
|
|
1049
1072
|
_BridgeStatusController_trackUnifiedSwapBridgeEvent.set(this, (eventName, txMetaId, eventProperties) => {
|
|
1050
|
-
|
|
1073
|
+
// Legacy/new metrics fields are intentionally kept independent during migration.
|
|
1051
1074
|
const historyAbTests = txMetaId
|
|
1052
1075
|
? this.state.txHistory?.[txMetaId]?.abTests
|
|
1053
1076
|
: undefined;
|
|
1054
|
-
const
|
|
1077
|
+
const historyActiveAbTests = txMetaId
|
|
1078
|
+
? this.state.txHistory?.[txMetaId]?.activeAbTests
|
|
1079
|
+
: undefined;
|
|
1080
|
+
const resolvedAbTests = eventProperties?.ab_tests ?? historyAbTests;
|
|
1081
|
+
const resolvedActiveAbTests = eventProperties?.active_ab_tests ?? historyActiveAbTests;
|
|
1055
1082
|
const baseProperties = {
|
|
1056
1083
|
action_type: MetricsActionType.SWAPBRIDGE_V1,
|
|
1057
1084
|
location: eventProperties?.location ??
|
|
@@ -1062,6 +1089,10 @@ export class BridgeStatusController extends StaticIntervalPollingController() {
|
|
|
1062
1089
|
Object.keys(resolvedAbTests).length > 0 && {
|
|
1063
1090
|
ab_tests: resolvedAbTests,
|
|
1064
1091
|
}),
|
|
1092
|
+
...(resolvedActiveAbTests &&
|
|
1093
|
+
resolvedActiveAbTests.length > 0 && {
|
|
1094
|
+
active_ab_tests: resolvedActiveAbTests,
|
|
1095
|
+
}),
|
|
1065
1096
|
};
|
|
1066
1097
|
// This will publish events for PERPS dropped tx failures as well
|
|
1067
1098
|
if (!txMetaId) {
|