@web3auth/no-modal 8.7.0 → 8.9.1
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/dist/noModal.cjs.js +40 -29
- package/dist/noModal.esm.js +41 -30
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +0 -9
- package/dist/types/noModal.d.ts +1 -0
- package/package.json +6 -6
package/dist/noModal.cjs.js
CHANGED
|
@@ -130,7 +130,8 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
130
130
|
try {
|
|
131
131
|
projectConfig = await (0,base_namespaceObject.fetchProjectConfig)(this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
132
132
|
} catch (e) {
|
|
133
|
-
|
|
133
|
+
base_namespaceObject.log.error("Failed to fetch project configurations", e);
|
|
134
|
+
throw base_namespaceObject.WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
134
135
|
}
|
|
135
136
|
const initPromises = Object.keys(this.walletAdapters).map(async adapterName => {
|
|
136
137
|
this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
|
|
@@ -294,9 +295,15 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
294
295
|
return this.walletAdapters[this.connectedAdapterName].authenticateUser();
|
|
295
296
|
}
|
|
296
297
|
addPlugin(plugin) {
|
|
297
|
-
if (this.plugins[plugin.name]) throw
|
|
298
|
-
if (plugin.pluginNamespace !== base_namespaceObject.PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== this.coreOptions.chainConfig.chainNamespace) throw
|
|
298
|
+
if (this.plugins[plugin.name]) throw base_namespaceObject.WalletInitializationError.duplicateAdapterError(`Plugin ${plugin.name} already exist`);
|
|
299
|
+
if (plugin.pluginNamespace !== base_namespaceObject.PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== this.coreOptions.chainConfig.chainNamespace) throw base_namespaceObject.WalletInitializationError.incompatibleChainNameSpace(`This plugin belongs to ${plugin.pluginNamespace} namespace which is incompatible with currently used namespace: ${this.coreOptions.chainConfig.chainNamespace}`);
|
|
299
300
|
this.plugins[plugin.name] = plugin;
|
|
301
|
+
if (this.status === base_namespaceObject.ADAPTER_STATUS.CONNECTED && this.connectedAdapterName) {
|
|
302
|
+
// web3auth is already connected. can initialize plugins
|
|
303
|
+
this.connectToPlugins({
|
|
304
|
+
adapter: this.connectedAdapterName
|
|
305
|
+
});
|
|
306
|
+
}
|
|
300
307
|
return this;
|
|
301
308
|
}
|
|
302
309
|
getPlugin(name) {
|
|
@@ -313,32 +320,7 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
313
320
|
this.connectedAdapterName = data.adapter;
|
|
314
321
|
this.cacheWallet(data.adapter);
|
|
315
322
|
base_namespaceObject.log.debug("connected", this.status, this.connectedAdapterName);
|
|
316
|
-
|
|
317
|
-
try {
|
|
318
|
-
if (!plugin.SUPPORTED_ADAPTERS.includes(data.adapter)) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const {
|
|
322
|
-
openloginInstance
|
|
323
|
-
} = this.walletAdapters[this.connectedAdapterName];
|
|
324
|
-
const {
|
|
325
|
-
options,
|
|
326
|
-
sessionId,
|
|
327
|
-
sessionNamespace
|
|
328
|
-
} = openloginInstance || {};
|
|
329
|
-
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
330
|
-
await plugin.connect({
|
|
331
|
-
sessionId,
|
|
332
|
-
sessionNamespace
|
|
333
|
-
});
|
|
334
|
-
} catch (error) {
|
|
335
|
-
// swallow error if connector adapter doesn't supports this plugin.
|
|
336
|
-
if (error.code === 5211) {
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
base_namespaceObject.log.error(error);
|
|
340
|
-
}
|
|
341
|
-
});
|
|
323
|
+
this.connectToPlugins(data);
|
|
342
324
|
this.emit(base_namespaceObject.ADAPTER_EVENTS.CONNECTED, objectSpread2_default()({}, data));
|
|
343
325
|
});
|
|
344
326
|
walletAdapter.on(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED, async data => {
|
|
@@ -396,6 +378,35 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
396
378
|
window[this.storage].setItem(ADAPTER_CACHE_KEY, walletName);
|
|
397
379
|
this.cachedAdapter = walletName;
|
|
398
380
|
}
|
|
381
|
+
connectToPlugins(data) {
|
|
382
|
+
Object.values(this.plugins).map(async plugin => {
|
|
383
|
+
try {
|
|
384
|
+
if (!plugin.SUPPORTED_ADAPTERS.includes(data.adapter)) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (plugin.status === base_namespaceObject.PLUGIN_STATUS.CONNECTED) return;
|
|
388
|
+
const {
|
|
389
|
+
openloginInstance
|
|
390
|
+
} = this.walletAdapters[this.connectedAdapterName];
|
|
391
|
+
const {
|
|
392
|
+
options,
|
|
393
|
+
sessionId,
|
|
394
|
+
sessionNamespace
|
|
395
|
+
} = openloginInstance || {};
|
|
396
|
+
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
397
|
+
await plugin.connect({
|
|
398
|
+
sessionId,
|
|
399
|
+
sessionNamespace
|
|
400
|
+
});
|
|
401
|
+
} catch (error) {
|
|
402
|
+
// swallow error if connector adapter doesn't supports this plugin.
|
|
403
|
+
if (error.code === 5211) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
base_namespaceObject.log.error(error);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
399
410
|
}
|
|
400
411
|
;// CONCATENATED MODULE: ./src/index.ts
|
|
401
412
|
|
package/dist/noModal.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { SafeEventEmitter } from '@toruslabs/openlogin-jrpc';
|
|
4
|
-
import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, ADAPTER_EVENTS, ADAPTER_NAMESPACES, WalletLoginError, PLUGIN_NAMESPACES } from '@web3auth/base';
|
|
4
|
+
import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, ADAPTER_EVENTS, ADAPTER_NAMESPACES, WalletLoginError, PLUGIN_NAMESPACES, PLUGIN_STATUS } from '@web3auth/base';
|
|
5
5
|
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
6
6
|
import { LOGIN_PROVIDER } from '@web3auth/openlogin-adapter';
|
|
7
7
|
import clonedeep from 'lodash.clonedeep';
|
|
@@ -54,7 +54,8 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
54
54
|
try {
|
|
55
55
|
projectConfig = await fetchProjectConfig(this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
56
56
|
} catch (e) {
|
|
57
|
-
|
|
57
|
+
log.error("Failed to fetch project configurations", e);
|
|
58
|
+
throw WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
58
59
|
}
|
|
59
60
|
const initPromises = Object.keys(this.walletAdapters).map(async adapterName => {
|
|
60
61
|
this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
|
|
@@ -218,9 +219,15 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
218
219
|
return this.walletAdapters[this.connectedAdapterName].authenticateUser();
|
|
219
220
|
}
|
|
220
221
|
addPlugin(plugin) {
|
|
221
|
-
if (this.plugins[plugin.name]) throw
|
|
222
|
-
if (plugin.pluginNamespace !== PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== this.coreOptions.chainConfig.chainNamespace) throw
|
|
222
|
+
if (this.plugins[plugin.name]) throw WalletInitializationError.duplicateAdapterError(`Plugin ${plugin.name} already exist`);
|
|
223
|
+
if (plugin.pluginNamespace !== PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== this.coreOptions.chainConfig.chainNamespace) throw WalletInitializationError.incompatibleChainNameSpace(`This plugin belongs to ${plugin.pluginNamespace} namespace which is incompatible with currently used namespace: ${this.coreOptions.chainConfig.chainNamespace}`);
|
|
223
224
|
this.plugins[plugin.name] = plugin;
|
|
225
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName) {
|
|
226
|
+
// web3auth is already connected. can initialize plugins
|
|
227
|
+
this.connectToPlugins({
|
|
228
|
+
adapter: this.connectedAdapterName
|
|
229
|
+
});
|
|
230
|
+
}
|
|
224
231
|
return this;
|
|
225
232
|
}
|
|
226
233
|
getPlugin(name) {
|
|
@@ -237,32 +244,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
237
244
|
this.connectedAdapterName = data.adapter;
|
|
238
245
|
this.cacheWallet(data.adapter);
|
|
239
246
|
log.debug("connected", this.status, this.connectedAdapterName);
|
|
240
|
-
|
|
241
|
-
try {
|
|
242
|
-
if (!plugin.SUPPORTED_ADAPTERS.includes(data.adapter)) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
const {
|
|
246
|
-
openloginInstance
|
|
247
|
-
} = this.walletAdapters[this.connectedAdapterName];
|
|
248
|
-
const {
|
|
249
|
-
options,
|
|
250
|
-
sessionId,
|
|
251
|
-
sessionNamespace
|
|
252
|
-
} = openloginInstance || {};
|
|
253
|
-
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
254
|
-
await plugin.connect({
|
|
255
|
-
sessionId,
|
|
256
|
-
sessionNamespace
|
|
257
|
-
});
|
|
258
|
-
} catch (error) {
|
|
259
|
-
// swallow error if connector adapter doesn't supports this plugin.
|
|
260
|
-
if (error.code === 5211) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
log.error(error);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
247
|
+
this.connectToPlugins(data);
|
|
266
248
|
this.emit(ADAPTER_EVENTS.CONNECTED, _objectSpread({}, data));
|
|
267
249
|
});
|
|
268
250
|
walletAdapter.on(ADAPTER_EVENTS.DISCONNECTED, async data => {
|
|
@@ -320,6 +302,35 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
320
302
|
window[this.storage].setItem(ADAPTER_CACHE_KEY, walletName);
|
|
321
303
|
this.cachedAdapter = walletName;
|
|
322
304
|
}
|
|
305
|
+
connectToPlugins(data) {
|
|
306
|
+
Object.values(this.plugins).map(async plugin => {
|
|
307
|
+
try {
|
|
308
|
+
if (!plugin.SUPPORTED_ADAPTERS.includes(data.adapter)) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (plugin.status === PLUGIN_STATUS.CONNECTED) return;
|
|
312
|
+
const {
|
|
313
|
+
openloginInstance
|
|
314
|
+
} = this.walletAdapters[this.connectedAdapterName];
|
|
315
|
+
const {
|
|
316
|
+
options,
|
|
317
|
+
sessionId,
|
|
318
|
+
sessionNamespace
|
|
319
|
+
} = openloginInstance || {};
|
|
320
|
+
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
321
|
+
await plugin.connect({
|
|
322
|
+
sessionId,
|
|
323
|
+
sessionNamespace
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
// swallow error if connector adapter doesn't supports this plugin.
|
|
327
|
+
if (error.code === 5211) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
log.error(error);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
323
334
|
}
|
|
324
335
|
|
|
325
336
|
export { Web3AuthNoModal };
|