@metamask-previews/bridge-status-controller 67.0.1-preview-0aca970c8 → 67.0.1-preview-b2b2c8f6a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/bridge-status-controller.cjs +21 -26
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts +6 -4
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts +6 -4
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +18 -78
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +5 -38
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +5 -38
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +16 -76
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +23 -28
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/intent-api.cjs +6 -10
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +7 -8
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +7 -8
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +6 -10
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/transaction.d.cts +1 -9
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +1 -9
- package/dist/utils/transaction.d.mts.map +1 -1
- package/package.json +1 -2
|
@@ -10,69 +10,31 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _IntentStatusManager_messenger, _IntentStatusManager_updateTransactionFn;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.IntentStatusManager = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_IntentManager_messenger.set(this, void 0);
|
|
23
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
24
|
-
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
25
|
-
/**
|
|
26
|
-
* Get the status of an intent order.
|
|
27
|
-
*
|
|
28
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
29
|
-
* @param protocol - The protocol of the intent.
|
|
30
|
-
* @param clientId - The client ID.
|
|
31
|
-
* @returns The intent order mapped status.
|
|
32
|
-
*/
|
|
33
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId, historyItem, clientId) => {
|
|
34
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
35
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
36
|
-
const protocol = intent?.protocol ?? '';
|
|
37
|
-
try {
|
|
38
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId.toString(), clientId);
|
|
39
|
-
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
if (error instanceof Error) {
|
|
43
|
-
throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Sync the transaction status from the intent status.
|
|
50
|
-
*
|
|
51
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
52
|
-
* @param historyItem - The history item.
|
|
53
|
-
*/
|
|
54
|
-
this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
|
|
17
|
+
class IntentStatusManager {
|
|
18
|
+
constructor({ messenger, updateTransactionFn, }) {
|
|
19
|
+
_IntentStatusManager_messenger.set(this, void 0);
|
|
20
|
+
_IntentStatusManager_updateTransactionFn.set(this, void 0);
|
|
21
|
+
this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus) => {
|
|
55
22
|
// Update the actual transaction in TransactionController to sync with intent status
|
|
56
23
|
// Use the original transaction ID (not the bridge history key)
|
|
57
24
|
const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
|
|
58
25
|
if (!originalTxId) {
|
|
59
26
|
return;
|
|
60
27
|
}
|
|
61
|
-
const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
|
|
62
|
-
if (!intentStatuses) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
28
|
try {
|
|
66
29
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
67
|
-
const { transactions } = __classPrivateFieldGet(this,
|
|
30
|
+
const { transactions } = __classPrivateFieldGet(this, _IntentStatusManager_messenger, "f").call('TransactionController:getState');
|
|
68
31
|
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
69
32
|
if (!existingTxMeta) {
|
|
70
|
-
console.warn('[Intent polling] Skipping update
|
|
33
|
+
console.warn('📝 [Intent polling] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
71
34
|
return;
|
|
72
35
|
}
|
|
73
|
-
const {
|
|
74
|
-
const
|
|
75
|
-
const isComplete = bridgeStatus?.status.status === bridge_controller_1.StatusTypes.COMPLETE;
|
|
36
|
+
const { txHash } = intentTranslation;
|
|
37
|
+
const isComplete = intentTranslation.status.status === bridge_controller_1.StatusTypes.COMPLETE;
|
|
76
38
|
const existingTxReceipt = existingTxMeta.txReceipt;
|
|
77
39
|
const txReceiptUpdate = txHash
|
|
78
40
|
? {
|
|
@@ -85,46 +47,24 @@ class IntentManager {
|
|
|
85
47
|
: {};
|
|
86
48
|
const updatedTxMeta = {
|
|
87
49
|
...existingTxMeta,
|
|
88
|
-
status:
|
|
50
|
+
status: intentTranslation.transactionStatus,
|
|
89
51
|
...(txHash ? { hash: txHash } : {}),
|
|
90
52
|
...txReceiptUpdate,
|
|
91
53
|
};
|
|
92
|
-
__classPrivateFieldGet(this,
|
|
93
|
-
if (isComplete) {
|
|
94
|
-
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
95
|
-
}
|
|
54
|
+
__classPrivateFieldGet(this, _IntentStatusManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`);
|
|
96
55
|
}
|
|
97
56
|
catch (error) {
|
|
98
|
-
console.error('[Intent polling] Failed to update transaction status', {
|
|
57
|
+
console.error('📝 [Intent polling] Failed to update transaction status', {
|
|
99
58
|
originalTxId,
|
|
100
59
|
bridgeHistoryKey: bridgeTxMetaId,
|
|
101
60
|
error,
|
|
102
61
|
});
|
|
103
62
|
}
|
|
104
63
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
* @param submissionParams - The submission parameters.
|
|
109
|
-
* @param clientId - The client ID.
|
|
110
|
-
* @returns The intent order.
|
|
111
|
-
*/
|
|
112
|
-
this.submitIntent = async (submissionParams, clientId) => {
|
|
113
|
-
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
114
|
-
};
|
|
115
|
-
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
116
|
-
__classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
|
|
117
|
-
this.intentApi = new intent_api_1.IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
64
|
+
__classPrivateFieldSet(this, _IntentStatusManager_messenger, messenger, "f");
|
|
65
|
+
__classPrivateFieldSet(this, _IntentStatusManager_updateTransactionFn, updateTransactionFn, "f");
|
|
118
66
|
}
|
|
119
67
|
}
|
|
120
|
-
exports.
|
|
121
|
-
|
|
122
|
-
const bridgeStatus = (0, intent_api_1.translateIntentOrderToBridgeStatus)(order, srcChainId, txHash.toString());
|
|
123
|
-
const intentStatuses = {
|
|
124
|
-
orderStatus: order.status,
|
|
125
|
-
bridgeStatus,
|
|
126
|
-
};
|
|
127
|
-
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
|
|
128
|
-
return intentStatuses;
|
|
129
|
-
};
|
|
68
|
+
exports.IntentStatusManager = IntentStatusManager;
|
|
69
|
+
_IntentStatusManager_messenger = new WeakMap(), _IntentStatusManager_updateTransactionFn = new WeakMap();
|
|
130
70
|
//# sourceMappingURL=bridge-status-controller.intent.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0D;
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.cjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAA0D;AAQ1D,MAAa,mBAAmB;IAK9B,YAAY,EACV,SAAS,EACT,mBAAmB,GAIpB;QAVQ,iDAA4C;QAE5C,2DAA+E;QAaxF,oCAA+B,GAAG,CAChC,cAAsB,EACtB,WAA8B,EAC9B,iBAA0C,EAC1C,iBAAyB,EACnB,EAAE;YACR,oFAAoF;YACpF,+DAA+D;YAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,qBAAqB,IAAI,WAAW,CAAC,QAAQ,CAAC;YAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sEAAsE;gBACtE,MAAM,EAAE,YAAY,EAAE,GAAG,uBAAA,IAAI,sCAAW,CAAC,IAAI,CAC3C,gCAAgC,CACjC,CAAC;gBACF,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CACtC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAChD,CAAC;gBACF,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CACV,4DAA4D,EAC5D,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,CACnD,CAAC;oBACF,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;gBACrC,MAAM,UAAU,GACd,iBAAiB,CAAC,MAAM,CAAC,MAAM,KAAK,+BAAW,CAAC,QAAQ,CAAC;gBAC3D,MAAM,iBAAiB,GACrB,cACD,CAAC,SAAS,CAAC;gBACZ,MAAM,eAAe,GAAG,MAAM;oBAC5B,CAAC,CAAC;wBACE,SAAS,EAAE;4BACT,GAAG,iBAAiB;4BACpB,eAAe,EAAE,MAAM;4BACvB,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAsB;yBAC1D;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;gBAEP,MAAM,aAAa,GAAoB;oBACrC,GAAG,cAAc;oBACjB,MAAM,EAAE,iBAAiB,CAAC,iBAAiB;oBAC3C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,GAAG,eAAe;iBACA,CAAC;gBAErB,uBAAA,IAAI,gDAAqB,MAAzB,IAAI,EACF,aAAa,EACb,yDAAyD,iBAAiB,EAAE,CAC7E,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE;oBACvE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QApEA,uBAAA,IAAI,kCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,4CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;CAmEF;AAjFD,kDAiFC","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { IntentStatusTranslation } from './utils/intent-api';\n\nexport class IntentStatusManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n constructor({\n messenger,\n updateTransactionFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n }\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n intentTranslation: IntentStatusTranslation,\n intentOrderStatus: string,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '📝 [Intent polling] Skipping update; transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n\n const { txHash } = intentTranslation;\n const isComplete =\n intentTranslation.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: intentTranslation.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`,\n );\n } catch (error) {\n console.error('📝 [Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n}\n"]}
|
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
|
-
import type { BridgeStatusControllerMessenger
|
|
2
|
+
import type { BridgeStatusControllerMessenger } from "./types.cjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.cjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type IntentStatuses = {
|
|
7
|
-
orderStatus: IntentOrderStatus;
|
|
8
|
-
bridgeStatus: IntentBridgeStatus | null;
|
|
9
|
-
};
|
|
10
|
-
export declare class IntentManager {
|
|
4
|
+
import { IntentStatusTranslation } from "./utils/intent-api.cjs";
|
|
5
|
+
export declare class IntentStatusManager {
|
|
11
6
|
#private;
|
|
12
|
-
|
|
13
|
-
constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
|
|
7
|
+
constructor({ messenger, updateTransactionFn, }: {
|
|
14
8
|
messenger: BridgeStatusControllerMessenger;
|
|
15
9
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
|
-
customBridgeApiBaseUrl: string;
|
|
17
|
-
fetchFn: FetchFunction;
|
|
18
|
-
getJwt: GetJwtFn;
|
|
19
10
|
});
|
|
20
|
-
|
|
21
|
-
* Get the status of an intent order.
|
|
22
|
-
*
|
|
23
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
24
|
-
* @param protocol - The protocol of the intent.
|
|
25
|
-
* @param clientId - The client ID.
|
|
26
|
-
* @returns The intent order mapped status.
|
|
27
|
-
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, clientId: string) => Promise<IntentStatuses | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* Sync the transaction status from the intent status.
|
|
31
|
-
*
|
|
32
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
33
|
-
* @param historyItem - The history item.
|
|
34
|
-
*/
|
|
35
|
-
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Submit an intent order.
|
|
38
|
-
*
|
|
39
|
-
* @param submissionParams - The submission parameters.
|
|
40
|
-
* @param clientId - The client ID.
|
|
41
|
-
* @returns The intent order.
|
|
42
|
-
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId: string) => Promise<IntentOrder>;
|
|
11
|
+
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, intentTranslation: IntentStatusTranslation, intentOrderStatus: string) => void;
|
|
44
12
|
}
|
|
45
|
-
export {};
|
|
46
13
|
//# sourceMappingURL=bridge-status-controller.intent.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.cts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,oBAAgB;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D,qBAAa,mBAAmB;;gBAKlB,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;KAC/E;IAKD,+BAA+B,mBACb,MAAM,eACT,iBAAiB,qBACX,uBAAuB,qBACvB,MAAM,KACxB,IAAI,CA2DL;CACH"}
|
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
import type { TransactionController } from "@metamask/transaction-controller";
|
|
2
|
-
import type { BridgeStatusControllerMessenger
|
|
2
|
+
import type { BridgeStatusControllerMessenger } from "./types.mjs";
|
|
3
3
|
import type { BridgeHistoryItem } from "./types.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type IntentStatuses = {
|
|
7
|
-
orderStatus: IntentOrderStatus;
|
|
8
|
-
bridgeStatus: IntentBridgeStatus | null;
|
|
9
|
-
};
|
|
10
|
-
export declare class IntentManager {
|
|
4
|
+
import { IntentStatusTranslation } from "./utils/intent-api.mjs";
|
|
5
|
+
export declare class IntentStatusManager {
|
|
11
6
|
#private;
|
|
12
|
-
|
|
13
|
-
constructor({ messenger, updateTransactionFn, customBridgeApiBaseUrl, fetchFn, getJwt, }: {
|
|
7
|
+
constructor({ messenger, updateTransactionFn, }: {
|
|
14
8
|
messenger: BridgeStatusControllerMessenger;
|
|
15
9
|
updateTransactionFn: typeof TransactionController.prototype.updateTransaction;
|
|
16
|
-
customBridgeApiBaseUrl: string;
|
|
17
|
-
fetchFn: FetchFunction;
|
|
18
|
-
getJwt: GetJwtFn;
|
|
19
10
|
});
|
|
20
|
-
|
|
21
|
-
* Get the status of an intent order.
|
|
22
|
-
*
|
|
23
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
24
|
-
* @param protocol - The protocol of the intent.
|
|
25
|
-
* @param clientId - The client ID.
|
|
26
|
-
* @returns The intent order mapped status.
|
|
27
|
-
*/
|
|
28
|
-
getIntentTransactionStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, clientId: string) => Promise<IntentStatuses | undefined>;
|
|
29
|
-
/**
|
|
30
|
-
* Sync the transaction status from the intent status.
|
|
31
|
-
*
|
|
32
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
33
|
-
* @param historyItem - The history item.
|
|
34
|
-
*/
|
|
35
|
-
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Submit an intent order.
|
|
38
|
-
*
|
|
39
|
-
* @param submissionParams - The submission parameters.
|
|
40
|
-
* @param clientId - The client ID.
|
|
41
|
-
* @returns The intent order.
|
|
42
|
-
*/
|
|
43
|
-
submitIntent: (submissionParams: IntentSubmissionParams, clientId: string) => Promise<IntentOrder>;
|
|
11
|
+
syncTransactionFromIntentStatus: (bridgeTxMetaId: string, historyItem: BridgeHistoryItem, intentTranslation: IntentStatusTranslation, intentOrderStatus: string) => void;
|
|
44
12
|
}
|
|
45
|
-
export {};
|
|
46
13
|
//# sourceMappingURL=bridge-status-controller.intent.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.d.mts","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yCAAyC;AAG9E,OAAO,KAAK,EAAE,+BAA+B,EAAE,oBAAgB;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAgB;AACjD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D,qBAAa,mBAAmB;;gBAKlB,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE;QACD,SAAS,EAAE,+BAA+B,CAAC;QAC3C,mBAAmB,EAAE,OAAO,qBAAqB,CAAC,SAAS,CAAC,iBAAiB,CAAC;KAC/E;IAKD,+BAA+B,mBACb,MAAM,eACT,iBAAiB,qBACX,uBAAuB,qBACvB,MAAM,KACxB,IAAI,CA2DL;CACH"}
|
|
@@ -9,67 +9,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _IntentStatusManager_messenger, _IntentStatusManager_updateTransactionFn;
|
|
13
13
|
import { StatusTypes } from "@metamask/bridge-controller";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_IntentManager_messenger.set(this, void 0);
|
|
20
|
-
_IntentManager_updateTransactionFn.set(this, void 0);
|
|
21
|
-
_IntentManager_intentStatusesByBridgeTxMetaId.set(this, new Map());
|
|
22
|
-
/**
|
|
23
|
-
* Get the status of an intent order.
|
|
24
|
-
*
|
|
25
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
26
|
-
* @param protocol - The protocol of the intent.
|
|
27
|
-
* @param clientId - The client ID.
|
|
28
|
-
* @returns The intent order mapped status.
|
|
29
|
-
*/
|
|
30
|
-
this.getIntentTransactionStatus = async (bridgeTxMetaId, historyItem, clientId) => {
|
|
31
|
-
const { status: statusObj, quote: { srcChainId, intent }, } = historyItem;
|
|
32
|
-
const txHash = statusObj?.srcChain?.txHash ?? '';
|
|
33
|
-
const protocol = intent?.protocol ?? '';
|
|
34
|
-
try {
|
|
35
|
-
const orderStatus = await this.intentApi.getOrderStatus(bridgeTxMetaId, protocol, srcChainId.toString(), clientId);
|
|
36
|
-
return __classPrivateFieldGet(this, _IntentManager_instances, "m", _IntentManager_setIntentStatuses).call(this, bridgeTxMetaId, orderStatus, srcChainId, txHash.toString());
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
if (error instanceof Error) {
|
|
40
|
-
throw new Error(`[Intent polling] Failed to get intent order status from API: ${error.message}`);
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Sync the transaction status from the intent status.
|
|
47
|
-
*
|
|
48
|
-
* @param bridgeTxMetaId - The bridge transaction meta ID.
|
|
49
|
-
* @param historyItem - The history item.
|
|
50
|
-
*/
|
|
51
|
-
this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem) => {
|
|
14
|
+
export class IntentStatusManager {
|
|
15
|
+
constructor({ messenger, updateTransactionFn, }) {
|
|
16
|
+
_IntentStatusManager_messenger.set(this, void 0);
|
|
17
|
+
_IntentStatusManager_updateTransactionFn.set(this, void 0);
|
|
18
|
+
this.syncTransactionFromIntentStatus = (bridgeTxMetaId, historyItem, intentTranslation, intentOrderStatus) => {
|
|
52
19
|
// Update the actual transaction in TransactionController to sync with intent status
|
|
53
20
|
// Use the original transaction ID (not the bridge history key)
|
|
54
21
|
const originalTxId = historyItem.originalTransactionId ?? historyItem.txMetaId;
|
|
55
22
|
if (!originalTxId) {
|
|
56
23
|
return;
|
|
57
24
|
}
|
|
58
|
-
const intentStatuses = __classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").get(bridgeTxMetaId);
|
|
59
|
-
if (!intentStatuses) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
25
|
try {
|
|
63
26
|
// Merge with existing TransactionMeta to avoid wiping required fields
|
|
64
|
-
const { transactions } = __classPrivateFieldGet(this,
|
|
27
|
+
const { transactions } = __classPrivateFieldGet(this, _IntentStatusManager_messenger, "f").call('TransactionController:getState');
|
|
65
28
|
const existingTxMeta = transactions.find((tx) => tx.id === originalTxId);
|
|
66
29
|
if (!existingTxMeta) {
|
|
67
|
-
console.warn('[Intent polling] Skipping update
|
|
30
|
+
console.warn('📝 [Intent polling] Skipping update; transaction not found', { originalTxId, bridgeHistoryKey: bridgeTxMetaId });
|
|
68
31
|
return;
|
|
69
32
|
}
|
|
70
|
-
const {
|
|
71
|
-
const
|
|
72
|
-
const isComplete = bridgeStatus?.status.status === StatusTypes.COMPLETE;
|
|
33
|
+
const { txHash } = intentTranslation;
|
|
34
|
+
const isComplete = intentTranslation.status.status === StatusTypes.COMPLETE;
|
|
73
35
|
const existingTxReceipt = existingTxMeta.txReceipt;
|
|
74
36
|
const txReceiptUpdate = txHash
|
|
75
37
|
? {
|
|
@@ -82,45 +44,23 @@ export class IntentManager {
|
|
|
82
44
|
: {};
|
|
83
45
|
const updatedTxMeta = {
|
|
84
46
|
...existingTxMeta,
|
|
85
|
-
status:
|
|
47
|
+
status: intentTranslation.transactionStatus,
|
|
86
48
|
...(txHash ? { hash: txHash } : {}),
|
|
87
49
|
...txReceiptUpdate,
|
|
88
50
|
};
|
|
89
|
-
__classPrivateFieldGet(this,
|
|
90
|
-
if (isComplete) {
|
|
91
|
-
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").delete(bridgeTxMetaId);
|
|
92
|
-
}
|
|
51
|
+
__classPrivateFieldGet(this, _IntentStatusManager_updateTransactionFn, "f").call(this, updatedTxMeta, `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`);
|
|
93
52
|
}
|
|
94
53
|
catch (error) {
|
|
95
|
-
console.error('[Intent polling] Failed to update transaction status', {
|
|
54
|
+
console.error('📝 [Intent polling] Failed to update transaction status', {
|
|
96
55
|
originalTxId,
|
|
97
56
|
bridgeHistoryKey: bridgeTxMetaId,
|
|
98
57
|
error,
|
|
99
58
|
});
|
|
100
59
|
}
|
|
101
60
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
* @param submissionParams - The submission parameters.
|
|
106
|
-
* @param clientId - The client ID.
|
|
107
|
-
* @returns The intent order.
|
|
108
|
-
*/
|
|
109
|
-
this.submitIntent = async (submissionParams, clientId) => {
|
|
110
|
-
return this.intentApi.submitIntent(submissionParams, clientId);
|
|
111
|
-
};
|
|
112
|
-
__classPrivateFieldSet(this, _IntentManager_messenger, messenger, "f");
|
|
113
|
-
__classPrivateFieldSet(this, _IntentManager_updateTransactionFn, updateTransactionFn, "f");
|
|
114
|
-
this.intentApi = new IntentApiImpl(customBridgeApiBaseUrl, fetchFn, getJwt);
|
|
61
|
+
__classPrivateFieldSet(this, _IntentStatusManager_messenger, messenger, "f");
|
|
62
|
+
__classPrivateFieldSet(this, _IntentStatusManager_updateTransactionFn, updateTransactionFn, "f");
|
|
115
63
|
}
|
|
116
64
|
}
|
|
117
|
-
|
|
118
|
-
const bridgeStatus = translateIntentOrderToBridgeStatus(order, srcChainId, txHash.toString());
|
|
119
|
-
const intentStatuses = {
|
|
120
|
-
orderStatus: order.status,
|
|
121
|
-
bridgeStatus,
|
|
122
|
-
};
|
|
123
|
-
__classPrivateFieldGet(this, _IntentManager_intentStatusesByBridgeTxMetaId, "f").set(bridgeTxMetaId, intentStatuses);
|
|
124
|
-
return intentStatuses;
|
|
125
|
-
};
|
|
65
|
+
_IntentStatusManager_messenger = new WeakMap(), _IntentStatusManager_updateTransactionFn = new WeakMap();
|
|
126
66
|
//# sourceMappingURL=bridge-status-controller.intent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"bridge-status-controller.intent.mjs","sourceRoot":"","sources":["../src/bridge-status-controller.intent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,oCAAoC;AAQ1D,MAAM,OAAO,mBAAmB;IAK9B,YAAY,EACV,SAAS,EACT,mBAAmB,GAIpB;QAVQ,iDAA4C;QAE5C,2DAA+E;QAaxF,oCAA+B,GAAG,CAChC,cAAsB,EACtB,WAA8B,EAC9B,iBAA0C,EAC1C,iBAAyB,EACnB,EAAE;YACR,oFAAoF;YACpF,+DAA+D;YAC/D,MAAM,YAAY,GAChB,WAAW,CAAC,qBAAqB,IAAI,WAAW,CAAC,QAAQ,CAAC;YAC5D,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sEAAsE;gBACtE,MAAM,EAAE,YAAY,EAAE,GAAG,uBAAA,IAAI,sCAAW,CAAC,IAAI,CAC3C,gCAAgC,CACjC,CAAC;gBACF,MAAM,cAAc,GAAG,YAAY,CAAC,IAAI,CACtC,CAAC,EAAmB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAChD,CAAC;gBACF,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,OAAO,CAAC,IAAI,CACV,4DAA4D,EAC5D,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,CACnD,CAAC;oBACF,OAAO;gBACT,CAAC;gBAED,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC;gBACrC,MAAM,UAAU,GACd,iBAAiB,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,QAAQ,CAAC;gBAC3D,MAAM,iBAAiB,GACrB,cACD,CAAC,SAAS,CAAC;gBACZ,MAAM,eAAe,GAAG,MAAM;oBAC5B,CAAC,CAAC;wBACE,SAAS,EAAE;4BACT,GAAG,iBAAiB;4BACpB,eAAe,EAAE,MAAM;4BACvB,MAAM,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAsB;yBAC1D;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;gBAEP,MAAM,aAAa,GAAoB;oBACrC,GAAG,cAAc;oBACjB,MAAM,EAAE,iBAAiB,CAAC,iBAAiB;oBAC3C,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,GAAG,eAAe;iBACA,CAAC;gBAErB,uBAAA,IAAI,gDAAqB,MAAzB,IAAI,EACF,aAAa,EACb,yDAAyD,iBAAiB,EAAE,CAC7E,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE;oBACvE,YAAY;oBACZ,gBAAgB,EAAE,cAAc;oBAChC,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QApEA,uBAAA,IAAI,kCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,4CAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;CAmEF","sourcesContent":["import { StatusTypes } from '@metamask/bridge-controller';\nimport type { TransactionController } from '@metamask/transaction-controller';\nimport { TransactionMeta } from '@metamask/transaction-controller';\n\nimport type { BridgeStatusControllerMessenger } from './types';\nimport type { BridgeHistoryItem } from './types';\nimport { IntentStatusTranslation } from './utils/intent-api';\n\nexport class IntentStatusManager {\n readonly #messenger: BridgeStatusControllerMessenger;\n\n readonly #updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n\n constructor({\n messenger,\n updateTransactionFn,\n }: {\n messenger: BridgeStatusControllerMessenger;\n updateTransactionFn: typeof TransactionController.prototype.updateTransaction;\n }) {\n this.#messenger = messenger;\n this.#updateTransactionFn = updateTransactionFn;\n }\n\n syncTransactionFromIntentStatus = (\n bridgeTxMetaId: string,\n historyItem: BridgeHistoryItem,\n intentTranslation: IntentStatusTranslation,\n intentOrderStatus: string,\n ): void => {\n // Update the actual transaction in TransactionController to sync with intent status\n // Use the original transaction ID (not the bridge history key)\n const originalTxId =\n historyItem.originalTransactionId ?? historyItem.txMetaId;\n if (!originalTxId) {\n return;\n }\n\n try {\n // Merge with existing TransactionMeta to avoid wiping required fields\n const { transactions } = this.#messenger.call(\n 'TransactionController:getState',\n );\n const existingTxMeta = transactions.find(\n (tx: TransactionMeta) => tx.id === originalTxId,\n );\n if (!existingTxMeta) {\n console.warn(\n '📝 [Intent polling] Skipping update; transaction not found',\n { originalTxId, bridgeHistoryKey: bridgeTxMetaId },\n );\n return;\n }\n\n const { txHash } = intentTranslation;\n const isComplete =\n intentTranslation.status.status === StatusTypes.COMPLETE;\n const existingTxReceipt = (\n existingTxMeta as { txReceipt?: Record<string, unknown> }\n ).txReceipt;\n const txReceiptUpdate = txHash\n ? {\n txReceipt: {\n ...existingTxReceipt,\n transactionHash: txHash,\n status: (isComplete ? '0x1' : '0x0') as unknown as string,\n },\n }\n : {};\n\n const updatedTxMeta: TransactionMeta = {\n ...existingTxMeta,\n status: intentTranslation.transactionStatus,\n ...(txHash ? { hash: txHash } : {}),\n ...txReceiptUpdate,\n } as TransactionMeta;\n\n this.#updateTransactionFn(\n updatedTxMeta,\n `BridgeStatusController - Intent order status updated: ${intentOrderStatus}`,\n );\n } catch (error) {\n console.error('📝 [Intent polling] Failed to update transaction status', {\n originalTxId,\n bridgeHistoryKey: bridgeTxMetaId,\n error,\n });\n }\n };\n}\n"]}
|