@web3auth/modal 3.0.1 → 3.0.3
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/modal.cjs.js +37 -194
- package/dist/modal.cjs.js.map +1 -1
- package/dist/modal.esm.js +34 -189
- package/dist/modal.esm.js.map +1 -1
- package/dist/modal.umd.min.js +1 -1
- package/dist/modal.umd.min.js.LICENSE.txt +0 -15
- package/dist/modal.umd.min.js.map +1 -1
- package/dist/types/modalManager.d.ts +1 -1
- package/package.json +8 -8
- package/src/modalManager.ts +18 -36
- package/src/utils.ts +2 -1
package/dist/modal.esm.js
CHANGED
|
@@ -11,7 +11,7 @@ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstruct
|
|
|
11
11
|
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
12
12
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
13
13
|
import { Web3AuthCore } from '@web3auth/core';
|
|
14
|
-
import LoginModal,
|
|
14
|
+
import { LoginModal, getAdapterSocialLogins, OPENLOGIN_PROVIDERS, LOGIN_MODAL_EVENTS } from '@web3auth/ui';
|
|
15
15
|
|
|
16
16
|
var _adapters, _adapters2;
|
|
17
17
|
var defaultSolanaDappModalConfig = {
|
|
@@ -86,36 +86,28 @@ var defaultOtherModalConfig = {
|
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
89
|
-
|
|
90
89
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
91
90
|
var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
92
91
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
|
|
93
92
|
var name, customChainConfig, clientId, finalChainConfig, _yield$import, TorusWalletAdapter, adapter, _yield$import2, SolanaWalletAdapter, _adapter, _yield$import3, MetamaskAdapter, _adapter2, _yield$import4, PhantomAdapter, _adapter3, _yield$import5, WalletConnectV1Adapter, _adapter4, _yield$import6, OpenloginAdapter, getOpenloginDefaultOptions, defaultOptions, _adapter5;
|
|
94
|
-
|
|
95
93
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
96
94
|
while (1) {
|
|
97
95
|
switch (_context.prev = _context.next) {
|
|
98
96
|
case 0:
|
|
99
97
|
name = params.name, customChainConfig = params.customChainConfig, clientId = params.clientId;
|
|
100
|
-
|
|
101
98
|
if (Object.values(CHAIN_NAMESPACES).includes(customChainConfig.chainNamespace)) {
|
|
102
99
|
_context.next = 3;
|
|
103
100
|
break;
|
|
104
101
|
}
|
|
105
|
-
|
|
106
102
|
throw new Error("Invalid chainNamespace: ".concat(customChainConfig.chainNamespace));
|
|
107
|
-
|
|
108
103
|
case 3:
|
|
109
104
|
finalChainConfig = _objectSpread$1(_objectSpread$1({}, getChainConfig(customChainConfig.chainNamespace, customChainConfig === null || customChainConfig === void 0 ? void 0 : customChainConfig.chainId)), customChainConfig || {});
|
|
110
|
-
|
|
111
105
|
if (!(name === WALLET_ADAPTERS.TORUS_EVM)) {
|
|
112
106
|
_context.next = 13;
|
|
113
107
|
break;
|
|
114
108
|
}
|
|
115
|
-
|
|
116
109
|
_context.next = 7;
|
|
117
110
|
return import('@web3auth/torus-evm-adapter');
|
|
118
|
-
|
|
119
111
|
case 7:
|
|
120
112
|
_yield$import = _context.sent;
|
|
121
113
|
TorusWalletAdapter = _yield$import.TorusWalletAdapter;
|
|
@@ -124,16 +116,13 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
124
116
|
clientId: clientId
|
|
125
117
|
});
|
|
126
118
|
return _context.abrupt("return", adapter);
|
|
127
|
-
|
|
128
119
|
case 13:
|
|
129
120
|
if (!(name === WALLET_ADAPTERS.TORUS_SOLANA)) {
|
|
130
121
|
_context.next = 22;
|
|
131
122
|
break;
|
|
132
123
|
}
|
|
133
|
-
|
|
134
124
|
_context.next = 16;
|
|
135
125
|
return import('@web3auth/torus-solana-adapter');
|
|
136
|
-
|
|
137
126
|
case 16:
|
|
138
127
|
_yield$import2 = _context.sent;
|
|
139
128
|
SolanaWalletAdapter = _yield$import2.SolanaWalletAdapter;
|
|
@@ -142,16 +131,13 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
142
131
|
clientId: clientId
|
|
143
132
|
});
|
|
144
133
|
return _context.abrupt("return", _adapter);
|
|
145
|
-
|
|
146
134
|
case 22:
|
|
147
135
|
if (!(name === WALLET_ADAPTERS.METAMASK)) {
|
|
148
136
|
_context.next = 31;
|
|
149
137
|
break;
|
|
150
138
|
}
|
|
151
|
-
|
|
152
139
|
_context.next = 25;
|
|
153
140
|
return import('@web3auth/metamask-adapter');
|
|
154
|
-
|
|
155
141
|
case 25:
|
|
156
142
|
_yield$import3 = _context.sent;
|
|
157
143
|
MetamaskAdapter = _yield$import3.MetamaskAdapter;
|
|
@@ -160,16 +146,13 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
160
146
|
clientId: clientId
|
|
161
147
|
});
|
|
162
148
|
return _context.abrupt("return", _adapter2);
|
|
163
|
-
|
|
164
149
|
case 31:
|
|
165
150
|
if (!(name === WALLET_ADAPTERS.PHANTOM)) {
|
|
166
151
|
_context.next = 40;
|
|
167
152
|
break;
|
|
168
153
|
}
|
|
169
|
-
|
|
170
154
|
_context.next = 34;
|
|
171
155
|
return import('@web3auth/phantom-adapter');
|
|
172
|
-
|
|
173
156
|
case 34:
|
|
174
157
|
_yield$import4 = _context.sent;
|
|
175
158
|
PhantomAdapter = _yield$import4.PhantomAdapter;
|
|
@@ -178,16 +161,13 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
178
161
|
clientId: clientId
|
|
179
162
|
});
|
|
180
163
|
return _context.abrupt("return", _adapter3);
|
|
181
|
-
|
|
182
164
|
case 40:
|
|
183
165
|
if (!(name === WALLET_ADAPTERS.WALLET_CONNECT_V1)) {
|
|
184
166
|
_context.next = 49;
|
|
185
167
|
break;
|
|
186
168
|
}
|
|
187
|
-
|
|
188
169
|
_context.next = 43;
|
|
189
170
|
return import('@web3auth/wallet-connect-v1-adapter');
|
|
190
|
-
|
|
191
171
|
case 43:
|
|
192
172
|
_yield$import5 = _context.sent;
|
|
193
173
|
WalletConnectV1Adapter = _yield$import5.WalletConnectV1Adapter;
|
|
@@ -196,16 +176,13 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
196
176
|
clientId: clientId
|
|
197
177
|
});
|
|
198
178
|
return _context.abrupt("return", _adapter4);
|
|
199
|
-
|
|
200
179
|
case 49:
|
|
201
180
|
if (!(name === WALLET_ADAPTERS.OPENLOGIN)) {
|
|
202
181
|
_context.next = 58;
|
|
203
182
|
break;
|
|
204
183
|
}
|
|
205
|
-
|
|
206
184
|
_context.next = 52;
|
|
207
185
|
return import('@web3auth/openlogin-adapter');
|
|
208
|
-
|
|
209
186
|
case 52:
|
|
210
187
|
_yield$import6 = _context.sent;
|
|
211
188
|
OpenloginAdapter = _yield$import6.OpenloginAdapter;
|
|
@@ -218,10 +195,8 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
218
195
|
})
|
|
219
196
|
}));
|
|
220
197
|
return _context.abrupt("return", _adapter5);
|
|
221
|
-
|
|
222
198
|
case 58:
|
|
223
199
|
throw new Error("Invalid wallet adapter name");
|
|
224
|
-
|
|
225
200
|
case 59:
|
|
226
201
|
case "end":
|
|
227
202
|
return _context.stop();
|
|
@@ -229,7 +204,6 @@ var getDefaultAdapterModule = /*#__PURE__*/function () {
|
|
|
229
204
|
}
|
|
230
205
|
}, _callee);
|
|
231
206
|
}));
|
|
232
|
-
|
|
233
207
|
return function getDefaultAdapterModule(_x) {
|
|
234
208
|
return _ref.apply(this, arguments);
|
|
235
209
|
};
|
|
@@ -245,45 +219,30 @@ var languageMap = {
|
|
|
245
219
|
};
|
|
246
220
|
var getUserLanguage = function getUserLanguage(defaultLanguage) {
|
|
247
221
|
var userLanguage = defaultLanguage;
|
|
248
|
-
|
|
249
222
|
if (!userLanguage) {
|
|
250
|
-
var browserLanguage = window.navigator.userLanguage || window.navigator.language || "en-US";
|
|
223
|
+
var browserLanguage = typeof window !== "undefined" ? window.navigator.userLanguage || window.navigator.language || "en-US" : "en-US";
|
|
251
224
|
userLanguage = browserLanguage.split("-")[0];
|
|
252
225
|
}
|
|
253
|
-
|
|
254
226
|
return Object.prototype.hasOwnProperty.call(languageMap, userLanguage) ? userLanguage : "en";
|
|
255
227
|
};
|
|
256
228
|
|
|
257
229
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
258
|
-
|
|
259
230
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
260
|
-
|
|
261
231
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
262
|
-
|
|
263
232
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
264
233
|
var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
265
234
|
_inherits(Web3Auth, _Web3AuthCore);
|
|
266
|
-
|
|
267
235
|
var _super = _createSuper(Web3Auth);
|
|
268
|
-
|
|
269
236
|
function Web3Auth(options) {
|
|
270
237
|
var _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3;
|
|
271
|
-
|
|
272
238
|
var _this;
|
|
273
|
-
|
|
274
239
|
_classCallCheck(this, Web3Auth);
|
|
275
|
-
|
|
276
240
|
_this = _super.call(this, options);
|
|
277
|
-
|
|
278
241
|
_defineProperty(_assertThisInitialized(_this), "loginModal", void 0);
|
|
279
|
-
|
|
280
242
|
_defineProperty(_assertThisInitialized(_this), "options", void 0);
|
|
281
|
-
|
|
282
243
|
_defineProperty(_assertThisInitialized(_this), "modalConfig", defaultEvmDappModalConfig);
|
|
283
|
-
|
|
284
244
|
_this.options = _objectSpread({}, options);
|
|
285
245
|
var providedChainConfig = _this.options.chainConfig;
|
|
286
|
-
|
|
287
246
|
if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
288
247
|
if (options.authMode === "WALLET") {
|
|
289
248
|
// default config for solana wallet modal
|
|
@@ -304,9 +263,8 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
304
263
|
_this.modalConfig = defaultOtherModalConfig;
|
|
305
264
|
} else {
|
|
306
265
|
throw new Error("Invalid chainNamespace provided: ".concat(providedChainConfig.chainNamespace));
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
266
|
+
}
|
|
267
|
+
// get userLanguage
|
|
310
268
|
var defaultLanguage = getUserLanguage((_this$options$uiConfi = _this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.defaultLanguage);
|
|
311
269
|
_this.loginModal = new LoginModal({
|
|
312
270
|
theme: (_this$options$uiConfi2 = _this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.theme,
|
|
@@ -316,38 +274,29 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
316
274
|
displayErrorsOnModal: _this.options.displayErrorsOnModal,
|
|
317
275
|
defaultLanguage: defaultLanguage
|
|
318
276
|
});
|
|
319
|
-
|
|
320
277
|
_this.subscribeToLoginModalEvents();
|
|
321
|
-
|
|
322
278
|
return _this;
|
|
323
279
|
}
|
|
324
|
-
|
|
325
280
|
_createClass(Web3Auth, [{
|
|
326
281
|
key: "initModal",
|
|
327
282
|
value: function () {
|
|
328
283
|
var _initModal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
|
|
329
284
|
var _this2 = this;
|
|
330
|
-
|
|
331
285
|
var providedChainConfig, allAdapters, adapterConfigurationPromises, adapterNames, hasInAppWallets, initPromises, hasExternalWallets;
|
|
332
286
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
333
287
|
while (1) {
|
|
334
288
|
switch (_context3.prev = _context3.next) {
|
|
335
289
|
case 0:
|
|
336
290
|
_get(_getPrototypeOf(Web3Auth.prototype), "checkInitRequirements", this).call(this);
|
|
337
|
-
|
|
338
291
|
_context3.next = 3;
|
|
339
292
|
return this.loginModal.initModal();
|
|
340
|
-
|
|
341
293
|
case 3:
|
|
342
294
|
providedChainConfig = this.options.chainConfig; // merge default adapters with the custom configured adapters.
|
|
343
|
-
|
|
344
295
|
allAdapters = _toConsumableArray(new Set([].concat(_toConsumableArray(Object.keys(this.modalConfig.adapters || {})), _toConsumableArray(Object.keys(this.walletAdapters)))));
|
|
345
296
|
adapterConfigurationPromises = allAdapters.map( /*#__PURE__*/function () {
|
|
346
297
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(adapterName) {
|
|
347
298
|
var _this2$modalConfig$ad, _params$modalConfig, _this2$modalConfig$ad2, _this2$modalConfig$ad3;
|
|
348
|
-
|
|
349
299
|
var adapterConfig, adapter, ad, _this2$modalConfig$ad4, _this2$coreOptions$ch, chainConfig;
|
|
350
|
-
|
|
351
300
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
352
301
|
while (1) {
|
|
353
302
|
switch (_context.prev = _context.next) {
|
|
@@ -359,65 +308,53 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
359
308
|
showOnMobile: true,
|
|
360
309
|
showOnDesktop: true
|
|
361
310
|
}; // override the default config of adapter if some config is being provided by the user.
|
|
362
|
-
|
|
363
311
|
if (params !== null && params !== void 0 && (_params$modalConfig = params.modalConfig) !== null && _params$modalConfig !== void 0 && _params$modalConfig[adapterName]) {
|
|
364
312
|
adapterConfig = _objectSpread(_objectSpread({}, adapterConfig), params.modalConfig[adapterName]);
|
|
365
313
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
314
|
+
_this2.modalConfig.adapters[adapterName] = adapterConfig;
|
|
315
|
+
// check if adapter is configured/added by user and exist in walletAdapters map.
|
|
369
316
|
adapter = _this2.walletAdapters[adapterName];
|
|
370
|
-
log.debug("adapter config", adapterName, (_this2$modalConfig$ad2 = _this2.modalConfig.adapters) === null || _this2$modalConfig$ad2 === void 0 ? void 0 : _this2$modalConfig$ad2[adapterName].showOnModal, adapter);
|
|
317
|
+
log.debug("adapter config", adapterName, (_this2$modalConfig$ad2 = _this2.modalConfig.adapters) === null || _this2$modalConfig$ad2 === void 0 ? void 0 : _this2$modalConfig$ad2[adapterName].showOnModal, adapter);
|
|
318
|
+
// if adapter is not custom configured then check if it is available in default adapters.
|
|
371
319
|
// and if adapter is not hidden by user
|
|
372
|
-
|
|
373
320
|
if (!(!adapter && (_this2$modalConfig$ad3 = _this2.modalConfig.adapters) !== null && _this2$modalConfig$ad3 !== void 0 && _this2$modalConfig$ad3[adapterName].showOnModal)) {
|
|
374
321
|
_context.next = 13;
|
|
375
322
|
break;
|
|
376
323
|
}
|
|
377
|
-
|
|
378
324
|
_context.next = 8;
|
|
379
325
|
return getDefaultAdapterModule({
|
|
380
326
|
name: adapterName,
|
|
381
327
|
customChainConfig: _this2.options.chainConfig,
|
|
382
328
|
clientId: _this2.options.clientId
|
|
383
329
|
});
|
|
384
|
-
|
|
385
330
|
case 8:
|
|
386
331
|
ad = _context.sent;
|
|
387
332
|
_this2.walletAdapters[adapterName] = ad;
|
|
388
333
|
return _context.abrupt("return", adapterName);
|
|
389
|
-
|
|
390
334
|
case 13:
|
|
391
335
|
if (!((adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.IN_APP || (adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.EXTERNAL || adapterName === _this2.cachedAdapter)) {
|
|
392
336
|
_context.next = 19;
|
|
393
337
|
break;
|
|
394
338
|
}
|
|
395
|
-
|
|
396
339
|
if ((_this2$modalConfig$ad4 = _this2.modalConfig.adapters) !== null && _this2$modalConfig$ad4 !== void 0 && _this2$modalConfig$ad4[adapterName].showOnModal) {
|
|
397
340
|
_context.next = 16;
|
|
398
341
|
break;
|
|
399
342
|
}
|
|
400
|
-
|
|
401
343
|
return _context.abrupt("return");
|
|
402
|
-
|
|
403
344
|
case 16:
|
|
404
345
|
// add client id to adapter, same web3auth client id can be used in adapter.
|
|
405
346
|
// this id is being overridden if user is also passing client id in adapter's constructor.
|
|
406
347
|
_this2.walletAdapters[adapterName].setAdapterSettings({
|
|
407
348
|
clientId: _this2.options.clientId,
|
|
408
349
|
sessionTime: _this2.options.sessionTime
|
|
409
|
-
});
|
|
350
|
+
});
|
|
351
|
+
// if adapter doesn't have any chainConfig then we will set the chainConfig based of passed chainNamespace
|
|
410
352
|
// and chainNamespace.
|
|
411
|
-
|
|
412
|
-
|
|
413
353
|
if (!adapter.chainConfigProxy) {
|
|
414
354
|
chainConfig = _objectSpread(_objectSpread({}, getChainConfig(providedChainConfig.chainNamespace, (_this2$coreOptions$ch = _this2.coreOptions.chainConfig) === null || _this2$coreOptions$ch === void 0 ? void 0 : _this2$coreOptions$ch.chainId)), _this2.coreOptions.chainConfig);
|
|
415
|
-
|
|
416
355
|
_this2.walletAdapters[adapterName].setChainConfig(chainConfig);
|
|
417
356
|
}
|
|
418
|
-
|
|
419
357
|
return _context.abrupt("return", adapterName);
|
|
420
|
-
|
|
421
358
|
case 19:
|
|
422
359
|
case "end":
|
|
423
360
|
return _context.stop();
|
|
@@ -425,19 +362,16 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
425
362
|
}
|
|
426
363
|
}, _callee);
|
|
427
364
|
}));
|
|
428
|
-
|
|
429
365
|
return function (_x2) {
|
|
430
366
|
return _ref.apply(this, arguments);
|
|
431
367
|
};
|
|
432
368
|
}());
|
|
433
369
|
_context3.next = 8;
|
|
434
370
|
return Promise.all(adapterConfigurationPromises);
|
|
435
|
-
|
|
436
371
|
case 8:
|
|
437
372
|
adapterNames = _context3.sent;
|
|
438
373
|
hasInAppWallets = Object.values(this.walletAdapters).some(function (adapter) {
|
|
439
374
|
var _this2$modalConfig$ad5;
|
|
440
|
-
|
|
441
375
|
if (adapter.type !== ADAPTER_CATEGORY.IN_APP) return false;
|
|
442
376
|
if (_this2.modalConfig.adapters[adapter.name].showOnModal !== true) return false;
|
|
443
377
|
if (!_this2.modalConfig.adapters[adapter.name].loginMethods) return true;
|
|
@@ -447,8 +381,8 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
447
381
|
})) return true;
|
|
448
382
|
return false;
|
|
449
383
|
});
|
|
450
|
-
log.debug(hasInAppWallets, this.walletAdapters, "hasInAppWallets");
|
|
451
|
-
|
|
384
|
+
log.debug(hasInAppWallets, this.walletAdapters, "hasInAppWallets");
|
|
385
|
+
// Now, initialize the adapters.
|
|
452
386
|
initPromises = adapterNames.map( /*#__PURE__*/function () {
|
|
453
387
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(adapterName) {
|
|
454
388
|
var adapter;
|
|
@@ -460,51 +394,40 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
460
394
|
_context2.next = 2;
|
|
461
395
|
break;
|
|
462
396
|
}
|
|
463
|
-
|
|
464
397
|
return _context2.abrupt("return");
|
|
465
|
-
|
|
466
398
|
case 2:
|
|
467
399
|
_context2.prev = 2;
|
|
468
400
|
adapter = _this2.walletAdapters[adapterName]; // only initialize a external adapter here if it is a cached adapter.
|
|
469
|
-
|
|
470
401
|
if (!(_this2.cachedAdapter !== adapterName && adapter.type === ADAPTER_CATEGORY.EXTERNAL)) {
|
|
471
402
|
_context2.next = 6;
|
|
472
403
|
break;
|
|
473
404
|
}
|
|
474
|
-
|
|
475
405
|
return _context2.abrupt("return");
|
|
476
|
-
|
|
477
406
|
case 6:
|
|
478
407
|
// in-app wallets or cached wallet (being connected or already connected) are initialized first.
|
|
479
408
|
// if adapter is configured thn only initialize in app or cached adapter.
|
|
480
409
|
// external wallets are initialized on INIT_EXTERNAL_WALLET event.
|
|
481
410
|
_this2.subscribeToAdapterEvents(adapter);
|
|
482
|
-
|
|
483
411
|
if (!(adapter.status === ADAPTER_STATUS.NOT_READY)) {
|
|
484
412
|
_context2.next = 10;
|
|
485
413
|
break;
|
|
486
414
|
}
|
|
487
|
-
|
|
488
415
|
_context2.next = 10;
|
|
489
416
|
return adapter.init({
|
|
490
417
|
autoConnect: _this2.cachedAdapter === adapterName
|
|
491
418
|
});
|
|
492
|
-
|
|
493
419
|
case 10:
|
|
494
420
|
// note: not adding cachedWallet to modal if it is external wallet.
|
|
495
421
|
// adding it later if no in-app wallets are available.
|
|
496
422
|
if (adapter.type === ADAPTER_CATEGORY.IN_APP) {
|
|
497
423
|
_this2.initializeInAppWallet(adapterName);
|
|
498
424
|
}
|
|
499
|
-
|
|
500
425
|
_context2.next = 16;
|
|
501
426
|
break;
|
|
502
|
-
|
|
503
427
|
case 13:
|
|
504
428
|
_context2.prev = 13;
|
|
505
429
|
_context2.t0 = _context2["catch"](2);
|
|
506
430
|
log.error(_context2.t0, "error while initializing adapter");
|
|
507
|
-
|
|
508
431
|
case 16:
|
|
509
432
|
case "end":
|
|
510
433
|
return _context2.stop();
|
|
@@ -512,7 +435,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
512
435
|
}
|
|
513
436
|
}, _callee2, null, [[2, 13]]);
|
|
514
437
|
}));
|
|
515
|
-
|
|
516
438
|
return function (_x3) {
|
|
517
439
|
return _ref2.apply(this, arguments);
|
|
518
440
|
};
|
|
@@ -520,30 +442,24 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
520
442
|
this.status = ADAPTER_STATUS.READY;
|
|
521
443
|
_context3.next = 15;
|
|
522
444
|
return Promise.all(initPromises);
|
|
523
|
-
|
|
524
445
|
case 15:
|
|
525
446
|
hasExternalWallets = allAdapters.some(function (adapterName) {
|
|
526
447
|
var _this2$walletAdapters, _this2$modalConfig$ad6;
|
|
527
|
-
|
|
528
448
|
return ((_this2$walletAdapters = _this2.walletAdapters[adapterName]) === null || _this2$walletAdapters === void 0 ? void 0 : _this2$walletAdapters.type) === ADAPTER_CATEGORY.EXTERNAL && ((_this2$modalConfig$ad6 = _this2.modalConfig.adapters) === null || _this2$modalConfig$ad6 === void 0 ? void 0 : _this2$modalConfig$ad6[adapterName].showOnModal);
|
|
529
449
|
});
|
|
530
|
-
|
|
531
450
|
if (hasExternalWallets) {
|
|
532
451
|
this.loginModal.initExternalWalletContainer();
|
|
533
|
-
}
|
|
452
|
+
}
|
|
453
|
+
// variable to check if we have any in app wallets
|
|
534
454
|
// currently all default in app and external wallets can be hidden or shown based on config.
|
|
535
|
-
|
|
536
|
-
|
|
537
455
|
if (!(!hasInAppWallets && hasExternalWallets)) {
|
|
538
456
|
_context3.next = 20;
|
|
539
457
|
break;
|
|
540
458
|
}
|
|
541
|
-
|
|
542
459
|
_context3.next = 20;
|
|
543
460
|
return this.initExternalWalletAdapters(false, {
|
|
544
461
|
showExternalWalletsOnly: true
|
|
545
462
|
});
|
|
546
|
-
|
|
547
463
|
case 20:
|
|
548
464
|
case "end":
|
|
549
465
|
return _context3.stop();
|
|
@@ -551,11 +467,9 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
551
467
|
}
|
|
552
468
|
}, _callee3, this);
|
|
553
469
|
}));
|
|
554
|
-
|
|
555
470
|
function initModal(_x) {
|
|
556
471
|
return _initModal.apply(this, arguments);
|
|
557
472
|
}
|
|
558
|
-
|
|
559
473
|
return initModal;
|
|
560
474
|
}()
|
|
561
475
|
}, {
|
|
@@ -563,7 +477,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
563
477
|
value: function () {
|
|
564
478
|
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
565
479
|
var _this3 = this;
|
|
566
|
-
|
|
567
480
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
568
481
|
while (1) {
|
|
569
482
|
switch (_context4.prev = _context4.next) {
|
|
@@ -572,21 +485,17 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
572
485
|
_context4.next = 2;
|
|
573
486
|
break;
|
|
574
487
|
}
|
|
575
|
-
|
|
576
488
|
return _context4.abrupt("return", this.provider);
|
|
577
|
-
|
|
578
489
|
case 2:
|
|
579
490
|
this.loginModal.open();
|
|
580
491
|
return _context4.abrupt("return", new Promise(function (resolve, reject) {
|
|
581
492
|
_this3.once(ADAPTER_EVENTS.CONNECTED, function () {
|
|
582
493
|
return resolve(_this3.provider);
|
|
583
494
|
});
|
|
584
|
-
|
|
585
495
|
_this3.once(ADAPTER_EVENTS.ERRORED, function (err) {
|
|
586
496
|
return reject(err);
|
|
587
497
|
});
|
|
588
498
|
}));
|
|
589
|
-
|
|
590
499
|
case 4:
|
|
591
500
|
case "end":
|
|
592
501
|
return _context4.stop();
|
|
@@ -594,11 +503,9 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
594
503
|
}
|
|
595
504
|
}, _callee4, this);
|
|
596
505
|
}));
|
|
597
|
-
|
|
598
506
|
function connect() {
|
|
599
507
|
return _connect.apply(this, arguments);
|
|
600
508
|
}
|
|
601
|
-
|
|
602
509
|
return connect;
|
|
603
510
|
}()
|
|
604
511
|
}, {
|
|
@@ -606,8 +513,7 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
606
513
|
value: function () {
|
|
607
514
|
var _initExternalWalletAdapters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(externalWalletsInitialized, options) {
|
|
608
515
|
var _this4 = this;
|
|
609
|
-
|
|
610
|
-
var adaptersConfig, adaptersData, adapterPromises, adapterInitResults, finalAdaptersConfig;
|
|
516
|
+
var adaptersConfig;
|
|
611
517
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
612
518
|
while (1) {
|
|
613
519
|
switch (_context6.prev = _context6.next) {
|
|
@@ -616,119 +522,75 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
616
522
|
_context6.next = 2;
|
|
617
523
|
break;
|
|
618
524
|
}
|
|
619
|
-
|
|
620
525
|
return _context6.abrupt("return");
|
|
621
|
-
|
|
622
526
|
case 2:
|
|
623
527
|
adaptersConfig = {};
|
|
624
|
-
|
|
625
|
-
adapterPromises = Object.keys(this.walletAdapters).map( /*#__PURE__*/function () {
|
|
528
|
+
Object.keys(this.walletAdapters).forEach( /*#__PURE__*/function () {
|
|
626
529
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(adapterName) {
|
|
627
530
|
var adapter;
|
|
628
531
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
629
532
|
while (1) {
|
|
630
533
|
switch (_context5.prev = _context5.next) {
|
|
631
534
|
case 0:
|
|
632
|
-
_context5.prev = 0;
|
|
633
535
|
adapter = _this4.walletAdapters[adapterName];
|
|
634
|
-
|
|
635
536
|
if (!((adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.EXTERNAL)) {
|
|
636
|
-
_context5.next =
|
|
537
|
+
_context5.next = 9;
|
|
637
538
|
break;
|
|
638
539
|
}
|
|
639
|
-
|
|
640
540
|
log.debug("init external wallet", _this4.cachedAdapter, adapterName);
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
541
|
+
_this4.subscribeToAdapterEvents(adapter);
|
|
542
|
+
// we are not initializing cached adapter here as it is already being initialized in initModal before.
|
|
645
543
|
if (!(_this4.cachedAdapter === adapterName)) {
|
|
646
|
-
_context5.next =
|
|
544
|
+
_context5.next = 6;
|
|
647
545
|
break;
|
|
648
546
|
}
|
|
649
|
-
|
|
650
547
|
return _context5.abrupt("return");
|
|
651
|
-
|
|
652
|
-
case 7:
|
|
548
|
+
case 6:
|
|
653
549
|
if (!(adapter.status === ADAPTER_STATUS.NOT_READY)) {
|
|
654
|
-
_context5.next =
|
|
550
|
+
_context5.next = 9;
|
|
655
551
|
break;
|
|
656
552
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return Promise.race([adapter.init({
|
|
553
|
+
_context5.next = 9;
|
|
554
|
+
return adapter.init({
|
|
660
555
|
autoConnect: _this4.cachedAdapter === adapterName
|
|
661
556
|
}).then(function () {
|
|
662
557
|
adaptersConfig[adapterName] = _this4.modalConfig.adapters[adapterName];
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
})
|
|
670
|
-
|
|
671
|
-
case 10:
|
|
672
|
-
return _context5.abrupt("return", _context5.sent);
|
|
673
|
-
|
|
674
|
-
case 11:
|
|
675
|
-
_context5.next = 16;
|
|
676
|
-
break;
|
|
677
|
-
|
|
678
|
-
case 13:
|
|
679
|
-
_context5.prev = 13;
|
|
680
|
-
_context5.t0 = _context5["catch"](0);
|
|
681
|
-
log.error(_context5.t0, "error while initializing adapter");
|
|
682
|
-
|
|
683
|
-
case 16:
|
|
558
|
+
_this4.loginModal.addWalletLogins(adaptersConfig, {
|
|
559
|
+
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
560
|
+
});
|
|
561
|
+
return undefined;
|
|
562
|
+
}).catch(function (error) {
|
|
563
|
+
return log.error(error, "error while initializing adapter");
|
|
564
|
+
});
|
|
565
|
+
case 9:
|
|
684
566
|
case "end":
|
|
685
567
|
return _context5.stop();
|
|
686
568
|
}
|
|
687
569
|
}
|
|
688
|
-
}, _callee5
|
|
570
|
+
}, _callee5);
|
|
689
571
|
}));
|
|
690
|
-
|
|
691
572
|
return function (_x6) {
|
|
692
573
|
return _ref3.apply(this, arguments);
|
|
693
574
|
};
|
|
694
575
|
}());
|
|
695
|
-
|
|
696
|
-
return Promise.all(adapterPromises);
|
|
697
|
-
|
|
698
|
-
case 7:
|
|
699
|
-
adapterInitResults = _context6.sent;
|
|
700
|
-
finalAdaptersConfig = {};
|
|
701
|
-
adapterInitResults.forEach(function (result) {
|
|
702
|
-
if (result) {
|
|
703
|
-
finalAdaptersConfig[result] = adaptersConfig[result];
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
this.loginModal.addWalletLogins(finalAdaptersConfig, {
|
|
707
|
-
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
708
|
-
});
|
|
709
|
-
|
|
710
|
-
case 11:
|
|
576
|
+
case 4:
|
|
711
577
|
case "end":
|
|
712
578
|
return _context6.stop();
|
|
713
579
|
}
|
|
714
580
|
}
|
|
715
581
|
}, _callee6, this);
|
|
716
582
|
}));
|
|
717
|
-
|
|
718
583
|
function initExternalWalletAdapters(_x4, _x5) {
|
|
719
584
|
return _initExternalWalletAdapters.apply(this, arguments);
|
|
720
585
|
}
|
|
721
|
-
|
|
722
586
|
return initExternalWalletAdapters;
|
|
723
587
|
}()
|
|
724
588
|
}, {
|
|
725
589
|
key: "initializeInAppWallet",
|
|
726
590
|
value: function initializeInAppWallet(adapterName) {
|
|
727
591
|
log.info("adapterInitResults", adapterName);
|
|
728
|
-
|
|
729
592
|
if (this.walletAdapters[adapterName].type === ADAPTER_CATEGORY.IN_APP) {
|
|
730
593
|
var _this$modalConfig$ada, _this$options$uiConfi4;
|
|
731
|
-
|
|
732
594
|
this.loginModal.addSocialLogins(adapterName, getAdapterSocialLogins(adapterName, this.walletAdapters[adapterName], (_this$modalConfig$ada = this.modalConfig.adapters[adapterName]) === null || _this$modalConfig$ada === void 0 ? void 0 : _this$modalConfig$ada.loginMethods), ((_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.loginMethodsOrder) || OPENLOGIN_PROVIDERS);
|
|
733
595
|
}
|
|
734
596
|
}
|
|
@@ -736,7 +598,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
736
598
|
key: "subscribeToLoginModalEvents",
|
|
737
599
|
value: function subscribeToLoginModalEvents() {
|
|
738
600
|
var _this5 = this;
|
|
739
|
-
|
|
740
601
|
this.loginModal.on(LOGIN_MODAL_EVENTS.LOGIN, /*#__PURE__*/function () {
|
|
741
602
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
|
|
742
603
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
@@ -746,16 +607,13 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
746
607
|
_context7.prev = 0;
|
|
747
608
|
_context7.next = 3;
|
|
748
609
|
return _this5.connectTo(params.adapter, params.loginParams);
|
|
749
|
-
|
|
750
610
|
case 3:
|
|
751
611
|
_context7.next = 8;
|
|
752
612
|
break;
|
|
753
|
-
|
|
754
613
|
case 5:
|
|
755
614
|
_context7.prev = 5;
|
|
756
615
|
_context7.t0 = _context7["catch"](0);
|
|
757
616
|
log.error("Error while connecting to adapter: ".concat(params.adapter), _context7.t0);
|
|
758
|
-
|
|
759
617
|
case 8:
|
|
760
618
|
case "end":
|
|
761
619
|
return _context7.stop();
|
|
@@ -763,7 +621,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
763
621
|
}
|
|
764
622
|
}, _callee7, null, [[0, 5]]);
|
|
765
623
|
}));
|
|
766
|
-
|
|
767
624
|
return function (_x7) {
|
|
768
625
|
return _ref4.apply(this, arguments);
|
|
769
626
|
};
|
|
@@ -776,7 +633,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
776
633
|
case 0:
|
|
777
634
|
_context8.next = 2;
|
|
778
635
|
return _this5.initExternalWalletAdapters(params.externalWalletsInitialized);
|
|
779
|
-
|
|
780
636
|
case 2:
|
|
781
637
|
case "end":
|
|
782
638
|
return _context8.stop();
|
|
@@ -784,7 +640,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
784
640
|
}
|
|
785
641
|
}, _callee8);
|
|
786
642
|
}));
|
|
787
|
-
|
|
788
643
|
return function (_x8) {
|
|
789
644
|
return _ref5.apply(this, arguments);
|
|
790
645
|
};
|
|
@@ -797,16 +652,13 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
797
652
|
_context9.prev = 0;
|
|
798
653
|
_context9.next = 3;
|
|
799
654
|
return _this5.logout();
|
|
800
|
-
|
|
801
655
|
case 3:
|
|
802
656
|
_context9.next = 8;
|
|
803
657
|
break;
|
|
804
|
-
|
|
805
658
|
case 5:
|
|
806
659
|
_context9.prev = 5;
|
|
807
660
|
_context9.t0 = _context9["catch"](0);
|
|
808
661
|
log.error("Error while disconnecting", _context9.t0);
|
|
809
|
-
|
|
810
662
|
case 8:
|
|
811
663
|
case "end":
|
|
812
664
|
return _context9.stop();
|
|
@@ -817,18 +669,14 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
817
669
|
this.loginModal.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, /*#__PURE__*/function () {
|
|
818
670
|
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(visibility) {
|
|
819
671
|
var _this5$walletAdapters;
|
|
820
|
-
|
|
821
672
|
var walletConnectStatus;
|
|
822
673
|
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
823
674
|
while (1) {
|
|
824
675
|
switch (_context10.prev = _context10.next) {
|
|
825
676
|
case 0:
|
|
826
677
|
log.debug("is login modal visible", visibility);
|
|
827
|
-
|
|
828
678
|
_this5.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
|
|
829
|
-
|
|
830
679
|
walletConnectStatus = (_this5$walletAdapters = _this5.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1]) === null || _this5$walletAdapters === void 0 ? void 0 : _this5$walletAdapters.status;
|
|
831
|
-
|
|
832
680
|
if (visibility && walletConnectStatus === ADAPTER_STATUS.READY) {
|
|
833
681
|
// refreshing session for wallet connect whenever modal is opened.
|
|
834
682
|
try {
|
|
@@ -837,7 +685,6 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
837
685
|
log.error("Error while disconnecting to wallet connect in core", error);
|
|
838
686
|
}
|
|
839
687
|
}
|
|
840
|
-
|
|
841
688
|
case 4:
|
|
842
689
|
case "end":
|
|
843
690
|
return _context10.stop();
|
|
@@ -845,14 +692,12 @@ var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
|
|
|
845
692
|
}
|
|
846
693
|
}, _callee10);
|
|
847
694
|
}));
|
|
848
|
-
|
|
849
695
|
return function (_x9) {
|
|
850
696
|
return _ref7.apply(this, arguments);
|
|
851
697
|
};
|
|
852
698
|
}());
|
|
853
699
|
}
|
|
854
700
|
}]);
|
|
855
|
-
|
|
856
701
|
return Web3Auth;
|
|
857
702
|
}(Web3AuthCore);
|
|
858
703
|
|