@metamask/bridge-status-controller 67.0.0 → 68.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 +30 -1
- package/dist/bridge-status-controller.cjs +43 -24
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +8 -7
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +8 -7
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +80 -18
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +38 -5
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +38 -5
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +78 -16
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +45 -26
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +9 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +9 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +10 -6
- 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 +10 -6
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/metrics.cjs +3 -1
- package/dist/utils/metrics.cjs.map +1 -1
- package/dist/utils/metrics.d.cts +3 -1
- package/dist/utils/metrics.d.cts.map +1 -1
- package/dist/utils/metrics.d.mts +3 -1
- package/dist/utils/metrics.d.mts.map +1 -1
- package/dist/utils/metrics.mjs +3 -1
- package/dist/utils/metrics.mjs.map +1 -1
- package/dist/utils/transaction.d.cts +11 -1
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +11 -1
- package/dist/utils/transaction.d.mts.map +1 -1
- package/package.json +9 -9
|
@@ -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,
|
|
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,EACN,oCAAoC;AACrC,OAAO,EAIL,0BAA0B,EAO1B,2BAA2B,EAK5B,oCAAoC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAQhE,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAEhB,yCAAyC;AAK1C,OAAO,EAEL,6BAA6B,EAK9B,wBAAoB;AACrB,OAAO,KAAK,EACV,2BAA2B,EAC3B,2CAA2C,EAC3C,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EAClB,oBAAgB;AACjB,OAAO,KAAK,EAAE,+BAA+B,EAAE,oBAAgB;AAC/D,OAAO,EAAE,cAAc,EAAE,oBAAgB;AA+CzC,wEAAwE;AACxE,KAAK,wBAAwB,GAAG,uBAAuB,CAAC;AAGxD,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;;;;;;;;;;;;;;;;AACF,qBAAa,sBAAuB,SAAQ,4BAC1C,OAAO,6BAA6B,EACpC,2BAA2B,EAC3B,+BAA+B,CAChC;;gBAuBa,EACV,SAAS,EACT,KAAK,EACL,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,MAAM,E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C,CAAC,CAgR1D;IAEF;;;;;;;;;;OAUG;IACH,YAAY,WAAkB;QAC5B,aAAa,EAAE,cAAc,KAAK,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC;QAC3D,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,2BAA2B,CAAC;QACvC,OAAO,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,KAAG,QAAQ,KAAK,eAAe,EAAE,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CA6LtE;CA2HH"}
|
|
@@ -10,31 +10,71 @@ 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
|
|
13
|
+
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.IntentManager = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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) => {
|
|
22
55
|
// Update the actual transaction in TransactionController to sync with intent status
|
|
23
56
|
// Use the original transaction ID (not the bridge history key)
|
|
24
57
|
const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
|
|
25
58
|
if (!originalTxId) {
|
|
26
59
|
return;
|
|
27
60
|
}
|
|
61
|
+
const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
|
|
62
|
+
if (!intentStatuses) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
28
65
|
try {
|
|
29
66
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
30
|
-
const { transactions } = __classPrivateFieldGet(this,
|
|
67
|
+
const { transactions } = __classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:getState');
|
|
31
68
|
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
32
69
|
if (!existingTxMeta) {
|
|
33
|
-
console.warn('
|
|
70
|
+
console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
34
71
|
return;
|
|
35
72
|
}
|
|
36
|
-
const {
|
|
37
|
-
const
|
|
73
|
+
const { bridgeStatus, orderStatus } = intentStatuses;
|
|
74
|
+
const txHash = bridgeStatus?.txHash;
|
|
75
|
+
const isComplete = bridgeStatus?.status.status === bridge_controller_1.StatusTypes.COMPLETE;
|
|
76
|
+
const isFinalStatus = bridgeStatus?.status.status === bridge_controller_1.StatusTypes.COMPLETE ||
|
|
77
|
+
bridgeStatus?.status.status === bridge_controller_1.StatusTypes.FAILED;
|
|
38
78
|
const existingTxReceipt = existingTxMeta.txReceipt;
|
|
39
79
|
const txReceiptUpdate = txHash
|
|
40
80
|
? {
|
|
@@ -47,24 +87,46 @@ class IntentStatusManager {
|
|
|
47
87
|
: {};
|
|
48
88
|
const updatedTxMeta = {
|
|
49
89
|
...existingTxMeta,
|
|
50
|
-
status:
|
|
90
|
+
status: bridgeStatus?.transactionStatus,
|
|
51
91
|
...(txHash ? { hash: txHash } : {}),
|
|
52
92
|
...txReceiptUpdate,
|
|
53
93
|
};
|
|
54
|
-
__classPrivateFieldGet(this,
|
|
94
|
+
__classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
95
|
+
if (isFinalStatus) {
|
|
96
|
+
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
97
|
+
}
|
|
55
98
|
}
|
|
56
99
|
catch (error) {
|
|
57
|
-
console.error('
|
|
100
|
+
console.error('[Intent polling] Failed to update transaction status', {
|
|
58
101
|
originalTxId,
|
|
59
102
|
bridgeHistoryKey: bridgeTxMetaId,
|
|
60
103
|
error,
|
|
61
104
|
});
|
|
62
105
|
}
|
|
63
106
|
};
|
|
64
|
-
|
|
65
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Submit an intent order.
|
|
109
|
+
*
|
|
110
|
+
* @param submissionParams - The submission parameters.
|
|
111
|
+
* @param clientId - The client ID.
|
|
112
|
+
* @returns The intent order.
|
|
113
|
+
*/
|
|
114
|
+
this.submitIntent = async (submissionParams, clientId) => {
|
|
115
|
+
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
116
|
+
};
|
|
117
|
+
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
118
|
+
__classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
|
|
119
|
+
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
66
120
|
}
|
|
67
121
|
}
|
|
68
|
-
exports.
|
|
69
|
-
|
|
122
|
+
exports.IntentManager = IntentManager;
|
|
123
|
+
_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.toString());
|
|
125
|
+
const intentStatuses = {
|
|
126
|
+
orderStatus: order.status,
|
|
127
|
+
bridgeStatus,
|
|
128
|
+
};
|
|
129
|
+
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
|
|
130
|
+
return intentStatuses;
|
|
131
|
+
};
|
|
70
132
|
//# 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;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
|
+
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;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c,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,13 +1,46 @@
|
|
|
1
1
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
|
-
import type { BridgeStatusControllerMessenger } from "./types.cjs";
|
|
2
|
+
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.cjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
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 {
|
|
6
11
|
#private;
|
|
7
|
-
|
|
12
|
+
readonly intentApi: IntentApi;
|
|
13
|
+
constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
|
|
8
14
|
messenger: BridgeStatusControllerMessenger;
|
|
9
15
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
|
+
customBridgeApiBaseUrl: string;
|
|
17
|
+
fetchFn: FetchFunction;
|
|
18
|
+
getJwt: GetJwtFn;
|
|
10
19
|
});
|
|
11
|
-
|
|
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>;
|
|
12
44
|
}
|
|
45
|
+
export {};
|
|
13
46
|
//# 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,oBAAgB;
|
|
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,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,MAAM,KACf,QAAQ,WAAW,CAAC,CAErB;CACH"}
|
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
|
-
import type { BridgeStatusControllerMessenger } from "./types.mjs";
|
|
2
|
+
import type { BridgeStatusControllerMessenger, FetchFunction } from "./types.mjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
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 {
|
|
6
11
|
#private;
|
|
7
|
-
|
|
12
|
+
readonly intentApi: IntentApi;
|
|
13
|
+
constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
|
|
8
14
|
messenger: BridgeStatusControllerMessenger;
|
|
9
15
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
|
+
customBridgeApiBaseUrl: string;
|
|
17
|
+
fetchFn: FetchFunction;
|
|
18
|
+
getJwt: GetJwtFn;
|
|
10
19
|
});
|
|
11
|
-
|
|
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>;
|
|
12
44
|
}
|
|
45
|
+
export {};
|
|
13
46
|
//# 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,oBAAgB;
|
|
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,CAuEL;IAEF;;;;;;OAMG;IACH,YAAY,qBACQ,sBAAsB,YAC9B,MAAM,KACf,QAAQ,WAAW,CAAC,CAErB;CACH"}
|
|
@@ -9,29 +9,69 @@ 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
|
|
12
|
+
var _IntentManager_instances, _IntentManager_messenger, _IntentManager_updateTransactionFn, _IntentManager_intentStatusesByBridgeTxMetaId, _IntentManager_setIntentStatuses;
|
|
13
13
|
import { StatusTypes } from "@metamask/bridge-controller";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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) => {
|
|
19
52
|
// Update the actual transaction in TransactionController to sync with intent status
|
|
20
53
|
// Use the original transaction ID (not the bridge history key)
|
|
21
54
|
const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
|
|
22
55
|
if (!originalTxId) {
|
|
23
56
|
return;
|
|
24
57
|
}
|
|
58
|
+
const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
|
|
59
|
+
if (!intentStatuses) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
25
62
|
try {
|
|
26
63
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
27
|
-
const { transactions } = __classPrivateFieldGet(this,
|
|
64
|
+
const { transactions } = __classPrivateFieldGet(this, _IntentManager_messenger, "f").call('TransactionController:getState');
|
|
28
65
|
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
29
66
|
if (!existingTxMeta) {
|
|
30
|
-
console.warn('
|
|
67
|
+
console.warn('[Intent polling] Skipping update, transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
31
68
|
return;
|
|
32
69
|
}
|
|
33
|
-
const {
|
|
34
|
-
const
|
|
70
|
+
const { bridgeStatus, orderStatus } = intentStatuses;
|
|
71
|
+
const txHash = bridgeStatus?.txHash;
|
|
72
|
+
const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;
|
|
73
|
+
const isFinalStatus = bridgeStatus?.status.status === StatusTypes.COMPLETE ||
|
|
74
|
+
bridgeStatus?.status.status === StatusTypes.FAILED;
|
|
35
75
|
const existingTxReceipt = existingTxMeta.txReceipt;
|
|
36
76
|
const txReceiptUpdate = txHash
|
|
37
77
|
? {
|
|
@@ -44,23 +84,45 @@ export class IntentStatusManager {
|
|
|
44
84
|
: {};
|
|
45
85
|
const updatedTxMeta = {
|
|
46
86
|
...existingTxMeta,
|
|
47
|
-
status:
|
|
87
|
+
status: bridgeStatus?.transactionStatus,
|
|
48
88
|
...(txHash ? { hash: txHash } : {}),
|
|
49
89
|
...txReceiptUpdate,
|
|
50
90
|
};
|
|
51
|
-
__classPrivateFieldGet(this,
|
|
91
|
+
__classPrivateFieldGet(this, _IntentManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${orderStatus}`);
|
|
92
|
+
if (isFinalStatus) {
|
|
93
|
+
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
94
|
+
}
|
|
52
95
|
}
|
|
53
96
|
catch (error) {
|
|
54
|
-
console.error('
|
|
97
|
+
console.error('[Intent polling] Failed to update transaction status', {
|
|
55
98
|
originalTxId,
|
|
56
99
|
bridgeHistoryKey: bridgeTxMetaId,
|
|
57
100
|
error,
|
|
58
101
|
});
|
|
59
102
|
}
|
|
60
103
|
};
|
|
61
|
-
|
|
62
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Submit an intent order.
|
|
106
|
+
*
|
|
107
|
+
* @param submissionParams - The submission parameters.
|
|
108
|
+
* @param clientId - The client ID.
|
|
109
|
+
* @returns The intent order.
|
|
110
|
+
*/
|
|
111
|
+
this.submitIntent = async (submissionParams, clientId) => {
|
|
112
|
+
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
113
|
+
};
|
|
114
|
+
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
115
|
+
__classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
|
|
116
|
+
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
63
117
|
}
|
|
64
118
|
}
|
|
65
|
-
|
|
119
|
+
_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.toString());
|
|
121
|
+
const intentStatuses = {
|
|
122
|
+
orderStatus: order.status,
|
|
123
|
+
bridgeStatus,
|
|
124
|
+
};
|
|
125
|
+
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
|
|
126
|
+
return intentStatuses;
|
|
127
|
+
};
|
|
66
128
|
//# 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;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,E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AAmB,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"]}
|
|
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,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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CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACjE,CAAC,CAAC;QA9KA,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;CA4KF;oRA/JG,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 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"]}
|