@metamask/connect-multichain 0.15.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 +28 -1
- package/README.md +0 -1
- package/dist/browser/es/connect-multichain.d.mts +7 -6
- package/dist/browser/es/connect-multichain.mjs +451 -368
- 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 +7 -6
- package/dist/browser/iife/connect-multichain.js +464 -368
- 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 +7 -6
- package/dist/browser/umd/connect-multichain.js +451 -368
- 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 +7 -6
- package/dist/node/cjs/connect-multichain.js +453 -366
- 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 +7 -6
- package/dist/node/es/connect-multichain.mjs +450 -365
- 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 +7 -6
- package/dist/react-native/es/connect-multichain.mjs +449 -364
- 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 +2 -2
- package/dist/src/domain/multichain/index.d.ts.map +1 -1
- package/dist/src/domain/multichain/index.js.map +1 -1
- package/dist/src/domain/multichain/types.d.ts +0 -1
- 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 +142 -147
- 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 +31 -5
- 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 +7 -6
- package/package.json +2 -2
|
@@ -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';
|
|
@@ -117,12 +118,6 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
117
118
|
get provider() {
|
|
118
119
|
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_provider, "f");
|
|
119
120
|
}
|
|
120
|
-
get transport() {
|
|
121
|
-
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) {
|
|
122
|
-
throw new Error('Transport not initialized, establish connection first');
|
|
123
|
-
}
|
|
124
|
-
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
125
|
-
}
|
|
126
121
|
get dappClient() {
|
|
127
122
|
if (!__classPrivateFieldGet(this, _MetaMaskConnectMultichain_dappClient, "f")) {
|
|
128
123
|
throw new Error('DappClient not initialized, establish connection first');
|
|
@@ -136,15 +131,13 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
136
131
|
get storage() {
|
|
137
132
|
return this.options.storage;
|
|
138
133
|
}
|
|
134
|
+
get version() {
|
|
135
|
+
return getVersion();
|
|
136
|
+
}
|
|
139
137
|
constructor(options) {
|
|
140
138
|
var _a, _b, _c, _d, _e;
|
|
141
139
|
const withDappMetadata = setupDappMetadata(options);
|
|
142
|
-
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({
|
|
143
|
-
// typeof guard needed: Metro (React Native) bundles TS source directly,
|
|
144
|
-
// bypassing the tsup build that substitutes __PACKAGE_VERSION__.
|
|
145
|
-
'connect-multichain': typeof __PACKAGE_VERSION__ === 'undefined'
|
|
146
|
-
? 'unknown'
|
|
147
|
-
: __PACKAGE_VERSION__ }, ((_d = options.versions) !== null && _d !== void 0 ? _d : {})) });
|
|
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 : {})) });
|
|
148
141
|
super(allOptions);
|
|
149
142
|
_MetaMaskConnectMultichain_instances.add(this);
|
|
150
143
|
_MetaMaskConnectMultichain_provider.set(this, void 0);
|
|
@@ -157,7 +150,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
157
150
|
_MetaMaskConnectMultichain_listener.set(this, void 0);
|
|
158
151
|
_MetaMaskConnectMultichain_anonId.set(this, void 0);
|
|
159
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}`);
|
|
160
|
-
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_providerTransportWrapper, new MultichainApiClientWrapperTransport(this), "f");
|
|
153
|
+
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_providerTransportWrapper, new MultichainApiClientWrapperTransport(this, () => __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")), "f");
|
|
161
154
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_provider, getMultichainClient({
|
|
162
155
|
transport: __classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f"),
|
|
163
156
|
}), "f");
|
|
@@ -175,6 +168,12 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
175
168
|
const existing = globalObject[SINGLETON_KEY];
|
|
176
169
|
if (existing) {
|
|
177
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
|
+
}
|
|
178
177
|
instance.mergeOptions(options);
|
|
179
178
|
if (instance instanceof MetaMaskConnectMultichain) {
|
|
180
179
|
yield __classPrivateFieldGet(instance, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupAnalytics).call(instance);
|
|
@@ -195,12 +194,12 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
195
194
|
}
|
|
196
195
|
yield __classPrivateFieldGet(instance, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_init).call(instance);
|
|
197
196
|
return instance;
|
|
198
|
-
}))()
|
|
199
|
-
globalObject[SINGLETON_KEY] = instancePromise;
|
|
200
|
-
instancePromise.catch((error) => {
|
|
197
|
+
}))().catch((error) => {
|
|
201
198
|
globalObject[SINGLETON_KEY] = undefined;
|
|
202
199
|
console.error('Error initializing MetaMaskConnectMultichain', error);
|
|
200
|
+
throw error;
|
|
203
201
|
});
|
|
202
|
+
globalObject[SINGLETON_KEY] = instancePromise;
|
|
204
203
|
return instancePromise;
|
|
205
204
|
});
|
|
206
205
|
}
|
|
@@ -254,9 +253,9 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
254
253
|
})
|
|
255
254
|
.then(() => __awaiter(this, void 0, void 0, function* () {
|
|
256
255
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") === TransportType.MWP) {
|
|
257
|
-
return this.storage.
|
|
256
|
+
return this.storage.setTransportType(TransportType.MWP);
|
|
258
257
|
}
|
|
259
|
-
return this.storage.
|
|
258
|
+
return this.storage.setTransportType(TransportType.Browser);
|
|
260
259
|
})), scopes, transportType);
|
|
261
260
|
}
|
|
262
261
|
// In MetaMask Mobile In App Browser, window.ethereum is available directly
|
|
@@ -294,11 +293,6 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
294
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);
|
|
295
294
|
});
|
|
296
295
|
}
|
|
297
|
-
emit(event, args) {
|
|
298
|
-
var _a, _b;
|
|
299
|
-
(_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 });
|
|
300
|
-
super.emit(event, args);
|
|
301
|
-
}
|
|
302
296
|
disconnect() {
|
|
303
297
|
return __awaiter(this, arguments, void 0, function* (scopes = []) {
|
|
304
298
|
var _a, _b, _c;
|
|
@@ -308,7 +302,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
308
302
|
: Object.keys(sessionData.sessionScopes).filter((scope) => !scopes.includes(scope));
|
|
309
303
|
yield ((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _a === void 0 ? void 0 : _a.disconnect(scopes));
|
|
310
304
|
if (remainingScopes.length === 0) {
|
|
311
|
-
yield this.storage.
|
|
305
|
+
yield this.storage.removeTransportType();
|
|
312
306
|
// We want to leave the DefaultTransport instance connected so that we can
|
|
313
307
|
// still listen for wallet_sessionChanged events.
|
|
314
308
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") !== TransportType.Browser) {
|
|
@@ -328,7 +322,8 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
328
322
|
invokeMethod(request) {
|
|
329
323
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
324
|
var _a;
|
|
331
|
-
const
|
|
325
|
+
const transport = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this);
|
|
326
|
+
const { options } = this;
|
|
332
327
|
const rpcClient = new RpcClient(options, __classPrivateFieldGet(this, _MetaMaskConnectMultichain_sdkInfo, "f"));
|
|
333
328
|
const requestRouter = new RequestRouter(transport, rpcClient, options, (_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f")) !== null && _a !== void 0 ? _a : TransportType.UNKNOWN);
|
|
334
329
|
// TODO: need read only method support for solana
|
|
@@ -343,7 +338,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
343
338
|
const shouldOpenDeeplink = secure && !showInstallModal;
|
|
344
339
|
if (shouldOpenDeeplink) {
|
|
345
340
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
346
|
-
const session = yield this.
|
|
341
|
+
const session = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).getActiveSession();
|
|
347
342
|
if (!session) {
|
|
348
343
|
throw new Error('No active session found');
|
|
349
344
|
}
|
|
@@ -371,7 +366,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
371
366
|
return;
|
|
372
367
|
}
|
|
373
368
|
// Otherwise, we need to fetch the current CAIP session from the wallet
|
|
374
|
-
const response = yield this.
|
|
369
|
+
const response = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f").request({
|
|
375
370
|
method: 'wallet_getSession',
|
|
376
371
|
});
|
|
377
372
|
// And then simulate a sessionChanged event with the current CAIP session data
|
|
@@ -379,7 +374,12 @@ export class MetaMaskConnectMultichain extends MultichainCore {
|
|
|
379
374
|
});
|
|
380
375
|
}
|
|
381
376
|
}
|
|
382
|
-
_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() {
|
|
383
383
|
return __awaiter(this, void 0, void 0, function* () {
|
|
384
384
|
yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
|
|
385
385
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_anonId, anonId, "f");
|
|
@@ -406,7 +406,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
406
406
|
});
|
|
407
407
|
}, _MetaMaskConnectMultichain_getStoredTransport = function _MetaMaskConnectMultichain_getStoredTransport() {
|
|
408
408
|
return __awaiter(this, void 0, void 0, function* () {
|
|
409
|
-
const transportType = yield this.storage.
|
|
409
|
+
const transportType = yield this.storage.getTransportType();
|
|
410
410
|
const hasExtensionInstalled = yield hasExtension();
|
|
411
411
|
if (transportType) {
|
|
412
412
|
if (transportType === TransportType.Browser) {
|
|
@@ -431,7 +431,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
431
431
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, apiTransport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
432
432
|
return apiTransport;
|
|
433
433
|
}
|
|
434
|
-
yield this.storage.
|
|
434
|
+
yield this.storage.removeTransportType();
|
|
435
435
|
}
|
|
436
436
|
return undefined;
|
|
437
437
|
});
|
|
@@ -440,16 +440,16 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
440
440
|
var _a;
|
|
441
441
|
const transport = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_getStoredTransport).call(this);
|
|
442
442
|
if (transport) {
|
|
443
|
-
if (!
|
|
443
|
+
if (!transport.isConnected()) {
|
|
444
444
|
this.status = 'connecting';
|
|
445
|
-
yield
|
|
445
|
+
yield transport.connect();
|
|
446
446
|
}
|
|
447
447
|
this.status = 'connected';
|
|
448
448
|
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_transportType, "f") === TransportType.MWP) {
|
|
449
|
-
yield this.storage.
|
|
449
|
+
yield this.storage.setTransportType(TransportType.MWP);
|
|
450
450
|
}
|
|
451
451
|
else {
|
|
452
|
-
yield this.storage.
|
|
452
|
+
yield this.storage.setTransportType(TransportType.Browser);
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
else {
|
|
@@ -463,7 +463,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
463
463
|
// and that wallet_sessionChanged (faked) is emitted. But because we are not
|
|
464
464
|
// calling transport.connect(), we need to initialize DefaultTransport manually.
|
|
465
465
|
try {
|
|
466
|
-
yield this.
|
|
466
|
+
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).init();
|
|
467
467
|
}
|
|
468
468
|
catch (error) {
|
|
469
469
|
console.error('Passive init failed:', error);
|
|
@@ -487,7 +487,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
487
487
|
yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_setupTransport).call(this);
|
|
488
488
|
}
|
|
489
489
|
catch (error) {
|
|
490
|
-
yield this.storage.
|
|
490
|
+
yield this.storage.removeTransportType();
|
|
491
491
|
this.status = 'pending';
|
|
492
492
|
logger('MetaMaskSDK error during initialization', error);
|
|
493
493
|
}
|
|
@@ -532,15 +532,15 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
532
532
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transport, apiTransport, "f");
|
|
533
533
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_transportType, TransportType.MWP, "f");
|
|
534
534
|
__classPrivateFieldGet(this, _MetaMaskConnectMultichain_providerTransportWrapper, "f").setupTransportNotificationListener();
|
|
535
|
-
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener,
|
|
536
|
-
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);
|
|
537
537
|
});
|
|
538
538
|
}, _MetaMaskConnectMultichain_onBeforeUnload = function _MetaMaskConnectMultichain_onBeforeUnload() {
|
|
539
539
|
return __awaiter(this, void 0, void 0, function* () {
|
|
540
540
|
var _a;
|
|
541
541
|
// Fixes glitch with "connecting" state when modal is still visible and we close screen or refresh
|
|
542
542
|
if ((_a = this.options.ui.factory.modal) === null || _a === void 0 ? void 0 : _a.isMounted) {
|
|
543
|
-
yield this.storage.
|
|
543
|
+
yield this.storage.removeTransportType();
|
|
544
544
|
}
|
|
545
545
|
});
|
|
546
546
|
}, _MetaMaskConnectMultichain_createBeforeUnloadListener = function _MetaMaskConnectMultichain_createBeforeUnloadListener() {
|
|
@@ -557,73 +557,70 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
557
557
|
};
|
|
558
558
|
}, _MetaMaskConnectMultichain_renderInstallModalAsync = function _MetaMaskConnectMultichain_renderInstallModalAsync(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
559
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
this.
|
|
563
|
-
.
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
576
|
-
var _a;
|
|
577
|
-
try {
|
|
578
|
-
yield this.transport.connect({
|
|
579
|
-
scopes,
|
|
580
|
-
caipAccountIds,
|
|
581
|
-
sessionProperties,
|
|
582
|
-
});
|
|
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.setTransport(TransportType.MWP);
|
|
587
|
-
}
|
|
588
|
-
catch (error) {
|
|
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
|
-
// Close the modal on error
|
|
594
|
-
yield this.options.ui.factory.unload(error);
|
|
595
|
-
reject(error);
|
|
596
|
-
}
|
|
597
|
-
// If request is expires, the QRCode will automatically be regenerated we can ignore this case
|
|
598
|
-
}
|
|
599
|
-
else {
|
|
600
|
-
this.status = 'disconnected';
|
|
601
|
-
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
602
|
-
// Close the modal on error
|
|
603
|
-
yield this.options.ui.factory.unload(normalizedError);
|
|
604
|
-
reject(normalizedError);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
}))().catch(() => {
|
|
608
|
-
// Error already handled in the async function
|
|
609
|
-
});
|
|
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),
|
|
610
573
|
});
|
|
611
|
-
})
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
|
615
597
|
}
|
|
616
598
|
else {
|
|
617
|
-
|
|
618
|
-
|
|
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);
|
|
619
603
|
}
|
|
620
|
-
})
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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)));
|
|
626
622
|
});
|
|
623
|
+
return completion.promise;
|
|
627
624
|
});
|
|
628
625
|
}, _MetaMaskConnectMultichain_showInstallModal = function _MetaMaskConnectMultichain_showInstallModal(desktopPreferred, scopes, caipAccountIds, sessionProperties) {
|
|
629
626
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -640,47 +637,45 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
640
637
|
});
|
|
641
638
|
}, _MetaMaskConnectMultichain_headlessConnect = function _MetaMaskConnectMultichain_headlessConnect(scopes, caipAccountIds, sessionProperties) {
|
|
642
639
|
return __awaiter(this, void 0, void 0, function* () {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
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,
|
|
659
662
|
});
|
|
660
|
-
|
|
661
|
-
this.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
this.status = 'disconnected';
|
|
679
|
-
yield this.storage.removeTransport();
|
|
680
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
681
|
-
}
|
|
682
|
-
}));
|
|
683
|
-
});
|
|
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
|
+
}
|
|
684
679
|
});
|
|
685
680
|
}, _MetaMaskConnectMultichain_setupDefaultTransport = function _MetaMaskConnectMultichain_setupDefaultTransport() {
|
|
686
681
|
return __awaiter(this, arguments, void 0, function* (options = { persist: true }) {
|
|
@@ -688,7 +683,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
688
683
|
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f");
|
|
689
684
|
}
|
|
690
685
|
if (options === null || options === void 0 ? void 0 : options.persist) {
|
|
691
|
-
yield this.storage.
|
|
686
|
+
yield this.storage.setTransportType(TransportType.Browser);
|
|
692
687
|
}
|
|
693
688
|
const transport = new DefaultTransport();
|
|
694
689
|
__classPrivateFieldSet(this, _MetaMaskConnectMultichain_listener, transport.onNotification(__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_onTransportNotification).bind(this)), "f");
|
|
@@ -724,7 +719,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
724
719
|
};
|
|
725
720
|
this.dappClient.on('message', dappClientMessageHandler);
|
|
726
721
|
let timeout;
|
|
727
|
-
if (this.
|
|
722
|
+
if (__classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this).isConnected()) {
|
|
728
723
|
timeout = setTimeout(() => {
|
|
729
724
|
this.openSimpleDeeplinkIfNeeded();
|
|
730
725
|
}, 250);
|
|
@@ -748,11 +743,11 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
748
743
|
}
|
|
749
744
|
});
|
|
750
745
|
}
|
|
751
|
-
return this.
|
|
746
|
+
return __classPrivateFieldGet(this, _MetaMaskConnectMultichain_instances, "m", _MetaMaskConnectMultichain_transportOrThrow).call(this)
|
|
752
747
|
.connect({ scopes, caipAccountIds, sessionProperties })
|
|
753
748
|
.then(resolve)
|
|
754
749
|
.catch((error) => __awaiter(this, void 0, void 0, function* () {
|
|
755
|
-
yield this.storage.
|
|
750
|
+
yield this.storage.removeTransportType();
|
|
756
751
|
this.dappClient.off('message', dappClientMessageHandler);
|
|
757
752
|
reject(error instanceof Error ? error : new Error(String(error)));
|
|
758
753
|
}))
|
|
@@ -809,7 +804,7 @@ _MetaMaskConnectMultichain_provider = new WeakMap(), _MetaMaskConnectMultichain_
|
|
|
809
804
|
};
|
|
810
805
|
if ((_a = __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f")) === null || _a === void 0 ? void 0 : _a.isConnected()) {
|
|
811
806
|
try {
|
|
812
|
-
const response = yield this.
|
|
807
|
+
const response = yield __classPrivateFieldGet(this, _MetaMaskConnectMultichain_transport, "f").request({
|
|
813
808
|
method: 'wallet_getSession',
|
|
814
809
|
});
|
|
815
810
|
if (response.result) {
|