@metamask/connect-multichain 0.14.0 → 1.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 +35 -1
- package/README.md +19 -19
- package/dist/browser/es/connect-multichain.d.mts +23 -10
- package/dist/browser/es/connect-multichain.mjs +595 -475
- package/dist/browser/es/connect-multichain.mjs.map +1 -1
- package/dist/browser/es/metafile-esm.json +1 -1
- package/dist/browser/iife/connect-multichain.d.ts +23 -10
- package/dist/browser/iife/connect-multichain.js +626 -475
- package/dist/browser/iife/connect-multichain.js.map +1 -1
- package/dist/browser/iife/metafile-iife.json +1 -1
- package/dist/browser/umd/connect-multichain.d.ts +23 -10
- package/dist/browser/umd/connect-multichain.js +595 -475
- package/dist/browser/umd/connect-multichain.js.map +1 -1
- package/dist/browser/umd/metafile-cjs.json +1 -1
- package/dist/node/cjs/connect-multichain.d.ts +23 -10
- package/dist/node/cjs/connect-multichain.js +597 -473
- package/dist/node/cjs/connect-multichain.js.map +1 -1
- package/dist/node/cjs/metafile-cjs.json +1 -1
- package/dist/node/es/connect-multichain.d.mts +23 -10
- package/dist/node/es/connect-multichain.mjs +594 -472
- package/dist/node/es/connect-multichain.mjs.map +1 -1
- package/dist/node/es/metafile-esm.json +1 -1
- package/dist/react-native/es/connect-multichain.d.mts +23 -10
- package/dist/react-native/es/connect-multichain.mjs +593 -471
- package/dist/react-native/es/connect-multichain.mjs.map +1 -1
- package/dist/react-native/es/metafile-esm.json +1 -1
- package/dist/src/domain/multichain/api/constants.d.ts +1 -0
- package/dist/src/domain/multichain/api/constants.d.ts.map +1 -1
- package/dist/src/domain/multichain/api/constants.js +13 -0
- package/dist/src/domain/multichain/api/constants.js.map +1 -1
- package/dist/src/domain/multichain/index.d.ts +3 -3
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js +7 -3
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +15 -4
- package/dist/src/domain/multichain/types.d.ts.map +1 -1
- package/dist/src/domain/platform/index.d.ts.map +1 -1
- package/dist/src/domain/platform/index.js +27 -5
- package/dist/src/domain/platform/index.js.map +1 -1
- package/dist/src/domain/store/client.d.ts +3 -3
- package/dist/src/domain/store/client.d.ts.map +1 -1
- package/dist/src/domain/utils/index.d.ts +1 -0
- package/dist/src/domain/utils/index.d.ts.map +1 -1
- package/dist/src/domain/utils/index.js +5 -1
- package/dist/src/domain/utils/index.js.map +1 -1
- package/dist/src/multichain/index.d.ts +2 -3
- package/dist/src/multichain/index.d.ts.map +1 -1
- package/dist/src/multichain/index.js +248 -207
- package/dist/src/multichain/index.js.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.d.ts +15 -0
- package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
- package/dist/src/multichain/rpc/requestRouter.js +54 -10
- package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
- package/dist/src/multichain/transports/default/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/default/index.js +16 -10
- package/dist/src/multichain/transports/default/index.js.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts +2 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js +25 -17
- package/dist/src/multichain/transports/multichainApiClientWrapper/index.js.map +1 -1
- package/dist/src/multichain/transports/mwp/index.d.ts +3 -1
- package/dist/src/multichain/transports/mwp/index.d.ts.map +1 -1
- package/dist/src/multichain/transports/mwp/index.js +227 -170
- package/dist/src/multichain/transports/mwp/index.js.map +1 -1
- package/dist/src/store/index.d.ts +3 -3
- package/dist/src/store/index.d.ts.map +1 -1
- package/dist/src/store/index.js +8 -8
- package/dist/src/store/index.js.map +1 -1
- package/dist/src/ui/ModalFactory.d.ts.map +1 -1
- package/dist/src/ui/ModalFactory.js +5 -1
- package/dist/src/ui/ModalFactory.js.map +1 -1
- package/dist/src/ui/index.js +1 -1
- package/dist/src/ui/index.js.map +1 -1
- package/dist/src/ui/modals/web/install.d.ts.map +1 -1
- package/dist/src/ui/modals/web/install.js.map +1 -1
- package/dist/types/connect-multichain.d.ts +23 -10
- package/package.json +3 -3
|
@@ -18,7 +18,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
19
19
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20
20
|
};
|
|
21
|
-
var _MetaMaskConnectMultichain_instances, _MetaMaskConnectMultichain_provider, _MetaMaskConnectMultichain_providerTransportWrapper, _MetaMaskConnectMultichain_transport, _MetaMaskConnectMultichain_dappClient, _MetaMaskConnectMultichain_beforeUnloadListener, _MetaMaskConnectMultichain_transportType, _MetaMaskConnectMultichain_listener, _MetaMaskConnectMultichain_anonId, _MetaMaskConnectMultichain_sdkInfo, _MetaMaskConnectMultichain_setupAnalytics, _MetaMaskConnectMultichain_onTransportNotification, _MetaMaskConnectMultichain_getStoredTransport, _MetaMaskConnectMultichain_setupTransport, _MetaMaskConnectMultichain_buildConnectionMetadata, _MetaMaskConnectMultichain_init, _MetaMaskConnectMultichain_createDappClient, _MetaMaskConnectMultichain_setupMWP, _MetaMaskConnectMultichain_onBeforeUnload, _MetaMaskConnectMultichain_createBeforeUnloadListener, _MetaMaskConnectMultichain_renderInstallModalAsync, _MetaMaskConnectMultichain_showInstallModal, _MetaMaskConnectMultichain_headlessConnect, _MetaMaskConnectMultichain_setupDefaultTransport, _MetaMaskConnectMultichain_deeplinkConnect, _MetaMaskConnectMultichain_handleConnection, _MetaMaskConnectMultichain_getCaipSession, _MetaMaskConnectMultichain_openConnectDeeplinkIfNeeded;
|
|
21
|
+
var _MetaMaskConnectMultichain_instances, _MetaMaskConnectMultichain_provider, _MetaMaskConnectMultichain_providerTransportWrapper, _MetaMaskConnectMultichain_transport, _MetaMaskConnectMultichain_dappClient, _MetaMaskConnectMultichain_beforeUnloadListener, _MetaMaskConnectMultichain_transportType, _MetaMaskConnectMultichain_listener, _MetaMaskConnectMultichain_anonId, _MetaMaskConnectMultichain_transportOrThrow, _MetaMaskConnectMultichain_sdkInfo, _MetaMaskConnectMultichain_setupAnalytics, _MetaMaskConnectMultichain_onTransportNotification, _MetaMaskConnectMultichain_getStoredTransport, _MetaMaskConnectMultichain_setupTransport, _MetaMaskConnectMultichain_buildConnectionMetadata, _MetaMaskConnectMultichain_init, _MetaMaskConnectMultichain_createDappClient, _MetaMaskConnectMultichain_setupMWP, _MetaMaskConnectMultichain_onBeforeUnload, _MetaMaskConnectMultichain_createBeforeUnloadListener, _MetaMaskConnectMultichain_renderInstallModalAsync, _MetaMaskConnectMultichain_showInstallModal, _MetaMaskConnectMultichain_headlessConnect, _MetaMaskConnectMultichain_setupDefaultTransport, _MetaMaskConnectMultichain_deeplinkConnect, _MetaMaskConnectMultichain_handleConnection, _MetaMaskConnectMultichain_getCaipSession, _MetaMaskConnectMultichain_openConnectDeeplinkIfNeeded;
|
|
22
22
|
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
23
23
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
24
24
|
/* eslint-disable no-restricted-globals */
|
|
@@ -26,6 +26,7 @@ var _MetaMaskConnectMultichain_instances, _MetaMaskConnectMultichain_provider, _
|
|
|
26
26
|
/* eslint-disable no-async-promise-executor -- Async promise executor needed for complex flow */
|
|
27
27
|
import { analytics } from '@metamask/analytics';
|
|
28
28
|
import { getMultichainClient, } from '@metamask/multichain-api-client';
|
|
29
|
+
import { createDeferredPromise } from '@metamask/utils';
|
|
29
30
|
import { METAMASK_CONNECT_BASE_URL, METAMASK_DEEPLINK_BASE, MWP_RELAY_URL, } from '../config';
|
|
30
31
|
import { getVersion, TransportType, } from '../domain';
|
|
31
32
|
import { extractErrorDiagnostics, getBaseAnalyticsProperties, isRejectionError, } from './utils/analytics';
|
|
@@ -41,6 +42,68 @@ export { getInfuraRpcUrls } from '../domain/multichain/api/infura';
|
|
|
41
42
|
// ENFORCE NAMESPACE THAT CAN BE DISABLED
|
|
42
43
|
const logger = createLogger('metamask-sdk:core');
|
|
43
44
|
const SINGLETON_KEY = '__METAMASK_CONNECT_MULTICHAIN_SINGLETON__';
|
|
45
|
+
/**
|
|
46
|
+
* Applies analytics defaults while preserving explicitly disabled analytics.
|
|
47
|
+
*
|
|
48
|
+
* @param analyticsOptions - Partial analytics options supplied by the consumer.
|
|
49
|
+
* @returns Analytics options with defaults applied.
|
|
50
|
+
*/
|
|
51
|
+
function normalizeAnalyticsOptions(analyticsOptions) {
|
|
52
|
+
var _a;
|
|
53
|
+
return Object.assign(Object.assign({}, (analyticsOptions !== null && analyticsOptions !== void 0 ? analyticsOptions : {})), { enabled: (_a = analyticsOptions === null || analyticsOptions === void 0 ? void 0 : analyticsOptions.enabled) !== null && _a !== void 0 ? _a : true,
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
55
|
+
integrationType: (analyticsOptions === null || analyticsOptions === void 0 ? void 0 : analyticsOptions.integrationType) || 'direct' });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether dapp-side analytics are enabled for the SDK instance.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Current SDK options.
|
|
61
|
+
* @returns Whether analytics events should be collected and sent.
|
|
62
|
+
*/
|
|
63
|
+
function isAnalyticsEnabled(options) {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = options.analytics) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sets up analytics globals using only APIs available on existing singleton
|
|
69
|
+
* instances, including instances created by older bundled package copies.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Current SDK options.
|
|
72
|
+
* @param storage - Storage client for retrieving the anonymous ID.
|
|
73
|
+
* @param setAnonId - Optional callback for updating the current instance anon ID.
|
|
74
|
+
*/
|
|
75
|
+
function setupAnalyticsGlobals(options, storage, setAnonId) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
if (!isAnalyticsEnabled(options)) {
|
|
79
|
+
setAnonId === null || setAnonId === void 0 ? void 0 : setAnonId(undefined);
|
|
80
|
+
analytics.disable();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const platform = getPlatformType();
|
|
84
|
+
const isBrowser = platform === PlatformType.MetaMaskMobileWebview ||
|
|
85
|
+
platform === PlatformType.DesktopWeb ||
|
|
86
|
+
platform === PlatformType.MobileWeb;
|
|
87
|
+
const isReactNative = platform === PlatformType.ReactNative;
|
|
88
|
+
if (!isBrowser && !isReactNative) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const dappId = getDappId(options.dapp);
|
|
92
|
+
const anonId = yield storage.getAnonId();
|
|
93
|
+
setAnonId === null || setAnonId === void 0 ? void 0 : setAnonId(anonId);
|
|
94
|
+
const { integrationType } = (_a = options.analytics) !== null && _a !== void 0 ? _a : {
|
|
95
|
+
integrationType: '',
|
|
96
|
+
};
|
|
97
|
+
analytics.setGlobalProperty('mmconnect_versions', (_b = options.versions) !== null && _b !== void 0 ? _b : {});
|
|
98
|
+
analytics.setGlobalProperty('dapp_id', dappId);
|
|
99
|
+
analytics.setGlobalProperty('anon_id', anonId);
|
|
100
|
+
analytics.setGlobalProperty('platform', platform);
|
|
101
|
+
if (integrationType) {
|
|
102
|
+
analytics.setGlobalProperty('integration_types', [integrationType]);
|
|
103
|
+
}
|
|
104
|
+
analytics.enable();
|
|
105
|
+
});
|
|
106
|
+
}
|
|
44
107
|
export class MetaMaskConnectMultichain extends MultichainCore {
|
|
45
108
|
get status() {
|
|
46
109
|
return this._status;
|
|
@@ -55,12 +118,6 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
55
118
|
get provider() {
|
|
56
119
|
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_provider, "f");
|
|
57
120
|
}
|
|
58
|
-
get transport() {
|
|
59
|
-
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) {
|
|
60
|
-
throw new Error('Transport not initialized, establish connection first');
|
|
61
|
-
}
|
|
62
|
-
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
63
|
-
}
|
|
64
121
|
get dappClient() {
|
|
65
122
|
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_dappClient, "f")) {
|
|
66
123
|
throw new Error('DappClient not initialized, establish connection first');
|
|
@@ -74,17 +131,13 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
74
131
|
get storage() {
|
|
75
132
|
return this.options.storage;
|
|
76
133
|
}
|
|
134
|
+
get version() {
|
|
135
|
+
return getVersion();
|
|
136
|
+
}
|
|
77
137
|
constructor(options) {
|
|
78
|
-
var _a, _b, _c, _d, _e
|
|
138
|
+
var _a, _b, _c, _d, _e;
|
|
79
139
|
const withDappMetadata = setupDappMetadata(options);
|
|
80
|
-
|
|
81
|
-
const integrationType = ((_a = options.analytics) === null || _a === void 0 ? void 0 : _a.integrationType) || 'direct';
|
|
82
|
-
const allOptions = Object.assign(Object.assign({}, withDappMetadata), { ui: Object.assign(Object.assign({}, withDappMetadata.ui), { preferExtension: (_b = withDappMetadata.ui.preferExtension) !== null && _b !== void 0 ? _b : true, showInstallModal: (_c = withDappMetadata.ui.showInstallModal) !== null && _c !== void 0 ? _c : false, headless: (_d = withDappMetadata.ui.headless) !== null && _d !== void 0 ? _d : false }), analytics: Object.assign(Object.assign({}, ((_e = options.analytics) !== null && _e !== void 0 ? _e : {})), { integrationType }), versions: Object.assign({
|
|
83
|
-
// typeof guard needed: Metro (React Native) bundles TS source directly,
|
|
84
|
-
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
85
|
-
'connect-multichain': typeof __PACKAGE_VERSION__ === 'undefined'
|
|
86
|
-
? 'unknown'
|
|
87
|
-
: __PACKAGE_VERSION__ }, ((_f = options.versions) !== null && _f !== void 0 ? _f : {})) });
|
|
140
|
+
const allOptions = Object.assign(Object.assign({}, withDappMetadata), { ui: Object.assign(Object.assign({}, withDappMetadata.ui), { preferExtension: (_a = withDappMetadata.ui.preferExtension) !== null && _a !== void 0 ? _a : true, showInstallModal: (_b = withDappMetadata.ui.showInstallModal) !== null && _b !== void 0 ? _b : false, headless: (_c = withDappMetadata.ui.headless) !== null && _c !== void 0 ? _c : false }), analytics: normalizeAnalyticsOptions(options.analytics), versions: Object.assign({ 'connect-multichain': getVersion() }, ((_d = options.versions) !== null && _d !== void 0 ? _d : {})) });
|
|
88
141
|
super(allOptions);
|
|
89
142
|
_MetaMaskConnectMultichain_instances.add(this);
|
|
90
143
|
_MetaMaskConnectMultichain_provider.set(this, void 0);
|
|
@@ -96,8 +149,8 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
96
149
|
this._status = 'pending';
|
|
97
150
|
_MetaMaskConnectMultichain_listener.set(this, void 0);
|
|
98
151
|
_MetaMaskConnectMultichain_anonId.set(this, void 0);
|
|
99
|
-
_MetaMaskConnectMultichain_sdkInfo.set(this, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(
|
|
100
|
-
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_providerTransportWrapper, new MultichainApiClientWrapperTransport(this), "f");
|
|
152
|
+
_MetaMaskConnectMultichain_sdkInfo.set(this, `Sdk/Javascript SdkVersion/${getVersion()} Platform/${getPlatformType()} dApp/${(_e = this.options.dapp.url) !== null && _e !== void 0 ? _e : this.options.dapp.name} dAppTitle/${this.options.dapp.name}`);
|
|
153
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_providerTransportWrapper, new MultichainApiClientWrapperTransport(this, () => __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")), "f");
|
|
101
154
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_provider, getMultichainClient({
|
|
102
155
|
transport: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f"),
|
|
103
156
|
}), "f");
|
|
@@ -105,22 +158,28 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
105
158
|
// Creates a singleton instance of MetaMaskConnectMultichain.
|
|
106
159
|
// If the singleton already exists, it merges the incoming options with the
|
|
107
160
|
// existing singleton options for the following keys: `api.supportedNetworks`,
|
|
108
|
-
// `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
109
|
-
// that the value for `dapp` is not merged as it does not
|
|
110
|
-
// subsequent calls to `createMultichainClient` to have a
|
|
161
|
+
// `analytics`, `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
|
|
162
|
+
// `debug`. Take note that the value for `dapp` is not merged as it does not
|
|
163
|
+
// make sense for subsequent calls to `createMultichainClient` to have a
|
|
164
|
+
// different `dapp` value.
|
|
111
165
|
static create(options) {
|
|
112
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
var _a, _b;
|
|
114
167
|
const globalObject = getGlobalObject();
|
|
115
168
|
const existing = globalObject[SINGLETON_KEY];
|
|
116
169
|
if (existing) {
|
|
117
170
|
const instance = yield existing;
|
|
171
|
+
if (instance.version !== getVersion()) {
|
|
172
|
+
console.warn(`MetaMask Connect does not support using multiple versions of @metamask/connect-multichain. ` +
|
|
173
|
+
`Attempted to create a new instance with version ${getVersion()}, but an existing ${instance.version} singleton was already initialized. ` +
|
|
174
|
+
`Using the existing ${instance.version} singleton. This is NOT supported and may lead to unexpected behavior. ` +
|
|
175
|
+
`Please ensure there is only one version of @metamask/connect-multichain package resolved in your application.`);
|
|
176
|
+
}
|
|
118
177
|
instance.mergeOptions(options);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
178
|
+
if (instance instanceof MetaMaskConnectMultichain) {
|
|
179
|
+
yield __classPrivateFieldGet(instance, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupAnalytics).call(instance);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
yield setupAnalyticsGlobals(instance.options, instance.storage);
|
|
124
183
|
}
|
|
125
184
|
if (options.debug) {
|
|
126
185
|
enableDebug('metamask-sdk:*');
|
|
@@ -135,12 +194,12 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
135
194
|
}
|
|
136
195
|
yield __classPrivateFieldGet(instance, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_init).call(instance);
|
|
137
196
|
return instance;
|
|
138
|
-
}))()
|
|
139
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
140
|
-
instancePromise.catch((error) => {
|
|
197
|
+
}))().catch((error) => {
|
|
141
198
|
globalObject[SINGLETON_KEY] = undefined;
|
|
142
199
|
console.error('Error initializing MetaMaskConnectMultichain', error);
|
|
200
|
+
throw error;
|
|
143
201
|
});
|
|
202
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
144
203
|
return instancePromise;
|
|
145
204
|
});
|
|
146
205
|
}
|
|
@@ -168,13 +227,15 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
168
227
|
else {
|
|
169
228
|
transportType = TransportType.MWP;
|
|
170
229
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
230
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
231
|
+
try {
|
|
232
|
+
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
233
|
+
const dappConfiguredChains = Object.keys(this.options.api.supportedNetworks);
|
|
234
|
+
analytics.track('mmconnect_connection_initiated', Object.assign(Object.assign({}, baseProps), { transport_type: transportType, dapp_configured_chains: dappConfiguredChains, dapp_requested_chains: scopes }));
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
logger('Error tracking connection_initiated event', error);
|
|
238
|
+
}
|
|
178
239
|
}
|
|
179
240
|
const sessionData = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_getCaipSession).call(this);
|
|
180
241
|
const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(sessionData, scopes, caipAccountIds, sessionProperties);
|
|
@@ -192,9 +253,9 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
192
253
|
})
|
|
193
254
|
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
194
255
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") === TransportType.MWP) {
|
|
195
|
-
return this.storage.
|
|
256
|
+
return this.storage.setTransportType(TransportType.MWP);
|
|
196
257
|
}
|
|
197
|
-
return this.storage.
|
|
258
|
+
return this.storage.setTransportType(TransportType.Browser);
|
|
198
259
|
})), scopes, transportType);
|
|
199
260
|
}
|
|
200
261
|
// In MetaMask Mobile In App Browser, window.ethereum is available directly
|
|
@@ -232,11 +293,6 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
232
293
|
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_handleConnection).call(this, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_showInstallModal).call(this, shouldShowInstallModal, mergedScopes, mergedCaipAccountIds, nonEmptySessionProperties), scopes, transportType);
|
|
233
294
|
});
|
|
234
295
|
}
|
|
235
|
-
emit(event, args) {
|
|
236
|
-
var _a, _b;
|
|
237
|
-
(_b = (_a = this.options.transport) === null || _a === void 0 ? void 0 : _a.onNotification) === null || _b === void 0 ? void 0 : _b.call(_a, { method: event, params: args });
|
|
238
|
-
super.emit(event, args);
|
|
239
|
-
}
|
|
240
296
|
disconnect() {
|
|
241
297
|
return __awaiter(this, arguments, void 0, function* (scopes = []) {
|
|
242
298
|
var _a, _b, _c;
|
|
@@ -246,7 +302,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
246
302
|
: Object.keys(sessionData.sessionScopes).filter((scope) => !scopes.includes(scope));
|
|
247
303
|
yield ((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _a === void 0 ? void 0 : _a.disconnect(scopes));
|
|
248
304
|
if (remainingScopes.length === 0) {
|
|
249
|
-
yield this.storage.
|
|
305
|
+
yield this.storage.removeTransportType();
|
|
250
306
|
// We want to leave the DefaultTransport instance connected so that we can
|
|
251
307
|
// still listen for wallet_sessionChanged events.
|
|
252
308
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") !== TransportType.Browser) {
|
|
@@ -266,7 +322,8 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
266
322
|
invokeMethod(request) {
|
|
267
323
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
324
|
var _a;
|
|
269
|
-
const
|
|
325
|
+
const transport = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this);
|
|
326
|
+
const { options } = this;
|
|
270
327
|
const rpcClient = new RpcClient(options, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_sdkInfo, "f"));
|
|
271
328
|
const requestRouter = new RequestRouter(transport, rpcClient, options, (_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f")) !== null && _a !== void 0 ? _a : TransportType.UNKNOWN);
|
|
272
329
|
// TODO: need read only method support for solana
|
|
@@ -281,7 +338,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
281
338
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
282
339
|
if (shouldOpenDeeplink) {
|
|
283
340
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
const session = yield this.
|
|
341
|
+
const session = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).getActiveSession();
|
|
285
342
|
if (!session) {
|
|
286
343
|
throw new Error('No active session found');
|
|
287
344
|
}
|
|
@@ -309,7 +366,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
309
366
|
return;
|
|
310
367
|
}
|
|
311
368
|
// Otherwise, we need to fetch the current CAIP session from the wallet
|
|
312
|
-
const response = yield this.
|
|
369
|
+
const response = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f").request({
|
|
313
370
|
method: 'wallet_getSession',
|
|
314
371
|
});
|
|
315
372
|
// And then simulate a sessionChanged event with the current CAIP session data
|
|
@@ -317,31 +374,16 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
317
374
|
});
|
|
318
375
|
}
|
|
319
376
|
}
|
|
320
|
-
_MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_providerTransportWrapper = new WeakMap(), _MetaMaskConnectMultichain_transport = new WeakMap(), _MetaMaskConnectMultichain_dappClient = new WeakMap(), _MetaMaskConnectMultichain_beforeUnloadListener = new WeakMap(), _MetaMaskConnectMultichain_transportType = new WeakMap(), _MetaMaskConnectMultichain_listener = new WeakMap(), _MetaMaskConnectMultichain_anonId = new WeakMap(), _MetaMaskConnectMultichain_sdkInfo = new WeakMap(), _MetaMaskConnectMultichain_instances = new WeakSet(),
|
|
377
|
+
_MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_providerTransportWrapper = new WeakMap(), _MetaMaskConnectMultichain_transport = new WeakMap(), _MetaMaskConnectMultichain_dappClient = new WeakMap(), _MetaMaskConnectMultichain_beforeUnloadListener = new WeakMap(), _MetaMaskConnectMultichain_transportType = new WeakMap(), _MetaMaskConnectMultichain_listener = new WeakMap(), _MetaMaskConnectMultichain_anonId = new WeakMap(), _MetaMaskConnectMultichain_sdkInfo = new WeakMap(), _MetaMaskConnectMultichain_instances = new WeakSet(), _MetaMaskConnectMultichain_transportOrThrow = function _MetaMaskConnectMultichain_transportOrThrow() {
|
|
378
|
+
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) {
|
|
379
|
+
throw new Error('Transport not initialized, establish connection first');
|
|
380
|
+
}
|
|
381
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
382
|
+
}, _MetaMaskConnectMultichain_setupAnalytics = function _MetaMaskConnectMultichain_setupAnalytics() {
|
|
321
383
|
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
platform === PlatformType.DesktopWeb ||
|
|
326
|
-
platform === PlatformType.MobileWeb;
|
|
327
|
-
const isReactNative = platform === PlatformType.ReactNative;
|
|
328
|
-
if (!isBrowser && !isReactNative) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const dappId = getDappId(this.options.dapp);
|
|
332
|
-
const anonId = yield this.storage.getAnonId();
|
|
333
|
-
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_anonId, anonId, "f");
|
|
334
|
-
const { integrationType } = (_a = this.options.analytics) !== null && _a !== void 0 ? _a : {
|
|
335
|
-
integrationType: '',
|
|
336
|
-
};
|
|
337
|
-
analytics.setGlobalProperty('mmconnect_versions', (_b = this.options.versions) !== null && _b !== void 0 ? _b : {});
|
|
338
|
-
analytics.setGlobalProperty('dapp_id', dappId);
|
|
339
|
-
analytics.setGlobalProperty('anon_id', anonId);
|
|
340
|
-
analytics.setGlobalProperty('platform', platform);
|
|
341
|
-
if (integrationType) {
|
|
342
|
-
analytics.setGlobalProperty('integration_types', [integrationType]);
|
|
343
|
-
}
|
|
344
|
-
analytics.enable();
|
|
384
|
+
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
385
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_anonId, anonId, "f");
|
|
386
|
+
});
|
|
345
387
|
});
|
|
346
388
|
}, _MetaMaskConnectMultichain_onTransportNotification = function _MetaMaskConnectMultichain_onTransportNotification(payload) {
|
|
347
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -364,7 +406,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
364
406
|
});
|
|
365
407
|
}, _MetaMaskConnectMultichain_getStoredTransport = function _MetaMaskConnectMultichain_getStoredTransport() {
|
|
366
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
-
const transportType = yield this.storage.
|
|
409
|
+
const transportType = yield this.storage.getTransportType();
|
|
368
410
|
const hasExtensionInstalled = yield hasExtension();
|
|
369
411
|
if (transportType) {
|
|
370
412
|
if (transportType === TransportType.Browser) {
|
|
@@ -389,7 +431,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
389
431
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, apiTransport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
390
432
|
return apiTransport;
|
|
391
433
|
}
|
|
392
|
-
yield this.storage.
|
|
434
|
+
yield this.storage.removeTransportType();
|
|
393
435
|
}
|
|
394
436
|
return undefined;
|
|
395
437
|
});
|
|
@@ -398,16 +440,16 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
398
440
|
var _a;
|
|
399
441
|
const transport = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_getStoredTransport).call(this);
|
|
400
442
|
if (transport) {
|
|
401
|
-
if (!
|
|
443
|
+
if (!transport.isConnected()) {
|
|
402
444
|
this.status = 'connecting';
|
|
403
|
-
yield
|
|
445
|
+
yield transport.connect();
|
|
404
446
|
}
|
|
405
447
|
this.status = 'connected';
|
|
406
448
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") === TransportType.MWP) {
|
|
407
|
-
yield this.storage.
|
|
449
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
408
450
|
}
|
|
409
451
|
else {
|
|
410
|
-
yield this.storage.
|
|
452
|
+
yield this.storage.setTransportType(TransportType.Browser);
|
|
411
453
|
}
|
|
412
454
|
}
|
|
413
455
|
else {
|
|
@@ -421,7 +463,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
421
463
|
// and that wallet_sessionChanged (faked) is emitted. But because we are not
|
|
422
464
|
// calling transport.connect(), we need to initialize DefaultTransport manually.
|
|
423
465
|
try {
|
|
424
|
-
yield this.
|
|
466
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).init();
|
|
425
467
|
}
|
|
426
468
|
catch (error) {
|
|
427
469
|
console.error('Passive init failed:', error);
|
|
@@ -434,7 +476,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
434
476
|
dapp: this.options.dapp,
|
|
435
477
|
sdk: { version: getVersion(), platform: getPlatformType() },
|
|
436
478
|
};
|
|
437
|
-
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_anonId, "f")) {
|
|
479
|
+
if (isAnalyticsEnabled(this.options) && __classPrivateFieldGet(this, _MetaMaskConnectMultichain_anonId, "f")) {
|
|
438
480
|
metadata.analytics = { remote_session_id: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_anonId, "f") };
|
|
439
481
|
}
|
|
440
482
|
return metadata;
|
|
@@ -445,7 +487,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
445
487
|
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupTransport).call(this);
|
|
446
488
|
}
|
|
447
489
|
catch (error) {
|
|
448
|
-
yield this.storage.
|
|
490
|
+
yield this.storage.removeTransportType();
|
|
449
491
|
this.status = 'pending';
|
|
450
492
|
logger('MetaMaskSDK error during initialization', error);
|
|
451
493
|
}
|
|
@@ -490,15 +532,15 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
490
532
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, apiTransport, "f");
|
|
491
533
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transportType, TransportType.MWP, "f");
|
|
492
534
|
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupTransportNotificationListener();
|
|
493
|
-
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener,
|
|
494
|
-
yield this.storage.
|
|
535
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, apiTransport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
536
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
495
537
|
});
|
|
496
538
|
}, _MetaMaskConnectMultichain_onBeforeUnload = function _MetaMaskConnectMultichain_onBeforeUnload() {
|
|
497
539
|
return __awaiter(this, void 0, void 0, function* () {
|
|
498
540
|
var _a;
|
|
499
541
|
// Fixes glitch with "connecting" state when modal is still visible and we close screen or refresh
|
|
500
542
|
if ((_a = this.options.ui.factory.modal) === null || _a === void 0 ? void 0 : _a.isMounted) {
|
|
501
|
-
yield this.storage.
|
|
543
|
+
yield this.storage.removeTransportType();
|
|
502
544
|
}
|
|
503
545
|
});
|
|
504
546
|
}, _MetaMaskConnectMultichain_createBeforeUnloadListener = function _MetaMaskConnectMultichain_createBeforeUnloadListener() {
|
|
@@ -515,73 +557,70 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
515
557
|
};
|
|
516
558
|
}, _MetaMaskConnectMultichain_renderInstallModalAsync = function _MetaMaskConnectMultichain_renderInstallModalAsync(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
517
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
this.
|
|
521
|
-
.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
534
|
-
var _a;
|
|
535
|
-
try {
|
|
536
|
-
yield this.transport.connect({
|
|
537
|
-
scopes,
|
|
538
|
-
caipAccountIds,
|
|
539
|
-
sessionProperties,
|
|
540
|
-
});
|
|
541
|
-
yield this.options.ui.factory.unload();
|
|
542
|
-
(_a = this.options.ui.factory.modal) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
543
|
-
this.status = 'connected';
|
|
544
|
-
yield this.storage.setTransport(TransportType.MWP);
|
|
545
|
-
}
|
|
546
|
-
catch (error) {
|
|
547
|
-
const { ProtocolError, ErrorCode } = yield import('@metamask/mobile-wallet-protocol-core');
|
|
548
|
-
if (error instanceof ProtocolError) {
|
|
549
|
-
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
550
|
-
this.status = 'disconnected';
|
|
551
|
-
// Close the modal on error
|
|
552
|
-
yield this.options.ui.factory.unload(error);
|
|
553
|
-
reject(error);
|
|
554
|
-
}
|
|
555
|
-
// If request is expires, the QRCode will automatically be regenerated we can ignore this case
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
this.status = 'disconnected';
|
|
559
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
560
|
-
// Close the modal on error
|
|
561
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
562
|
-
reject(normalizedError);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}))().catch(() => {
|
|
566
|
-
// Error already handled in the async function
|
|
567
|
-
});
|
|
560
|
+
const completion = createDeferredPromise();
|
|
561
|
+
const createConnectionRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
562
|
+
if (this.dappClient.state === 'CONNECTED' ||
|
|
563
|
+
this.dappClient.state === 'CONNECTING') {
|
|
564
|
+
yield this.dappClient.disconnect();
|
|
565
|
+
}
|
|
566
|
+
// The session_request event carries the pending request needed to build
|
|
567
|
+
// the deeplink / QR code. We resolve this deferred when it fires.
|
|
568
|
+
const sessionRequestDeferred = createDeferredPromise();
|
|
569
|
+
this.dappClient.on('session_request', (sessionRequest) => {
|
|
570
|
+
sessionRequestDeferred.resolve({
|
|
571
|
+
sessionRequest,
|
|
572
|
+
metadata: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_buildConnectionMetadata).call(this),
|
|
568
573
|
});
|
|
569
|
-
})
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
574
|
+
});
|
|
575
|
+
// Start the connection flow in the background — it will eventually emit
|
|
576
|
+
// session_request (resolving sessionRequestDeferred) and then either
|
|
577
|
+
// succeed (handled by the successCallback below) or fail (rejecting
|
|
578
|
+
// the outer completion deferred).
|
|
579
|
+
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this)
|
|
580
|
+
.connect({ scopes, caipAccountIds, sessionProperties })
|
|
581
|
+
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
582
|
+
var _a;
|
|
583
|
+
yield this.options.ui.factory.unload();
|
|
584
|
+
(_a = this.options.ui.factory.modal) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
585
|
+
this.status = 'connected';
|
|
586
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
587
|
+
}))
|
|
588
|
+
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
589
|
+
const { ProtocolError, ErrorCode } = yield import('@metamask/mobile-wallet-protocol-core');
|
|
590
|
+
if (error instanceof ProtocolError) {
|
|
591
|
+
if (error.code !== ErrorCode.REQUEST_EXPIRED) {
|
|
592
|
+
this.status = 'disconnected';
|
|
593
|
+
yield this.options.ui.factory.unload(error);
|
|
594
|
+
completion.reject(error);
|
|
595
|
+
}
|
|
596
|
+
// If the request is expired the QR code is automatically regenerated — ignore this case
|
|
573
597
|
}
|
|
574
598
|
else {
|
|
575
|
-
|
|
576
|
-
|
|
599
|
+
this.status = 'disconnected';
|
|
600
|
+
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
601
|
+
yield this.options.ui.factory.unload(normalizedError);
|
|
602
|
+
completion.reject(normalizedError);
|
|
577
603
|
}
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
604
|
+
}));
|
|
605
|
+
return sessionRequestDeferred.promise;
|
|
606
|
+
});
|
|
607
|
+
this.options.ui.factory
|
|
608
|
+
.renderInstallModal(desktopPreferred, createConnectionRequest, (error) => __awaiter(this, void 0, void 0, function* () {
|
|
609
|
+
if (error) {
|
|
610
|
+
yield this.storage.removeTransportType();
|
|
611
|
+
completion.reject(error);
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
615
|
+
completion.resolve();
|
|
616
|
+
}
|
|
617
|
+
}), (uri) => {
|
|
618
|
+
this.emit('display_uri', uri);
|
|
619
|
+
})
|
|
620
|
+
.catch((error) => {
|
|
621
|
+
completion.reject(error instanceof Error ? error : new Error(String(error)));
|
|
584
622
|
});
|
|
623
|
+
return completion.promise;
|
|
585
624
|
});
|
|
586
625
|
}, _MetaMaskConnectMultichain_showInstallModal = function _MetaMaskConnectMultichain_showInstallModal(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
587
626
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -598,47 +637,45 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
598
637
|
});
|
|
599
638
|
}, _MetaMaskConnectMultichain_headlessConnect = function _MetaMaskConnectMultichain_headlessConnect(scopes, caipAccountIds, sessionProperties) {
|
|
600
639
|
return __awaiter(this, void 0, void 0, function* () {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
640
|
+
if (this.dappClient.state === 'CONNECTED' ||
|
|
641
|
+
this.dappClient.state === 'CONNECTING') {
|
|
642
|
+
yield this.dappClient.disconnect().catch(() => undefined);
|
|
643
|
+
}
|
|
644
|
+
// Listen for session_request to generate and emit the QR code link.
|
|
645
|
+
// Captured as a named ref so the listener can be removed when the
|
|
646
|
+
// connection settles — otherwise each #headlessConnect() call would leak
|
|
647
|
+
// a listener that re-emits `display_uri` for every future session_request.
|
|
648
|
+
const onSessionRequest = (sessionRequest) => {
|
|
649
|
+
const connectionRequest = {
|
|
650
|
+
sessionRequest,
|
|
651
|
+
metadata: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_buildConnectionMetadata).call(this),
|
|
652
|
+
};
|
|
653
|
+
const deeplink = this.options.ui.factory.createConnectionDeeplink(connectionRequest);
|
|
654
|
+
this.emit('display_uri', deeplink);
|
|
655
|
+
};
|
|
656
|
+
this.dappClient.on('session_request', onSessionRequest);
|
|
657
|
+
try {
|
|
658
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).connect({
|
|
659
|
+
scopes,
|
|
660
|
+
caipAccountIds,
|
|
661
|
+
sessionProperties,
|
|
617
662
|
});
|
|
618
|
-
|
|
619
|
-
this.
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
else {
|
|
636
|
-
this.status = 'disconnected';
|
|
637
|
-
yield this.storage.removeTransport();
|
|
638
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
639
|
-
}
|
|
640
|
-
}));
|
|
641
|
-
});
|
|
663
|
+
this.status = 'connected';
|
|
664
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
665
|
+
}
|
|
666
|
+
catch (error) {
|
|
667
|
+
const { ProtocolError } = yield import('@metamask/mobile-wallet-protocol-core');
|
|
668
|
+
this.status = 'disconnected';
|
|
669
|
+
yield this.storage.removeTransportType();
|
|
670
|
+
// In headless mode, we don't auto-regenerate QR codes since there's no modal to display them
|
|
671
|
+
if (error instanceof ProtocolError || error instanceof Error) {
|
|
672
|
+
throw error;
|
|
673
|
+
}
|
|
674
|
+
throw new Error(String(error));
|
|
675
|
+
}
|
|
676
|
+
finally {
|
|
677
|
+
this.dappClient.off('session_request', onSessionRequest);
|
|
678
|
+
}
|
|
642
679
|
});
|
|
643
680
|
}, _MetaMaskConnectMultichain_setupDefaultTransport = function _MetaMaskConnectMultichain_setupDefaultTransport() {
|
|
644
681
|
return __awaiter(this, arguments, void 0, function* (options = { persist: true }) {
|
|
@@ -646,7 +683,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
646
683
|
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
647
684
|
}
|
|
648
685
|
if (options === null || options === void 0 ? void 0 : options.persist) {
|
|
649
|
-
yield this.storage.
|
|
686
|
+
yield this.storage.setTransportType(TransportType.Browser);
|
|
650
687
|
}
|
|
651
688
|
const transport = new DefaultTransport();
|
|
652
689
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, transport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
@@ -682,7 +719,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
682
719
|
};
|
|
683
720
|
this.dappClient.on('message', dappClientMessageHandler);
|
|
684
721
|
let timeout;
|
|
685
|
-
if (this.
|
|
722
|
+
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).isConnected()) {
|
|
686
723
|
timeout = setTimeout(() => {
|
|
687
724
|
this.openSimpleDeeplinkIfNeeded();
|
|
688
725
|
}, 250);
|
|
@@ -706,11 +743,11 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
706
743
|
}
|
|
707
744
|
});
|
|
708
745
|
}
|
|
709
|
-
return this.
|
|
746
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this)
|
|
710
747
|
.connect({ scopes, caipAccountIds, sessionProperties })
|
|
711
748
|
.then(resolve)
|
|
712
749
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
713
|
-
yield this.storage.
|
|
750
|
+
yield this.storage.removeTransportType();
|
|
714
751
|
this.dappClient.off('message', dappClientMessageHandler);
|
|
715
752
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
716
753
|
}))
|
|
@@ -727,30 +764,34 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
727
764
|
return promise
|
|
728
765
|
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
729
766
|
this.status = 'connected';
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
767
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
768
|
+
try {
|
|
769
|
+
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
770
|
+
analytics.track('mmconnect_connection_established', Object.assign(Object.assign({}, baseProps), { transport_type: transportType, user_permissioned_chains: scopes }));
|
|
771
|
+
}
|
|
772
|
+
catch (error) {
|
|
773
|
+
logger('Error tracking connection_established event', error);
|
|
774
|
+
}
|
|
736
775
|
}
|
|
737
776
|
return undefined; // explicitly return `undefined` to avoid eslintpromise/always-return
|
|
738
777
|
}))
|
|
739
778
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
740
779
|
this.status = 'disconnected';
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
780
|
+
if (isAnalyticsEnabled(this.options)) {
|
|
781
|
+
try {
|
|
782
|
+
const baseProps = yield getBaseAnalyticsProperties(this.options, this.storage);
|
|
783
|
+
const isRejection = isRejectionError(error);
|
|
784
|
+
if (isRejection) {
|
|
785
|
+
analytics.track('mmconnect_connection_rejected', Object.assign(Object.assign({}, baseProps), { transport_type: transportType }));
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
analytics.track('mmconnect_connection_failed', Object.assign(Object.assign(Object.assign({}, baseProps), { transport_type: transportType }), extractErrorDiagnostics(error)));
|
|
789
|
+
}
|
|
746
790
|
}
|
|
747
|
-
|
|
748
|
-
|
|
791
|
+
catch (_a) {
|
|
792
|
+
logger('Error tracking connection failed/rejected event', error);
|
|
749
793
|
}
|
|
750
794
|
}
|
|
751
|
-
catch (_a) {
|
|
752
|
-
logger('Error tracking connection failed/rejected event', error);
|
|
753
|
-
}
|
|
754
795
|
throw error;
|
|
755
796
|
}));
|
|
756
797
|
});
|
|
@@ -763,7 +804,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
763
804
|
};
|
|
764
805
|
if ((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _a === void 0 ? void 0 : _a.isConnected()) {
|
|
765
806
|
try {
|
|
766
|
-
const response = yield this.
|
|
807
|
+
const response = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f").request({
|
|
767
808
|
method: 'wallet_getSession',
|
|
768
809
|
});
|
|
769
810
|
if (response.result) {
|