@metamask-previews/bridge-status-controller 69.0.0-preview-45f35b773 → 69.0.0-preview-e0f8f1907
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 +4 -0
- package/dist/bridge-status-controller.cjs +73 -175
- package/dist/bridge-status-controller.cjs.map +1 -1
- package/dist/bridge-status-controller.d.cts.map +1 -1
- package/dist/bridge-status-controller.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.cjs +3 -2
- package/dist/bridge-status-controller.intent.cjs.map +1 -1
- package/dist/bridge-status-controller.intent.d.cts +2 -3
- package/dist/bridge-status-controller.intent.d.cts.map +1 -1
- package/dist/bridge-status-controller.intent.d.mts +2 -3
- package/dist/bridge-status-controller.intent.d.mts.map +1 -1
- package/dist/bridge-status-controller.intent.mjs +3 -2
- package/dist/bridge-status-controller.intent.mjs.map +1 -1
- package/dist/bridge-status-controller.mjs +75 -177
- package/dist/bridge-status-controller.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/utils/accounts.cjs +8 -0
- package/dist/utils/accounts.cjs.map +1 -0
- package/dist/utils/accounts.d.cts +36 -0
- package/dist/utils/accounts.d.cts.map +1 -0
- package/dist/utils/accounts.d.mts +36 -0
- package/dist/utils/accounts.d.mts.map +1 -0
- package/dist/utils/accounts.mjs +4 -0
- package/dist/utils/accounts.mjs.map +1 -0
- package/dist/utils/authentication.cjs +15 -0
- package/dist/utils/authentication.cjs.map +1 -0
- package/dist/utils/authentication.d.cts +3 -0
- package/dist/utils/authentication.d.cts.map +1 -0
- package/dist/utils/authentication.d.mts +3 -0
- package/dist/utils/authentication.d.mts.map +1 -0
- package/dist/utils/authentication.mjs +11 -0
- package/dist/utils/authentication.mjs.map +1 -0
- package/dist/utils/bridge.cjs +16 -0
- package/dist/utils/bridge.cjs.map +1 -0
- package/dist/utils/bridge.d.cts +10 -0
- package/dist/utils/bridge.d.cts.map +1 -0
- package/dist/utils/bridge.d.mts +10 -0
- package/dist/utils/bridge.d.mts.map +1 -0
- package/dist/utils/bridge.mjs +11 -0
- package/dist/utils/bridge.mjs.map +1 -0
- package/dist/utils/history.cjs +97 -0
- package/dist/utils/history.cjs.map +1 -0
- package/dist/utils/history.d.cts +21 -0
- package/dist/utils/history.d.cts.map +1 -0
- package/dist/utils/history.d.mts +21 -0
- package/dist/utils/history.d.mts.map +1 -0
- package/dist/utils/history.mjs +90 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/intent-api.cjs +16 -1
- package/dist/utils/intent-api.cjs.map +1 -1
- package/dist/utils/intent-api.d.cts +9 -1
- package/dist/utils/intent-api.d.cts.map +1 -1
- package/dist/utils/intent-api.d.mts +9 -1
- package/dist/utils/intent-api.d.mts.map +1 -1
- package/dist/utils/intent-api.mjs +14 -0
- package/dist/utils/intent-api.mjs.map +1 -1
- package/dist/utils/keyring.cjs +12 -0
- package/dist/utils/keyring.cjs.map +1 -0
- package/dist/utils/keyring.d.cts +8 -0
- package/dist/utils/keyring.d.cts.map +1 -0
- package/dist/utils/keyring.d.mts +8 -0
- package/dist/utils/keyring.d.mts.map +1 -0
- package/dist/utils/keyring.mjs +8 -0
- package/dist/utils/keyring.mjs.map +1 -0
- package/dist/utils/network.cjs +17 -0
- package/dist/utils/network.cjs.map +1 -0
- package/dist/utils/network.d.cts +5 -0
- package/dist/utils/network.d.cts.map +1 -0
- package/dist/utils/network.d.mts +5 -0
- package/dist/utils/network.d.mts.map +1 -0
- package/dist/utils/network.mjs +12 -0
- package/dist/utils/network.mjs.map +1 -0
- package/dist/utils/snaps.cjs +146 -1
- package/dist/utils/snaps.cjs.map +1 -1
- package/dist/utils/snaps.d.cts +62 -0
- package/dist/utils/snaps.d.cts.map +1 -1
- package/dist/utils/snaps.d.mts +62 -0
- package/dist/utils/snaps.d.mts.map +1 -1
- package/dist/utils/snaps.mjs +141 -0
- package/dist/utils/snaps.mjs.map +1 -1
- package/dist/utils/trace.cjs +31 -0
- package/dist/utils/trace.cjs.map +1 -0
- package/dist/utils/trace.d.cts +17 -0
- package/dist/utils/trace.d.cts.map +1 -0
- package/dist/utils/trace.d.mts +17 -0
- package/dist/utils/trace.d.mts.map +1 -0
- package/dist/utils/trace.mjs +26 -0
- package/dist/utils/trace.mjs.map +1 -0
- package/dist/utils/transaction.cjs +6 -177
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +2 -73
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +2 -73
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +6 -171
- package/dist/utils/transaction.mjs.map +1 -1
- package/dist/utils/validators.d.cts +2 -2
- package/dist/utils/validators.d.mts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
2
|
+
export declare const getAccountByAddress: (messenger: BridgeStatusControllerMessenger, address: string) => {
|
|
3
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
4
|
+
id: string;
|
|
5
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
6
|
+
entropy?: {
|
|
7
|
+
type: "mnemonic";
|
|
8
|
+
id: string;
|
|
9
|
+
derivationPath: string;
|
|
10
|
+
groupIndex: number;
|
|
11
|
+
} | {
|
|
12
|
+
type: "private-key";
|
|
13
|
+
} | {
|
|
14
|
+
type: "custom";
|
|
15
|
+
} | undefined;
|
|
16
|
+
exportable?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
metadata: {
|
|
19
|
+
name: string;
|
|
20
|
+
importTime: number;
|
|
21
|
+
keyring: {
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
snap?: {
|
|
25
|
+
name: string;
|
|
26
|
+
id: string;
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
} | undefined;
|
|
29
|
+
nameLastUpdatedAt?: number | undefined;
|
|
30
|
+
lastSelected?: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
address: string;
|
|
33
|
+
scopes: `${string}:${string}`[];
|
|
34
|
+
methods: string[];
|
|
35
|
+
} | undefined;
|
|
36
|
+
//# sourceMappingURL=accounts.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.cts","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,mBAAmB,wDAErB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAGhB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
2
|
+
export declare const getAccountByAddress: (messenger: BridgeStatusControllerMessenger, address: string) => {
|
|
3
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
|
|
4
|
+
id: string;
|
|
5
|
+
options: Record<string, import("@metamask/utils").Json> & {
|
|
6
|
+
entropy?: {
|
|
7
|
+
type: "mnemonic";
|
|
8
|
+
id: string;
|
|
9
|
+
derivationPath: string;
|
|
10
|
+
groupIndex: number;
|
|
11
|
+
} | {
|
|
12
|
+
type: "private-key";
|
|
13
|
+
} | {
|
|
14
|
+
type: "custom";
|
|
15
|
+
} | undefined;
|
|
16
|
+
exportable?: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
metadata: {
|
|
19
|
+
name: string;
|
|
20
|
+
importTime: number;
|
|
21
|
+
keyring: {
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
snap?: {
|
|
25
|
+
name: string;
|
|
26
|
+
id: string;
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
} | undefined;
|
|
29
|
+
nameLastUpdatedAt?: number | undefined;
|
|
30
|
+
lastSelected?: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
address: string;
|
|
33
|
+
scopes: `${string}:${string}`[];
|
|
34
|
+
methods: string[];
|
|
35
|
+
} | undefined;
|
|
36
|
+
//# sourceMappingURL=accounts.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.mts","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,mBAAmB,wDAErB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAGhB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.mjs","sourceRoot":"","sources":["../../src/utils/accounts.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,SAA0C,EAC1C,OAAe,EACf,EAAE;IACF,OAAO,SAAS,CAAC,IAAI,CAAC,wCAAwC,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/explicit-function-return-type */\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const getAccountByAddress = (\n messenger: BridgeStatusControllerMessenger,\n address: string,\n) => {\n return messenger.call('AccountsController:getAccountByAddress', address);\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getJwt = void 0;
|
|
4
|
+
const getJwt = async (messenger) => {
|
|
5
|
+
try {
|
|
6
|
+
const token = await messenger.call('AuthenticationController:getBearerToken');
|
|
7
|
+
return token;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.error('Error getting JWT token for bridge-api request', error);
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.getJwt = getJwt;
|
|
15
|
+
//# sourceMappingURL=authentication.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.cjs","sourceRoot":"","sources":["../../src/utils/authentication.ts"],"names":[],"mappings":";;;AAEO,MAAM,MAAM,GAAG,KAAK,EACzB,SAA0C,EACb,EAAE;IAC/B,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAChC,yCAAyC,CAC1C,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,MAAM,UAYjB","sourcesContent":["import type { BridgeStatusControllerMessenger } from '../types';\n\nexport const getJwt = async (\n messenger: BridgeStatusControllerMessenger,\n): Promise<string | undefined> => {\n try {\n const token = await messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return token;\n } catch (error) {\n console.error('Error getting JWT token for bridge-api request', error);\n return undefined;\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.d.cts","sourceRoot":"","sources":["../../src/utils/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAEhE,eAAO,MAAM,MAAM,kDAEhB,QAAQ,MAAM,GAAG,SAAS,CAU5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.d.mts","sourceRoot":"","sources":["../../src/utils/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,qBAAiB;AAEhE,eAAO,MAAM,MAAM,kDAEhB,QAAQ,MAAM,GAAG,SAAS,CAU5B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getJwt = async (messenger) => {
|
|
2
|
+
try {
|
|
3
|
+
const token = await messenger.call('AuthenticationController:getBearerToken');
|
|
4
|
+
return token;
|
|
5
|
+
}
|
|
6
|
+
catch (error) {
|
|
7
|
+
console.error('Error getting JWT token for bridge-api request', error);
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=authentication.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.mjs","sourceRoot":"","sources":["../../src/utils/authentication.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EACzB,SAA0C,EACb,EAAE;IAC/B,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAChC,yCAAyC,CAC1C,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { BridgeStatusControllerMessenger } from '../types';\n\nexport const getJwt = async (\n messenger: BridgeStatusControllerMessenger,\n): Promise<string | undefined> => {\n try {\n const token = await messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return token;\n } catch (error) {\n console.error('Error getting JWT token for bridge-api request', error);\n return undefined;\n }\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackMetricsEvent = exports.stopPollingForQuotes = void 0;
|
|
4
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
|
+
const stopPollingForQuotes = (messenger, featureId, metricsContext) => {
|
|
6
|
+
messenger.call('BridgeController:stopPollingForQuotes', bridge_controller_1.AbortReason.TransactionSubmitted,
|
|
7
|
+
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
8
|
+
// 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
|
|
9
|
+
featureId ? undefined : metricsContext);
|
|
10
|
+
};
|
|
11
|
+
exports.stopPollingForQuotes = stopPollingForQuotes;
|
|
12
|
+
const trackMetricsEvent = ({ messenger, eventName, properties, }) => {
|
|
13
|
+
messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, properties);
|
|
14
|
+
};
|
|
15
|
+
exports.trackMetricsEvent = trackMetricsEvent;
|
|
16
|
+
//# sourceMappingURL=bridge.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.cjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":";;;AAAA,mEAIqC;AAK9B,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,SAAqB,EACrB,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,+BAAW,CAAC,oBAAoB;IAChC,4FAA4F;IAC5F,qJAAqJ;IACrJ,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CACvC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEK,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B","sourcesContent":["import {\n AbortReason,\n FeatureId,\n UnifiedSwapBridgeEventName,\n} from '@metamask/bridge-controller';\nimport type { RequiredEventContextFromClient } from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n featureId?: FeatureId,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n // If trade is submitted before all quotes are loaded, the QuotesReceived event is published\n // 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\n featureId ? undefined : metricsContext,\n );\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
|
|
2
|
+
import type { RequiredEventContextFromClient } from "@metamask/bridge-controller";
|
|
3
|
+
import { BridgeStatusControllerMessenger } from "../types.cjs";
|
|
4
|
+
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, featureId?: FeatureId, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
|
|
5
|
+
export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
|
|
6
|
+
messenger: BridgeStatusControllerMessenger;
|
|
7
|
+
eventName: UnifiedSwapBridgeEventName;
|
|
8
|
+
properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];
|
|
9
|
+
}) => void;
|
|
10
|
+
//# sourceMappingURL=bridge.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.cts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AACrC,OAAO,KAAK,EAAE,8BAA8B,EAAE,oCAAoC;AAElF,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,2DAEnB,SAAS,mBACJ,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAQF,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
|
|
2
|
+
import type { RequiredEventContextFromClient } from "@metamask/bridge-controller";
|
|
3
|
+
import { BridgeStatusControllerMessenger } from "../types.mjs";
|
|
4
|
+
export declare const stopPollingForQuotes: (messenger: BridgeStatusControllerMessenger, featureId?: FeatureId, metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived]) => void;
|
|
5
|
+
export declare const trackMetricsEvent: ({ messenger, eventName, properties, }: {
|
|
6
|
+
messenger: BridgeStatusControllerMessenger;
|
|
7
|
+
eventName: UnifiedSwapBridgeEventName;
|
|
8
|
+
properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];
|
|
9
|
+
}) => void;
|
|
10
|
+
//# sourceMappingURL=bridge.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AACrC,OAAO,KAAK,EAAE,8BAA8B,EAAE,oCAAoC;AAElF,OAAO,EAAE,+BAA+B,EAAE,qBAAiB;AAE3D,eAAO,MAAM,oBAAoB,2DAEnB,SAAS,mBACJ,8BAA8B,CAAC,2BAA2B,cAAc,CAAC,KACzF,IAQF,CAAC;AAEF,eAAO,MAAM,iBAAiB;;eAMjB,0BAA0B;gBACzB,8BAA8B,CAAC,0BAA0B,CAAC;MACpE,IAMH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbortReason, FeatureId, UnifiedSwapBridgeEventName } from "@metamask/bridge-controller";
|
|
2
|
+
export const stopPollingForQuotes = (messenger, featureId, metricsContext) => {
|
|
3
|
+
messenger.call('BridgeController:stopPollingForQuotes', AbortReason.TransactionSubmitted,
|
|
4
|
+
// If trade is submitted before all quotes are loaded, the QuotesReceived event is published
|
|
5
|
+
// 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
|
|
6
|
+
featureId ? undefined : metricsContext);
|
|
7
|
+
};
|
|
8
|
+
export const trackMetricsEvent = ({ messenger, eventName, properties, }) => {
|
|
9
|
+
messenger.call('BridgeController:trackUnifiedSwapBridgeEvent', eventName, properties);
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=bridge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.mjs","sourceRoot":"","sources":["../../src/utils/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,SAAS,EACT,0BAA0B,EAC3B,oCAAoC;AAKrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,SAA0C,EAC1C,SAAqB,EACrB,cAA0F,EACpF,EAAE;IACR,SAAS,CAAC,IAAI,CACZ,uCAAuC,EACvC,WAAW,CAAC,oBAAoB;IAChC,4FAA4F;IAC5F,qJAAqJ;IACrJ,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CACvC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,GAKX,EAAQ,EAAE;IACT,SAAS,CAAC,IAAI,CACZ,8CAA8C,EAC9C,SAAS,EACT,UAAU,CACX,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n AbortReason,\n FeatureId,\n UnifiedSwapBridgeEventName,\n} from '@metamask/bridge-controller';\nimport type { RequiredEventContextFromClient } from '@metamask/bridge-controller';\n\nimport { BridgeStatusControllerMessenger } from '../types';\n\nexport const stopPollingForQuotes = (\n messenger: BridgeStatusControllerMessenger,\n featureId?: FeatureId,\n metricsContext?: RequiredEventContextFromClient[UnifiedSwapBridgeEventName.QuotesReceived],\n): void => {\n messenger.call(\n 'BridgeController:stopPollingForQuotes',\n AbortReason.TransactionSubmitted,\n // If trade is submitted before all quotes are loaded, the QuotesReceived event is published\n // 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\n featureId ? undefined : metricsContext,\n );\n};\n\nexport const trackMetricsEvent = ({\n messenger,\n eventName,\n properties,\n}: {\n messenger: BridgeStatusControllerMessenger;\n eventName: UnifiedSwapBridgeEventName;\n properties: RequiredEventContextFromClient[UnifiedSwapBridgeEventName];\n}): void => {\n messenger.call(\n 'BridgeController:trackUnifiedSwapBridgeEvent',\n eventName,\n properties,\n );\n};\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldPollHistoryItem = exports.getInitialHistoryItem = exports.getHistoryKey = exports.rekeyHistoryItemInState = void 0;
|
|
4
|
+
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
5
|
+
const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
6
|
+
const historyItem = state.txHistory[actionId];
|
|
7
|
+
if (!historyItem) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
state.txHistory[txMeta.id] = {
|
|
11
|
+
...historyItem,
|
|
12
|
+
txMetaId: txMeta.id,
|
|
13
|
+
originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
|
|
14
|
+
status: {
|
|
15
|
+
...historyItem.status,
|
|
16
|
+
srcChain: {
|
|
17
|
+
...historyItem.status.srcChain,
|
|
18
|
+
txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
delete state.txHistory[actionId];
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
exports.rekeyHistoryItemInState = rekeyHistoryItemInState;
|
|
26
|
+
/**
|
|
27
|
+
* Determines the key to use for storing a bridge history item.
|
|
28
|
+
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
29
|
+
*
|
|
30
|
+
* @param actionId - The action ID used for pre-submission tracking
|
|
31
|
+
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
32
|
+
* @returns The key to use for the history item
|
|
33
|
+
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
34
|
+
*/
|
|
35
|
+
function getHistoryKey(actionId, bridgeTxMetaId) {
|
|
36
|
+
const historyKey = actionId ?? bridgeTxMetaId;
|
|
37
|
+
if (!historyKey) {
|
|
38
|
+
throw new Error('Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided');
|
|
39
|
+
}
|
|
40
|
+
return historyKey;
|
|
41
|
+
}
|
|
42
|
+
exports.getHistoryKey = getHistoryKey;
|
|
43
|
+
const getInitialHistoryItem = ({ bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, statusRequest, activeAbTests, accountAddress: selectedAddress, }, actionId) => {
|
|
44
|
+
// Determine the key for this history item:
|
|
45
|
+
// - For pre-submission (non-batch EVM): use actionId
|
|
46
|
+
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
47
|
+
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id);
|
|
48
|
+
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
49
|
+
// We know it's in progress but not the exact status yet
|
|
50
|
+
const txHistoryItem = {
|
|
51
|
+
txMetaId: bridgeTxMeta?.id,
|
|
52
|
+
actionId,
|
|
53
|
+
originalTransactionId: bridgeTxMeta
|
|
54
|
+
?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions
|
|
55
|
+
batchId: bridgeTxMeta?.batchId,
|
|
56
|
+
quote: quoteResponse.quote,
|
|
57
|
+
startTime,
|
|
58
|
+
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
59
|
+
slippagePercentage,
|
|
60
|
+
pricingData: {
|
|
61
|
+
amountSent: quoteResponse.sentAmount?.amount ?? '0',
|
|
62
|
+
amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
|
|
63
|
+
quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
|
|
64
|
+
quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
|
|
65
|
+
quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
|
|
66
|
+
},
|
|
67
|
+
initialDestAssetBalance,
|
|
68
|
+
targetContractAddress,
|
|
69
|
+
account: selectedAddress,
|
|
70
|
+
status: {
|
|
71
|
+
// We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
|
|
72
|
+
// Also we know the bare minimum fields for status at this point in time
|
|
73
|
+
status: bridge_controller_1.StatusTypes.PENDING,
|
|
74
|
+
srcChain: {
|
|
75
|
+
chainId: quoteResponse.quote.srcChainId,
|
|
76
|
+
txHash: statusRequest?.srcTxHash ?? bridgeTxMeta?.hash,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
80
|
+
approvalTxId,
|
|
81
|
+
isStxEnabled: Boolean(isStxEnabled),
|
|
82
|
+
featureId: quoteResponse.featureId,
|
|
83
|
+
location,
|
|
84
|
+
...(abTests && { abTests }),
|
|
85
|
+
...(activeAbTests && { activeAbTests }),
|
|
86
|
+
};
|
|
87
|
+
return { historyKey, txHistoryItem };
|
|
88
|
+
};
|
|
89
|
+
exports.getInitialHistoryItem = getInitialHistoryItem;
|
|
90
|
+
const shouldPollHistoryItem = (historyItem) => {
|
|
91
|
+
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
92
|
+
const isBridgeTx = (0, bridge_controller_1.isCrossChain)(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
93
|
+
const isTronTx = (0, bridge_controller_1.isTronChainId)(historyItem.quote.srcChainId);
|
|
94
|
+
return [isBridgeTx, isIntent, isTronTx].some(Boolean);
|
|
95
|
+
};
|
|
96
|
+
exports.shouldPollHistoryItem = shouldPollHistoryItem;
|
|
97
|
+
//# sourceMappingURL=history.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.cjs","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":";;;AAAA,mEAIqC;AAQ9B,MAAM,uBAAuB,GAAG,CACrC,KAAkC,EAClC,QAAgB,EAChB,MAAqC,EAC5B,EAAE;IACX,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG;QAC3B,GAAG,WAAW;QACd,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,qBAAqB,EAAE,WAAW,CAAC,qBAAqB,IAAI,MAAM,CAAC,EAAE;QACrE,MAAM,EAAE;YACN,GAAG,WAAW,CAAC,MAAM;YACrB,QAAQ,EAAE;gBACR,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ;gBAC9B,MAAM,EAAE,MAAM,CAAC,IAAI,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM;aAC3D;SACF;KACF,CAAC;IACF,OAAO,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC;AAC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AAA,qBAAqB,yBAWhC","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isTronChainId,\n} from '@metamask/bridge-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n statusRequest,\n activeAbTests,\n accountAddress: selectedAddress,\n }: StartPollingForBridgeTxStatusArgsSerialized,\n actionId?: string,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id);\n\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId:\n (bridgeTxMeta as unknown as { originalTransactionId: string })\n ?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: quoteResponse.quote.srcChainId,\n txHash: statusRequest?.srcTxHash ?? bridgeTxMeta?.hash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BridgeHistoryItem, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.cjs";
|
|
2
|
+
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, actionId: string, txMeta: {
|
|
3
|
+
id: string;
|
|
4
|
+
hash?: string;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Determines the key to use for storing a bridge history item.
|
|
8
|
+
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
9
|
+
*
|
|
10
|
+
* @param actionId - The action ID used for pre-submission tracking
|
|
11
|
+
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
12
|
+
* @returns The key to use for the history item
|
|
13
|
+
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
14
|
+
*/
|
|
15
|
+
export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined): string;
|
|
16
|
+
export declare const getInitialHistoryItem: ({ bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, statusRequest, activeAbTests, accountAddress: selectedAddress, }: StartPollingForBridgeTxStatusArgsSerialized, actionId?: string) => {
|
|
17
|
+
historyKey: string;
|
|
18
|
+
txHistoryItem: BridgeHistoryItem;
|
|
19
|
+
};
|
|
20
|
+
export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
21
|
+
//# sourceMappingURL=history.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.cts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAElB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,kOAe7B,2CAA2C,aACnC,MAAM;gBAEL,MAAM;mBACH,iBAAiB;CAkDjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BridgeHistoryItem, BridgeStatusControllerState, StartPollingForBridgeTxStatusArgsSerialized } from "../types.mjs";
|
|
2
|
+
export declare const rekeyHistoryItemInState: (state: BridgeStatusControllerState, actionId: string, txMeta: {
|
|
3
|
+
id: string;
|
|
4
|
+
hash?: string;
|
|
5
|
+
}) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Determines the key to use for storing a bridge history item.
|
|
8
|
+
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
9
|
+
*
|
|
10
|
+
* @param actionId - The action ID used for pre-submission tracking
|
|
11
|
+
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
12
|
+
* @returns The key to use for the history item
|
|
13
|
+
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
14
|
+
*/
|
|
15
|
+
export declare function getHistoryKey(actionId: string | undefined, bridgeTxMetaId: string | undefined): string;
|
|
16
|
+
export declare const getInitialHistoryItem: ({ bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, statusRequest, activeAbTests, accountAddress: selectedAddress, }: StartPollingForBridgeTxStatusArgsSerialized, actionId?: string) => {
|
|
17
|
+
historyKey: string;
|
|
18
|
+
txHistoryItem: BridgeHistoryItem;
|
|
19
|
+
};
|
|
20
|
+
export declare const shouldPollHistoryItem: (historyItem: BridgeHistoryItem) => boolean;
|
|
21
|
+
//# sourceMappingURL=history.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.mts","sourceRoot":"","sources":["../../src/utils/history.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,2BAA2B,EAC3B,2CAA2C,EAC5C,qBAAiB;AAElB,eAAO,MAAM,uBAAuB,UAC3B,2BAA2B,YACxB,MAAM,UACR;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KACpC,OAoBF,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,MAAM,CAQR;AAED,eAAO,MAAM,qBAAqB,kOAe7B,2CAA2C,aACnC,MAAM;gBAEL,MAAM;mBACH,iBAAiB;CAkDjC,CAAC;AAEF,eAAO,MAAM,qBAAqB,gBACnB,iBAAiB,KAC7B,OASF,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { StatusTypes, isCrossChain, isTronChainId } from "@metamask/bridge-controller";
|
|
2
|
+
export const rekeyHistoryItemInState = (state, actionId, txMeta) => {
|
|
3
|
+
const historyItem = state.txHistory[actionId];
|
|
4
|
+
if (!historyItem) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
state.txHistory[txMeta.id] = {
|
|
8
|
+
...historyItem,
|
|
9
|
+
txMetaId: txMeta.id,
|
|
10
|
+
originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,
|
|
11
|
+
status: {
|
|
12
|
+
...historyItem.status,
|
|
13
|
+
srcChain: {
|
|
14
|
+
...historyItem.status.srcChain,
|
|
15
|
+
txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
delete state.txHistory[actionId];
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Determines the key to use for storing a bridge history item.
|
|
24
|
+
* Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.
|
|
25
|
+
*
|
|
26
|
+
* @param actionId - The action ID used for pre-submission tracking
|
|
27
|
+
* @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta
|
|
28
|
+
* @returns The key to use for the history item
|
|
29
|
+
* @throws Error if neither actionId nor bridgeTxMetaId is provided
|
|
30
|
+
*/
|
|
31
|
+
export function getHistoryKey(actionId, bridgeTxMetaId) {
|
|
32
|
+
const historyKey = actionId ?? bridgeTxMetaId;
|
|
33
|
+
if (!historyKey) {
|
|
34
|
+
throw new Error('Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided');
|
|
35
|
+
}
|
|
36
|
+
return historyKey;
|
|
37
|
+
}
|
|
38
|
+
export const getInitialHistoryItem = ({ bridgeTxMeta, quoteResponse, startTime, slippagePercentage, initialDestAssetBalance, targetContractAddress, approvalTxId, isStxEnabled, location, abTests, statusRequest, activeAbTests, accountAddress: selectedAddress, }, actionId) => {
|
|
39
|
+
// Determine the key for this history item:
|
|
40
|
+
// - For pre-submission (non-batch EVM): use actionId
|
|
41
|
+
// - For post-submission or other cases: use bridgeTxMeta.id
|
|
42
|
+
const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id);
|
|
43
|
+
// Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API
|
|
44
|
+
// We know it's in progress but not the exact status yet
|
|
45
|
+
const txHistoryItem = {
|
|
46
|
+
txMetaId: bridgeTxMeta?.id,
|
|
47
|
+
actionId,
|
|
48
|
+
originalTransactionId: bridgeTxMeta
|
|
49
|
+
?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions
|
|
50
|
+
batchId: bridgeTxMeta?.batchId,
|
|
51
|
+
quote: quoteResponse.quote,
|
|
52
|
+
startTime,
|
|
53
|
+
estimatedProcessingTimeInSeconds: quoteResponse.estimatedProcessingTimeInSeconds,
|
|
54
|
+
slippagePercentage,
|
|
55
|
+
pricingData: {
|
|
56
|
+
amountSent: quoteResponse.sentAmount?.amount ?? '0',
|
|
57
|
+
amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,
|
|
58
|
+
quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,
|
|
59
|
+
quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,
|
|
60
|
+
quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,
|
|
61
|
+
},
|
|
62
|
+
initialDestAssetBalance,
|
|
63
|
+
targetContractAddress,
|
|
64
|
+
account: selectedAddress,
|
|
65
|
+
status: {
|
|
66
|
+
// We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that
|
|
67
|
+
// Also we know the bare minimum fields for status at this point in time
|
|
68
|
+
status: StatusTypes.PENDING,
|
|
69
|
+
srcChain: {
|
|
70
|
+
chainId: quoteResponse.quote.srcChainId,
|
|
71
|
+
txHash: statusRequest?.srcTxHash ?? bridgeTxMeta?.hash,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
hasApprovalTx: Boolean(quoteResponse.approval),
|
|
75
|
+
approvalTxId,
|
|
76
|
+
isStxEnabled: Boolean(isStxEnabled),
|
|
77
|
+
featureId: quoteResponse.featureId,
|
|
78
|
+
location,
|
|
79
|
+
...(abTests && { abTests }),
|
|
80
|
+
...(activeAbTests && { activeAbTests }),
|
|
81
|
+
};
|
|
82
|
+
return { historyKey, txHistoryItem };
|
|
83
|
+
};
|
|
84
|
+
export const shouldPollHistoryItem = (historyItem) => {
|
|
85
|
+
const isIntent = Boolean(historyItem?.quote?.intent);
|
|
86
|
+
const isBridgeTx = isCrossChain(historyItem.quote.srcChainId, historyItem.quote.destChainId);
|
|
87
|
+
const isTronTx = isTronChainId(historyItem.quote.srcChainId);
|
|
88
|
+
return [isBridgeTx, isIntent, isTronTx].some(Boolean);
|
|
89
|
+
};
|
|
90
|
+
//# sourceM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AE,IAAI;aACvD;SACF;QACD,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC;QAC9C,YAAY;QACZ,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC;QACnC,SAAS,EAAE,aAAa,CAAC,SAAS;QAClC,QAAQ;QACR,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;QAC3B,GAAG,CAAC,aAAa,IAAI,EAAE,aAAa,EAAE,CAAC;KACxC,CAAC;IAEF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,WAA8B,EACrB,EAAE;IACX,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,UAAU,GAAG,YAAY,CAC7B,WAAW,CAAC,KAAK,CAAC,UAAU,EAC5B,WAAW,CAAC,KAAK,CAAC,WAAW,CAC9B,CAAC;IACF,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE7D,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC,CAAC","sourcesContent":["import {\n StatusTypes,\n isCrossChain,\n isTronChainId,\n} from '@metamask/bridge-controller';\n\nimport type {\n BridgeHistoryItem,\n BridgeStatusControllerState,\n StartPollingForBridgeTxStatusArgsSerialized,\n} from '../types';\n\nexport const rekeyHistoryItemInState = (\n state: BridgeStatusControllerState,\n actionId: string,\n txMeta: { id: string; hash?: string },\n): boolean => {\n const historyItem = state.txHistory[actionId];\n if (!historyItem) {\n return false;\n }\n\n state.txHistory[txMeta.id] = {\n ...historyItem,\n txMetaId: txMeta.id,\n originalTransactionId: historyItem.originalTransactionId ?? txMeta.id,\n status: {\n ...historyItem.status,\n srcChain: {\n ...historyItem.status.srcChain,\n txHash: txMeta.hash ?? historyItem.status.srcChain?.txHash,\n },\n },\n };\n delete state.txHistory[actionId];\n return true;\n};\n\n/**\n * Determines the key to use for storing a bridge history item.\n * Uses actionId for pre-submission tracking, or bridgeTxMetaId for post-submission.\n *\n * @param actionId - The action ID used for pre-submission tracking\n * @param bridgeTxMetaId - The transaction meta ID from bridgeTxMeta\n * @returns The key to use for the history item\n * @throws Error if neither actionId nor bridgeTxMetaId is provided\n */\nexport function getHistoryKey(\n actionId: string | undefined,\n bridgeTxMetaId: string | undefined,\n): string {\n const historyKey = actionId ?? bridgeTxMetaId;\n if (!historyKey) {\n throw new Error(\n 'Cannot add tx to history: either actionId or bridgeTxMeta.id must be provided',\n );\n }\n return historyKey;\n}\n\nexport const getInitialHistoryItem = (\n {\n bridgeTxMeta,\n quoteResponse,\n startTime,\n slippagePercentage,\n initialDestAssetBalance,\n targetContractAddress,\n approvalTxId,\n isStxEnabled,\n location,\n abTests,\n statusRequest,\n activeAbTests,\n accountAddress: selectedAddress,\n }: StartPollingForBridgeTxStatusArgsSerialized,\n actionId?: string,\n): {\n historyKey: string;\n txHistoryItem: BridgeHistoryItem;\n} => {\n // Determine the key for this history item:\n // - For pre-submission (non-batch EVM): use actionId\n // - For post-submission or other cases: use bridgeTxMeta.id\n const historyKey = getHistoryKey(actionId, bridgeTxMeta?.id);\n\n // Write all non-status fields to state so we can reference the quote in Activity list without the Bridge API\n // We know it's in progress but not the exact status yet\n const txHistoryItem = {\n txMetaId: bridgeTxMeta?.id,\n actionId,\n originalTransactionId:\n (bridgeTxMeta as unknown as { originalTransactionId: string })\n ?.originalTransactionId || bridgeTxMeta?.id, // Keep original for intent transactions\n batchId: bridgeTxMeta?.batchId,\n quote: quoteResponse.quote,\n startTime,\n estimatedProcessingTimeInSeconds:\n quoteResponse.estimatedProcessingTimeInSeconds,\n slippagePercentage,\n pricingData: {\n amountSent: quoteResponse.sentAmount?.amount ?? '0',\n amountSentInUsd: quoteResponse.sentAmount?.usd ?? undefined,\n quotedGasInUsd: quoteResponse.gasFee?.effective?.usd ?? undefined,\n quotedReturnInUsd: quoteResponse.toTokenAmount?.usd ?? undefined,\n quotedGasAmount: quoteResponse.gasFee?.effective?.amount ?? undefined,\n },\n initialDestAssetBalance,\n targetContractAddress,\n account: selectedAddress,\n status: {\n // We always have a PENDING status when we start polling for a tx, don't need the Bridge API for that\n // Also we know the bare minimum fields for status at this point in time\n status: StatusTypes.PENDING,\n srcChain: {\n chainId: quoteResponse.quote.srcChainId,\n txHash: statusRequest?.srcTxHash ?? bridgeTxMeta?.hash,\n },\n },\n hasApprovalTx: Boolean(quoteResponse.approval),\n approvalTxId,\n isStxEnabled: Boolean(isStxEnabled),\n featureId: quoteResponse.featureId,\n location,\n ...(abTests && { abTests }),\n ...(activeAbTests && { activeAbTests }),\n };\n\n return { historyKey, txHistoryItem };\n};\n\nexport const shouldPollHistoryItem = (\n historyItem: BridgeHistoryItem,\n): boolean => {\n const isIntent = Boolean(historyItem?.quote?.intent);\n const isBridgeTx = isCrossChain(\n historyItem.quote.srcChainId,\n historyItem.quote.destChainId,\n );\n const isTronTx = isTronChainId(historyItem.quote.srcChainId);\n\n return [isBridgeTx, isIntent, isTronTx].some(Boolean);\n};\n"]}
|
|
@@ -12,7 +12,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _IntentApiImpl_baseUrl, _IntentApiImpl_fetchFn, _IntentApiImpl_getJwt;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.mapIntentOrderStatusToTransactionStatus = exports.translateIntentOrderToBridgeStatus = exports.IntentApiImpl = void 0;
|
|
15
|
+
exports.getIntentFromQuote = exports.mapIntentOrderStatusToTransactionStatus = exports.translateIntentOrderToBridgeStatus = exports.IntentApiImpl = void 0;
|
|
16
16
|
const bridge_controller_1 = require("@metamask/bridge-controller");
|
|
17
17
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
18
18
|
const validators_1 = require("./validators.cjs");
|
|
@@ -125,4 +125,19 @@ function mapIntentOrderStatusToTransactionStatus(intentStatus) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
exports.mapIntentOrderStatusToTransactionStatus = mapIntentOrderStatusToTransactionStatus;
|
|
128
|
+
/**
|
|
129
|
+
* Extracts and validates the intent data from a quote response.
|
|
130
|
+
*
|
|
131
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
132
|
+
* @returns The intent data from the quote
|
|
133
|
+
* @throws Error if the quote does not contain intent data
|
|
134
|
+
*/
|
|
135
|
+
function getIntentFromQuote(quoteResponse) {
|
|
136
|
+
const { intent } = quoteResponse.quote;
|
|
137
|
+
if (!intent) {
|
|
138
|
+
throw new Error('submitIntent: missing intent data');
|
|
139
|
+
}
|
|
140
|
+
return intent;
|
|
141
|
+
}
|
|
142
|
+
exports.getIntentFromQuote = getIntentFromQuote;
|
|
128
143
|
//# sourceMappingURL=intent-api.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.cjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"intent-api.cjs","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mEAOqC;AACrC,6EAAqE;AAErE,iDAIsB;AA2BtB,MAAa,aAAa;IAOxB,YAAY,OAAe,EAAE,OAAsB,EAAE,MAAgB;QAN5D,yCAAiB;QAEjB,yCAAwB;QAExB,wCAAkB;QAGzB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,0BAAY,OAAO,MAAA,CAAC;QACxB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,MAA8B,EAC9B,QAAwB;QAExB,MAAM,QAAQ,GAAG,GAAG,u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,IAAI,cAAc,IAAI,EAAE,CAAC;IAC1D,MAAM,MAAM,GAAmB;QAC7B,MAAM,EAAE,UAAU;QAClB,QAAQ,EAAE;YACR,OAAO,EAAE,UAAU;YACnB,MAAM;SACP;KACF,CAAC;IAEF,OAAO;QACL,MAAM;QACN,MAAM;QACN,iBAAiB,EAAE,uCAAuC,CACxD,WAAW,CAAC,MAAM,CACnB;KACF,CAAC;AACJ,CAAC,CAAC;AA1CW,QAAA,kCAAkC,sCA0C7C;AAEF,SAAgB,uCAAuC,CACrD,YAA+B;IAE/B,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,8BAAiB,CAAC,OAAO,CAAC;QAC/B,KAAK,8BAAiB,CAAC,SAAS;YAC9B,OAAO,0CAAiB,CAAC,SAAS,CAAC;QACrC,KAAK,8BAAiB,CAAC,SAAS,CAAC;QACjC,KAAK,8BAAiB,CAAC,SAAS;YAC9B,OAAO,0CAAiB,CAAC,SAAS,CAAC;QACrC,KAAK,8BAAiB,CAAC,MAAM,CAAC;QAC9B,KAAK,8BAAiB,CAAC,OAAO,CAAC;QAC/B,KAAK,8BAAiB,CAAC,SAAS;YAC9B,OAAO,0CAAiB,CAAC,MAAM,CAAC;QAClC;YACE,OAAO,0CAAiB,CAAC,SAAS,CAAC;IACvC,CAAC;AACH,CAAC;AAjBD,0FAiBC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,aAA4B;IAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC;IACvC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAND,gDAMC","sourcesContent":["import {\n BridgeClientId,\n ChainId,\n getClientHeaders,\n Intent,\n QuoteResponse,\n StatusTypes,\n} from '@metamask/bridge-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\n\nimport {\n IntentStatusResponse,\n IntentOrderStatus,\n validateIntentStatusResponse,\n} from './validators';\nimport type { FetchFunction, StatusResponse } from '../types';\n\nexport type IntentSubmissionParams = {\n srcChainId: ChainId;\n quoteId: string;\n signature: string;\n order: unknown;\n userAddress: string;\n aggregatorId: string;\n};\n\nexport type IntentApi = {\n submitIntent(\n params: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse>;\n};\n\nexport type GetJwtFn = () => Promise<string | undefined>;\n\nexport class IntentApiImpl implements IntentApi {\n readonly #baseUrl: string;\n\n readonly #fetchFn: FetchFunction;\n\n readonly #getJwt: GetJwtFn;\n\n constructor(baseUrl: string, fetchFn: FetchFunction, getJwt: GetJwtFn) {\n this.#baseUrl = baseUrl;\n this.#fetchFn = fetchFn;\n this.#getJwt = getJwt;\n }\n\n async submitIntent(\n params: IntentSubmissionParams,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/submitOrder`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...getClientHeaders({ clientId, jwt }),\n },\n body: JSON.stringify(params),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid submitOrder response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to submit intent: ${error.message}`);\n }\n throw new Error('Failed to submit intent');\n }\n }\n\n async getOrderStatus(\n orderId: string,\n aggregatorId: string,\n srcChainId: ChainId,\n clientId: BridgeClientId,\n ): Promise<IntentStatusResponse> {\n const endpoint = `${this.#baseUrl}/getOrderStatus?orderId=${orderId}&aggregatorId=${encodeURIComponent(aggregatorId)}&srcChainId=${srcChainId}`;\n try {\n const jwt = await this.#getJwt();\n const response = await this.#fetchFn(endpoint, {\n method: 'GET',\n headers: getClientHeaders({ clientId, jwt }),\n });\n if (!validateIntentStatusResponse(response)) {\n throw new Error('Invalid getOrderStatus response');\n }\n return response;\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Failed to get order status: ${error.message}`);\n }\n throw new Error('Failed to get order status');\n }\n }\n}\n\nexport type IntentBridgeStatus = {\n status: StatusResponse;\n txHash?: string;\n transactionStatus: TransactionStatus;\n};\n\nexport const translateIntentOrderToBridgeStatus = (\n intentOrder: IntentStatusResponse,\n srcChainId: number,\n fallbackTxHash?: string,\n): IntentBridgeStatus => {\n let statusType: StatusTypes;\n switch (intentOrder.status) {\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n statusType = StatusTypes.COMPLETE;\n break;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n statusType = StatusTypes.FAILED;\n break;\n case IntentOrderStatus.PENDING:\n statusType = StatusTypes.PENDING;\n break;\n case IntentOrderStatus.SUBMITTED:\n statusType = StatusTypes.SUBMITTED;\n break;\n default:\n statusType = StatusTypes.UNKNOWN;\n }\n\n const txHash = intentOrder.txHash ?? fallbackTxHash ?? '';\n const status: StatusResponse = {\n status: statusType,\n srcChain: {\n chainId: srcChainId,\n txHash,\n },\n };\n\n return {\n status,\n txHash,\n transactionStatus: mapIntentOrderStatusToTransactionStatus(\n intentOrder.status,\n ),\n };\n};\n\nexport function mapIntentOrderStatusToTransactionStatus(\n intentStatus: IntentOrderStatus,\n): TransactionStatus {\n switch (intentStatus) {\n case IntentOrderStatus.PENDING:\n case IntentOrderStatus.SUBMITTED:\n return TransactionStatus.submitted;\n case IntentOrderStatus.CONFIRMED:\n case IntentOrderStatus.COMPLETED:\n return TransactionStatus.confirmed;\n case IntentOrderStatus.FAILED:\n case IntentOrderStatus.EXPIRED:\n case IntentOrderStatus.CANCELLED:\n return TransactionStatus.failed;\n default:\n return TransactionStatus.submitted;\n }\n}\n\n/**\n * Extracts and validates the intent data from a quote response.\n *\n * @param quoteResponse - The quote response that may contain intent data\n * @returns The intent data from the quote\n * @throws Error if the quote does not contain intent data\n */\nexport function getIntentFromQuote(quoteResponse: QuoteResponse): Intent {\n const { intent } = quoteResponse.quote;\n if (!intent) {\n throw new Error('submitIntent: missing intent data');\n }\n return intent;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BridgeClientId, ChainId } from "@metamask/bridge-controller";
|
|
1
|
+
import { BridgeClientId, ChainId, Intent, QuoteResponse } from "@metamask/bridge-controller";
|
|
2
2
|
import { TransactionStatus } from "@metamask/transaction-controller";
|
|
3
3
|
import { IntentStatusResponse, IntentOrderStatus } from "./validators.cjs";
|
|
4
4
|
import type { FetchFunction, StatusResponse } from "../types.cjs";
|
|
@@ -28,4 +28,12 @@ export type IntentBridgeStatus = {
|
|
|
28
28
|
};
|
|
29
29
|
export declare const translateIntentOrderToBridgeStatus: (intentOrder: IntentStatusResponse, srcChainId: number, fallbackTxHash?: string) => IntentBridgeStatus;
|
|
30
30
|
export declare function mapIntentOrderStatusToTransactionStatus(intentStatus: IntentOrderStatus): TransactionStatus;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts and validates the intent data from a quote response.
|
|
33
|
+
*
|
|
34
|
+
* @param quoteResponse - The quote response that may contain intent data
|
|
35
|
+
* @returns The intent data from the quote
|
|
36
|
+
* @throws Error if the quote does not contain intent data
|
|
37
|
+
*/
|
|
38
|
+
export declare function getIntentFromQuote(quoteResponse: QuoteResponse): Intent;
|
|
31
39
|
//# sourceMappingURL=intent-api.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-api.d.cts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,OAAO,
|
|
1
|
+
{"version":3,"file":"intent-api.d.cts","sourceRoot":"","sources":["../../src/utils/intent-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc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