@web3auth/modal 4.5.0-beta.0 → 4.5.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/dist/modal.esm.js CHANGED
@@ -1,229 +1,197 @@
1
+ import { CHAIN_NAMESPACES, SOLANA_ADAPTERS, EVM_ADAPTERS, getChainConfig, WALLET_ADAPTERS, log, ADAPTER_CATEGORY, ADAPTER_STATUS, ADAPTER_EVENTS } from '@web3auth/base';
1
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
- import { CHAIN_NAMESPACES, SOLANA_ADAPTERS, EVM_ADAPTERS, WALLET_ADAPTERS, getChainConfig, ADAPTER_CATEGORY, log, ADAPTER_STATUS, ADAPTER_EVENTS } from '@web3auth/base';
3
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
- import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
5
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
6
- import _createClass from '@babel/runtime/helpers/createClass';
7
- import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
8
- import _get from '@babel/runtime/helpers/get';
9
- import _inherits from '@babel/runtime/helpers/inherits';
10
- import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
11
- import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
12
- import _regeneratorRuntime from '@babel/runtime/regenerator';
13
3
  import { Web3AuthCore } from '@web3auth/core';
14
4
  import { LoginModal, getAdapterSocialLogins, OPENLOGIN_PROVIDERS, LOGIN_MODAL_EVENTS } from '@web3auth/ui';
15
5
 
16
- var _adapters, _adapters2;
17
- var defaultSolanaDappModalConfig = {
6
+ const defaultSolanaDappModalConfig = {
18
7
  chainNamespace: CHAIN_NAMESPACES.SOLANA,
19
- adapters: (_adapters = {}, _defineProperty(_adapters, SOLANA_ADAPTERS.TORUS_SOLANA, {
20
- label: "Torus Wallet",
21
- showOnModal: true,
22
- showOnMobile: true,
23
- showOnDesktop: true
24
- }), _defineProperty(_adapters, SOLANA_ADAPTERS.OPENLOGIN, {
25
- label: "OpenLogin",
26
- showOnModal: true,
27
- showOnMobile: true,
28
- showOnDesktop: true
29
- }), _defineProperty(_adapters, SOLANA_ADAPTERS.PHANTOM, {
30
- label: "Phantom",
31
- showOnModal: true,
32
- showOnMobile: false,
33
- showOnDesktop: true
34
- }), _adapters)
8
+ adapters: {
9
+ [SOLANA_ADAPTERS.TORUS_SOLANA]: {
10
+ label: "Torus Wallet",
11
+ showOnModal: true,
12
+ showOnMobile: true,
13
+ showOnDesktop: true
14
+ },
15
+ [SOLANA_ADAPTERS.OPENLOGIN]: {
16
+ label: "OpenLogin",
17
+ showOnModal: true,
18
+ showOnMobile: true,
19
+ showOnDesktop: true
20
+ },
21
+ [SOLANA_ADAPTERS.PHANTOM]: {
22
+ label: "Phantom",
23
+ showOnModal: true,
24
+ showOnMobile: true,
25
+ showOnDesktop: true
26
+ }
27
+ }
35
28
  };
36
- var defaultEvmDappModalConfig = {
29
+ const defaultEvmDappModalConfig = {
37
30
  chainNamespace: CHAIN_NAMESPACES.EIP155,
38
- adapters: (_adapters2 = {}, _defineProperty(_adapters2, EVM_ADAPTERS.TORUS_EVM, {
39
- label: "Torus Wallet",
40
- showOnModal: true,
41
- showOnMobile: true,
42
- showOnDesktop: true
43
- }), _defineProperty(_adapters2, EVM_ADAPTERS.METAMASK, {
44
- label: "MetaMask",
45
- showOnModal: true,
46
- showOnMobile: false,
47
- showOnDesktop: true
48
- }), _defineProperty(_adapters2, EVM_ADAPTERS.OPENLOGIN, {
49
- label: "OpenLogin",
50
- showOnModal: true,
51
- showOnMobile: true,
52
- showOnDesktop: true
53
- }), _defineProperty(_adapters2, EVM_ADAPTERS.WALLET_CONNECT_V1, {
54
- label: "Wallet Connect",
55
- showOnModal: true,
56
- showOnMobile: true,
57
- showOnDesktop: true
58
- }), _adapters2)
31
+ adapters: {
32
+ [EVM_ADAPTERS.TORUS_EVM]: {
33
+ label: "Torus Wallet",
34
+ showOnModal: true,
35
+ showOnMobile: true,
36
+ showOnDesktop: true
37
+ },
38
+ [EVM_ADAPTERS.METAMASK]: {
39
+ label: "MetaMask",
40
+ showOnModal: true,
41
+ showOnMobile: true,
42
+ showOnDesktop: true
43
+ },
44
+ [EVM_ADAPTERS.OPENLOGIN]: {
45
+ label: "OpenLogin",
46
+ showOnModal: true,
47
+ showOnMobile: true,
48
+ showOnDesktop: true
49
+ },
50
+ [EVM_ADAPTERS.WALLET_CONNECT_V1]: {
51
+ label: "Wallet Connect",
52
+ showOnModal: true,
53
+ showOnMobile: true,
54
+ showOnDesktop: true
55
+ }
56
+ }
59
57
  };
60
- var defaultSolanaWalletModalConfig = {
58
+ const defaultSolanaWalletModalConfig = {
61
59
  chainNamespace: CHAIN_NAMESPACES.SOLANA,
62
- adapters: _defineProperty({}, SOLANA_ADAPTERS.OPENLOGIN, {
63
- label: "OpenLogin",
64
- showOnModal: true,
65
- showOnMobile: true,
66
- showOnDesktop: true
67
- })
60
+ adapters: {
61
+ [SOLANA_ADAPTERS.OPENLOGIN]: {
62
+ label: "OpenLogin",
63
+ showOnModal: true,
64
+ showOnMobile: true,
65
+ showOnDesktop: true
66
+ }
67
+ }
68
68
  };
69
- var defaultEvmWalletModalConfig = {
69
+ const defaultEvmWalletModalConfig = {
70
70
  chainNamespace: CHAIN_NAMESPACES.EIP155,
71
- adapters: _defineProperty({}, EVM_ADAPTERS.OPENLOGIN, {
72
- label: "OpenLogin",
73
- showOnModal: true,
74
- showOnMobile: true,
75
- showOnDesktop: true
76
- })
71
+ adapters: {
72
+ [EVM_ADAPTERS.OPENLOGIN]: {
73
+ label: "OpenLogin",
74
+ showOnModal: true,
75
+ showOnMobile: true,
76
+ showOnDesktop: true
77
+ }
78
+ }
77
79
  };
78
- var defaultOtherModalConfig = {
80
+ const defaultOtherModalConfig = {
79
81
  chainNamespace: CHAIN_NAMESPACES.OTHER,
80
- adapters: _defineProperty({}, EVM_ADAPTERS.OPENLOGIN, {
81
- label: "OpenLogin",
82
- showOnModal: true,
83
- showOnMobile: true,
84
- showOnDesktop: true
85
- })
82
+ adapters: {
83
+ [EVM_ADAPTERS.OPENLOGIN]: {
84
+ label: "OpenLogin",
85
+ showOnModal: true,
86
+ showOnMobile: true,
87
+ showOnDesktop: true
88
+ }
89
+ }
86
90
  };
87
91
 
88
92
  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
93
  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; }
90
- // warning: this function is not compatible with "OTHER" chainnamespace.
91
- var getDefaultAdapterModule = /*#__PURE__*/function () {
92
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
93
- 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
- return _regeneratorRuntime.wrap(function _callee$(_context) {
95
- while (1) {
96
- switch (_context.prev = _context.next) {
97
- case 0:
98
- name = params.name, customChainConfig = params.customChainConfig, clientId = params.clientId;
99
- if (Object.values(CHAIN_NAMESPACES).includes(customChainConfig.chainNamespace)) {
100
- _context.next = 3;
101
- break;
102
- }
103
- throw new Error("Invalid chainNamespace: ".concat(customChainConfig.chainNamespace));
104
- case 3:
105
- finalChainConfig = _objectSpread$1(_objectSpread$1({}, getChainConfig(customChainConfig.chainNamespace, customChainConfig === null || customChainConfig === void 0 ? void 0 : customChainConfig.chainId)), customChainConfig || {});
106
- if (!(name === WALLET_ADAPTERS.TORUS_EVM)) {
107
- _context.next = 13;
108
- break;
109
- }
110
- _context.next = 7;
111
- return import('@web3auth/torus-evm-adapter');
112
- case 7:
113
- _yield$import = _context.sent;
114
- TorusWalletAdapter = _yield$import.TorusWalletAdapter;
115
- adapter = new TorusWalletAdapter({
116
- chainConfig: finalChainConfig,
117
- clientId: clientId
118
- });
119
- return _context.abrupt("return", adapter);
120
- case 13:
121
- if (!(name === WALLET_ADAPTERS.TORUS_SOLANA)) {
122
- _context.next = 22;
123
- break;
124
- }
125
- _context.next = 16;
126
- return import('@web3auth/torus-solana-adapter');
127
- case 16:
128
- _yield$import2 = _context.sent;
129
- SolanaWalletAdapter = _yield$import2.SolanaWalletAdapter;
130
- _adapter = new SolanaWalletAdapter({
131
- chainConfig: finalChainConfig,
132
- clientId: clientId
133
- });
134
- return _context.abrupt("return", _adapter);
135
- case 22:
136
- if (!(name === WALLET_ADAPTERS.METAMASK)) {
137
- _context.next = 31;
138
- break;
139
- }
140
- _context.next = 25;
141
- return import('@web3auth/metamask-adapter');
142
- case 25:
143
- _yield$import3 = _context.sent;
144
- MetamaskAdapter = _yield$import3.MetamaskAdapter;
145
- _adapter2 = new MetamaskAdapter({
146
- chainConfig: finalChainConfig,
147
- clientId: clientId
148
- });
149
- return _context.abrupt("return", _adapter2);
150
- case 31:
151
- if (!(name === WALLET_ADAPTERS.PHANTOM)) {
152
- _context.next = 40;
153
- break;
154
- }
155
- _context.next = 34;
156
- return import('@web3auth/phantom-adapter');
157
- case 34:
158
- _yield$import4 = _context.sent;
159
- PhantomAdapter = _yield$import4.PhantomAdapter;
160
- _adapter3 = new PhantomAdapter({
161
- chainConfig: finalChainConfig,
162
- clientId: clientId
163
- });
164
- return _context.abrupt("return", _adapter3);
165
- case 40:
166
- if (!(name === WALLET_ADAPTERS.WALLET_CONNECT_V1)) {
167
- _context.next = 49;
168
- break;
169
- }
170
- _context.next = 43;
171
- return import('@web3auth/wallet-connect-v1-adapter');
172
- case 43:
173
- _yield$import5 = _context.sent;
174
- WalletConnectV1Adapter = _yield$import5.WalletConnectV1Adapter;
175
- _adapter4 = new WalletConnectV1Adapter({
176
- chainConfig: finalChainConfig,
177
- clientId: clientId
178
- });
179
- return _context.abrupt("return", _adapter4);
180
- case 49:
181
- if (!(name === WALLET_ADAPTERS.OPENLOGIN)) {
182
- _context.next = 58;
183
- break;
184
- }
185
- _context.next = 52;
186
- return import('@web3auth/openlogin-adapter');
187
- case 52:
188
- _yield$import6 = _context.sent;
189
- OpenloginAdapter = _yield$import6.OpenloginAdapter;
190
- getOpenloginDefaultOptions = _yield$import6.getOpenloginDefaultOptions;
191
- defaultOptions = getOpenloginDefaultOptions();
192
- _adapter5 = new OpenloginAdapter(_objectSpread$1(_objectSpread$1({}, defaultOptions), {}, {
193
- clientId: clientId,
194
- chainConfig: _objectSpread$1({}, finalChainConfig),
195
- adapterSettings: _objectSpread$1(_objectSpread$1({}, defaultOptions.adapterSettings), {}, {
196
- clientId: clientId
197
- })
198
- }));
199
- return _context.abrupt("return", _adapter5);
200
- case 58:
201
- throw new Error("Invalid wallet adapter name");
202
- case 59:
203
- case "end":
204
- return _context.stop();
205
- }
206
- }
207
- }, _callee);
208
- }));
209
- return function getDefaultAdapterModule(_x) {
210
- return _ref.apply(this, arguments);
211
- };
212
- }();
94
+ // warning: this function is not compatible with "OTHER" chain namespace.
95
+ const getDefaultAdapterModule = async params => {
96
+ const {
97
+ name,
98
+ customChainConfig,
99
+ clientId,
100
+ sessionTime,
101
+ web3AuthNetwork
102
+ } = params;
103
+ if (!Object.values(CHAIN_NAMESPACES).includes(customChainConfig.chainNamespace)) throw new Error(`Invalid chainNamespace: ${customChainConfig.chainNamespace}`);
104
+ const finalChainConfig = _objectSpread$1(_objectSpread$1({}, getChainConfig(customChainConfig.chainNamespace, customChainConfig === null || customChainConfig === void 0 ? void 0 : customChainConfig.chainId)), customChainConfig || {});
105
+ if (name === WALLET_ADAPTERS.TORUS_EVM) {
106
+ const {
107
+ TorusWalletAdapter
108
+ } = await import('@web3auth/torus-evm-adapter');
109
+ const adapter = new TorusWalletAdapter({
110
+ chainConfig: finalChainConfig,
111
+ clientId,
112
+ sessionTime,
113
+ web3AuthNetwork
114
+ });
115
+ return adapter;
116
+ } else if (name === WALLET_ADAPTERS.TORUS_SOLANA) {
117
+ const {
118
+ SolanaWalletAdapter
119
+ } = await import('@web3auth/torus-solana-adapter');
120
+ const adapter = new SolanaWalletAdapter({
121
+ chainConfig: finalChainConfig,
122
+ clientId,
123
+ sessionTime,
124
+ web3AuthNetwork
125
+ });
126
+ return adapter;
127
+ } else if (name === WALLET_ADAPTERS.METAMASK) {
128
+ const {
129
+ MetamaskAdapter
130
+ } = await import('@web3auth/metamask-adapter');
131
+ const adapter = new MetamaskAdapter({
132
+ chainConfig: finalChainConfig,
133
+ clientId,
134
+ sessionTime,
135
+ web3AuthNetwork
136
+ });
137
+ return adapter;
138
+ } else if (name === WALLET_ADAPTERS.PHANTOM) {
139
+ const {
140
+ PhantomAdapter
141
+ } = await import('@web3auth/phantom-adapter');
142
+ const adapter = new PhantomAdapter({
143
+ chainConfig: finalChainConfig,
144
+ clientId,
145
+ sessionTime,
146
+ web3AuthNetwork
147
+ });
148
+ return adapter;
149
+ } else if (name === WALLET_ADAPTERS.WALLET_CONNECT_V1) {
150
+ const {
151
+ WalletConnectV1Adapter
152
+ } = await import('@web3auth/wallet-connect-v1-adapter');
153
+ const adapter = new WalletConnectV1Adapter({
154
+ chainConfig: finalChainConfig,
155
+ clientId,
156
+ sessionTime,
157
+ web3AuthNetwork
158
+ });
159
+ return adapter;
160
+ } else if (name === WALLET_ADAPTERS.OPENLOGIN) {
161
+ const {
162
+ OpenloginAdapter,
163
+ getOpenloginDefaultOptions
164
+ } = await import('@web3auth/openlogin-adapter');
165
+ const defaultOptions = getOpenloginDefaultOptions();
166
+ const adapter = new OpenloginAdapter(_objectSpread$1(_objectSpread$1({}, defaultOptions), {}, {
167
+ clientId,
168
+ chainConfig: _objectSpread$1({}, finalChainConfig),
169
+ adapterSettings: _objectSpread$1(_objectSpread$1({}, defaultOptions.adapterSettings), {}, {
170
+ clientId,
171
+ network: web3AuthNetwork
172
+ }),
173
+ sessionTime,
174
+ web3AuthNetwork
175
+ }));
176
+ return adapter;
177
+ }
178
+ throw new Error("Invalid wallet adapter name");
179
+ };
213
180
 
214
- var languageMap = {
181
+ const languageMap = {
215
182
  en: "english",
216
183
  de: "german",
217
184
  ja: "japanese",
218
185
  ko: "korean",
219
186
  zh: "mandarin",
220
187
  es: "spanish",
221
- fr: "french"
188
+ fr: "french",
189
+ pt: "portuguese"
222
190
  };
223
- var getUserLanguage = function getUserLanguage(defaultLanguage) {
224
- var userLanguage = defaultLanguage;
191
+ const getUserLanguage = defaultLanguage => {
192
+ let userLanguage = defaultLanguage;
225
193
  if (!userLanguage) {
226
- var browserLanguage = typeof window !== "undefined" ? window.navigator.userLanguage || window.navigator.language || "en-US" : "en-US";
194
+ const browserLanguage = typeof window !== "undefined" ? window.navigator.userLanguage || window.navigator.language || "en-US" : "en-US";
227
195
  userLanguage = browserLanguage.split("-")[0];
228
196
  }
229
197
  return Object.prototype.hasOwnProperty.call(languageMap, userLanguage) ? userLanguage : "en";
@@ -231,482 +199,240 @@ var getUserLanguage = function getUserLanguage(defaultLanguage) {
231
199
 
232
200
  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; }
233
201
  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; }
234
- 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); }; }
235
- 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; } }
236
- var Web3Auth = /*#__PURE__*/function (_Web3AuthCore) {
237
- _inherits(Web3Auth, _Web3AuthCore);
238
- var _super = _createSuper(Web3Auth);
239
- function Web3Auth(options) {
202
+ class Web3Auth extends Web3AuthCore {
203
+ constructor(options) {
240
204
  var _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3, _this$options$uiConfi4, _this$options$uiConfi5, _this$options$uiConfi6;
241
- var _this;
242
- _classCallCheck(this, Web3Auth);
243
- _this = _super.call(this, options);
244
- _defineProperty(_assertThisInitialized(_this), "loginModal", void 0);
245
- _defineProperty(_assertThisInitialized(_this), "options", void 0);
246
- _defineProperty(_assertThisInitialized(_this), "modalConfig", defaultEvmDappModalConfig);
247
- _this.options = _objectSpread({}, options);
248
- var providedChainConfig = _this.options.chainConfig;
205
+ super(options);
206
+ _defineProperty(this, "loginModal", void 0);
207
+ _defineProperty(this, "options", void 0);
208
+ _defineProperty(this, "modalConfig", defaultEvmDappModalConfig);
209
+ this.options = _objectSpread({}, options);
210
+ const providedChainConfig = this.options.chainConfig;
249
211
  if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
250
212
  if (options.authMode === "WALLET") {
251
213
  // default config for solana wallet modal
252
- _this.modalConfig = defaultSolanaWalletModalConfig;
214
+ this.modalConfig = defaultSolanaWalletModalConfig;
253
215
  } else {
254
216
  // default config for solana dapp modal
255
- _this.modalConfig = defaultSolanaDappModalConfig;
217
+ this.modalConfig = defaultSolanaDappModalConfig;
256
218
  }
257
219
  } else if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
258
220
  if (options.authMode === "WALLET") {
259
221
  // default config for evm wallet modal
260
- _this.modalConfig = defaultEvmWalletModalConfig;
222
+ this.modalConfig = defaultEvmWalletModalConfig;
261
223
  } else {
262
224
  // default config for evm dapp modal
263
- _this.modalConfig = defaultEvmDappModalConfig;
225
+ this.modalConfig = defaultEvmDappModalConfig;
264
226
  }
265
227
  } else if (providedChainConfig.chainNamespace === CHAIN_NAMESPACES.OTHER) {
266
- _this.modalConfig = defaultOtherModalConfig;
228
+ this.modalConfig = defaultOtherModalConfig;
267
229
  } else {
268
- throw new Error("Invalid chainNamespace provided: ".concat(providedChainConfig.chainNamespace));
230
+ throw new Error(`Invalid chainNamespace provided: ${providedChainConfig.chainNamespace}`);
269
231
  }
270
232
  // get userLanguage
271
- var defaultLanguage = getUserLanguage((_this$options$uiConfi = _this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.defaultLanguage);
272
- _this.loginModal = new LoginModal({
273
- theme: (_this$options$uiConfi2 = _this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.theme,
274
- appName: ((_this$options$uiConfi3 = _this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.appName) || "blockchain",
275
- appLogo: ((_this$options$uiConfi4 = _this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.appLogo) || "",
276
- adapterListener: _assertThisInitialized(_this),
277
- displayErrorsOnModal: (_this$options$uiConfi5 = _this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.displayErrorsOnModal,
278
- defaultLanguage: defaultLanguage,
279
- modalZIndex: ((_this$options$uiConfi6 = _this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.modalZIndex) || "99998"
233
+ const defaultLanguage = getUserLanguage((_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.defaultLanguage);
234
+ this.loginModal = new LoginModal({
235
+ theme: (_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.theme,
236
+ appName: ((_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.appName) || "blockchain",
237
+ appLogo: ((_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.appLogo) || "",
238
+ adapterListener: this,
239
+ displayErrorsOnModal: (_this$options$uiConfi5 = this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.displayErrorsOnModal,
240
+ defaultLanguage,
241
+ modalZIndex: ((_this$options$uiConfi6 = this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.modalZIndex) || "99998"
280
242
  });
281
- _this.subscribeToLoginModalEvents();
282
- return _this;
243
+ this.subscribeToLoginModalEvents();
283
244
  }
284
- _createClass(Web3Auth, [{
285
- key: "initModal",
286
- value: function () {
287
- var _initModal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
288
- var _this2 = this;
289
- var providedChainConfig, allAdapters, adapterConfigurationPromises, adapterNames, hasInAppWallets, initPromises, hasExternalWallets;
290
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
291
- while (1) {
292
- switch (_context3.prev = _context3.next) {
293
- case 0:
294
- _get(_getPrototypeOf(Web3Auth.prototype), "checkInitRequirements", this).call(this);
295
- _context3.next = 3;
296
- return this.loginModal.initModal();
297
- case 3:
298
- providedChainConfig = this.options.chainConfig; // merge default adapters with the custom configured adapters.
299
- allAdapters = _toConsumableArray(new Set([].concat(_toConsumableArray(Object.keys(this.modalConfig.adapters || {})), _toConsumableArray(Object.keys(this.walletAdapters)))));
300
- adapterConfigurationPromises = allAdapters.map( /*#__PURE__*/function () {
301
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(adapterName) {
302
- var _this2$modalConfig$ad, _params$modalConfig, _this2$modalConfig$ad2, _this2$modalConfig$ad3;
303
- var adapterConfig, adapter, ad, _this2$modalConfig$ad4, _this2$coreOptions$ch, chainConfig;
304
- return _regeneratorRuntime.wrap(function _callee$(_context) {
305
- while (1) {
306
- switch (_context.prev = _context.next) {
307
- case 0:
308
- // start with the default config of adapter.
309
- adapterConfig = ((_this2$modalConfig$ad = _this2.modalConfig.adapters) === null || _this2$modalConfig$ad === void 0 ? void 0 : _this2$modalConfig$ad[adapterName]) || {
310
- label: adapterName,
311
- showOnModal: true,
312
- showOnMobile: true,
313
- showOnDesktop: true
314
- }; // override the default config of adapter if some config is being provided by the user.
315
- if (params !== null && params !== void 0 && (_params$modalConfig = params.modalConfig) !== null && _params$modalConfig !== void 0 && _params$modalConfig[adapterName]) {
316
- adapterConfig = _objectSpread(_objectSpread({}, adapterConfig), params.modalConfig[adapterName]);
317
- }
318
- _this2.modalConfig.adapters[adapterName] = adapterConfig;
319
- // check if adapter is configured/added by user and exist in walletAdapters map.
320
- adapter = _this2.walletAdapters[adapterName];
321
- 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);
322
- // if adapter is not custom configured then check if it is available in default adapters.
323
- // and if adapter is not hidden by user
324
- if (!(!adapter && (_this2$modalConfig$ad3 = _this2.modalConfig.adapters) !== null && _this2$modalConfig$ad3 !== void 0 && _this2$modalConfig$ad3[adapterName].showOnModal)) {
325
- _context.next = 13;
326
- break;
327
- }
328
- _context.next = 8;
329
- return getDefaultAdapterModule({
330
- name: adapterName,
331
- customChainConfig: _this2.options.chainConfig,
332
- clientId: _this2.options.clientId
333
- });
334
- case 8:
335
- ad = _context.sent;
336
- _this2.walletAdapters[adapterName] = ad;
337
- return _context.abrupt("return", adapterName);
338
- case 13:
339
- 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)) {
340
- _context.next = 19;
341
- break;
342
- }
343
- if ((_this2$modalConfig$ad4 = _this2.modalConfig.adapters) !== null && _this2$modalConfig$ad4 !== void 0 && _this2$modalConfig$ad4[adapterName].showOnModal) {
344
- _context.next = 16;
345
- break;
346
- }
347
- return _context.abrupt("return");
348
- case 16:
349
- // add client id to adapter, same web3auth client id can be used in adapter.
350
- // this id is being overridden if user is also passing client id in adapter's constructor.
351
- _this2.walletAdapters[adapterName].setAdapterSettings({
352
- clientId: _this2.options.clientId,
353
- sessionTime: _this2.options.sessionTime,
354
- web3AuthNetwork: _this2.options.web3AuthNetwork
355
- });
356
- // if adapter doesn't have any chainConfig then we will set the chainConfig based of passed chainNamespace
357
- // and chainNamespace.
358
- if (!adapter.chainConfigProxy) {
359
- 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);
360
- _this2.walletAdapters[adapterName].setAdapterSettings({
361
- chainConfig: chainConfig
362
- });
363
- }
364
- return _context.abrupt("return", adapterName);
365
- case 19:
366
- case "end":
367
- return _context.stop();
368
- }
369
- }
370
- }, _callee);
371
- }));
372
- return function (_x2) {
373
- return _ref.apply(this, arguments);
374
- };
375
- }());
376
- _context3.next = 8;
377
- return Promise.all(adapterConfigurationPromises);
378
- case 8:
379
- adapterNames = _context3.sent;
380
- hasInAppWallets = Object.values(this.walletAdapters).some(function (adapter) {
381
- var _this2$modalConfig$ad5;
382
- if (adapter.type !== ADAPTER_CATEGORY.IN_APP) return false;
383
- if (_this2.modalConfig.adapters[adapter.name].showOnModal !== true) return false;
384
- if (!_this2.modalConfig.adapters[adapter.name].loginMethods) return true;
385
- var mergedLoginMethods = getAdapterSocialLogins(adapter.name, _this2.walletAdapters[adapter.name], (_this2$modalConfig$ad5 = _this2.modalConfig.adapters[adapter.name]) === null || _this2$modalConfig$ad5 === void 0 ? void 0 : _this2$modalConfig$ad5.loginMethods);
386
- if (Object.values(mergedLoginMethods).some(function (method) {
387
- return method.showOnModal;
388
- })) return true;
389
- return false;
390
- });
391
- log.debug(hasInAppWallets, this.walletAdapters, "hasInAppWallets");
392
- // Now, initialize the adapters.
393
- initPromises = adapterNames.map( /*#__PURE__*/function () {
394
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(adapterName) {
395
- var adapter;
396
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
397
- while (1) {
398
- switch (_context2.prev = _context2.next) {
399
- case 0:
400
- if (adapterName) {
401
- _context2.next = 2;
402
- break;
403
- }
404
- return _context2.abrupt("return");
405
- case 2:
406
- _context2.prev = 2;
407
- adapter = _this2.walletAdapters[adapterName]; // only initialize a external adapter here if it is a cached adapter.
408
- if (!(_this2.cachedAdapter !== adapterName && adapter.type === ADAPTER_CATEGORY.EXTERNAL)) {
409
- _context2.next = 6;
410
- break;
411
- }
412
- return _context2.abrupt("return");
413
- case 6:
414
- // in-app wallets or cached wallet (being connected or already connected) are initialized first.
415
- // if adapter is configured thn only initialize in app or cached adapter.
416
- // external wallets are initialized on INIT_EXTERNAL_WALLET event.
417
- _this2.subscribeToAdapterEvents(adapter);
418
- if (!(adapter.status === ADAPTER_STATUS.NOT_READY)) {
419
- _context2.next = 10;
420
- break;
421
- }
422
- _context2.next = 10;
423
- return adapter.init({
424
- autoConnect: _this2.cachedAdapter === adapterName
425
- });
426
- case 10:
427
- // note: not adding cachedWallet to modal if it is external wallet.
428
- // adding it later if no in-app wallets are available.
429
- if (adapter.type === ADAPTER_CATEGORY.IN_APP) {
430
- _this2.initializeInAppWallet(adapterName);
431
- }
432
- _context2.next = 16;
433
- break;
434
- case 13:
435
- _context2.prev = 13;
436
- _context2.t0 = _context2["catch"](2);
437
- log.error(_context2.t0, "error while initializing adapter");
438
- case 16:
439
- case "end":
440
- return _context2.stop();
441
- }
442
- }
443
- }, _callee2, null, [[2, 13]]);
444
- }));
445
- return function (_x3) {
446
- return _ref2.apply(this, arguments);
447
- };
448
- }());
449
- this.status = ADAPTER_STATUS.READY;
450
- _context3.next = 15;
451
- return Promise.all(initPromises);
452
- case 15:
453
- hasExternalWallets = allAdapters.some(function (adapterName) {
454
- var _this2$walletAdapters, _this2$modalConfig$ad6;
455
- 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);
456
- });
457
- if (hasExternalWallets) {
458
- this.loginModal.initExternalWalletContainer();
459
- }
460
- // variable to check if we have any in app wallets
461
- // currently all default in app and external wallets can be hidden or shown based on config.
462
- if (!(!hasInAppWallets && hasExternalWallets)) {
463
- _context3.next = 20;
464
- break;
465
- }
466
- _context3.next = 20;
467
- return this.initExternalWalletAdapters(false, {
468
- showExternalWalletsOnly: true
469
- });
470
- case 20:
471
- case "end":
472
- return _context3.stop();
473
- }
474
- }
475
- }, _callee3, this);
476
- }));
477
- function initModal(_x) {
478
- return _initModal.apply(this, arguments);
479
- }
480
- return initModal;
481
- }()
482
- }, {
483
- key: "connect",
484
- value: function () {
485
- var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
486
- var _this3 = this;
487
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
488
- while (1) {
489
- switch (_context4.prev = _context4.next) {
490
- case 0:
491
- if (!this.provider) {
492
- _context4.next = 2;
493
- break;
494
- }
495
- return _context4.abrupt("return", this.provider);
496
- case 2:
497
- this.loginModal.open();
498
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
499
- _this3.once(ADAPTER_EVENTS.CONNECTED, function () {
500
- return resolve(_this3.provider);
501
- });
502
- _this3.once(ADAPTER_EVENTS.ERRORED, function (err) {
503
- return reject(err);
504
- });
505
- }));
506
- case 4:
507
- case "end":
508
- return _context4.stop();
509
- }
510
- }
511
- }, _callee4, this);
512
- }));
513
- function connect() {
514
- return _connect.apply(this, arguments);
245
+ async initModal(params) {
246
+ super.checkInitRequirements();
247
+ await this.loginModal.initModal();
248
+ const providedChainConfig = this.options.chainConfig;
249
+ // merge default adapters with the custom configured adapters.
250
+ const allAdapters = [...new Set([...Object.keys(this.modalConfig.adapters || {}), ...Object.keys(this.walletAdapters)])];
251
+ const adapterConfigurationPromises = allAdapters.map(async adapterName => {
252
+ var _this$modalConfig$ada, _params$modalConfig, _this$modalConfig$ada2, _this$modalConfig$ada3;
253
+ // start with the default config of adapter.
254
+ let adapterConfig = ((_this$modalConfig$ada = this.modalConfig.adapters) === null || _this$modalConfig$ada === void 0 ? void 0 : _this$modalConfig$ada[adapterName]) || {
255
+ label: adapterName,
256
+ showOnModal: true,
257
+ showOnMobile: true,
258
+ showOnDesktop: true
259
+ };
260
+ // override the default config of adapter if some config is being provided by the user.
261
+ if (params !== null && params !== void 0 && (_params$modalConfig = params.modalConfig) !== null && _params$modalConfig !== void 0 && _params$modalConfig[adapterName]) {
262
+ adapterConfig = _objectSpread(_objectSpread({}, adapterConfig), params.modalConfig[adapterName]);
515
263
  }
516
- return connect;
517
- }()
518
- }, {
519
- key: "initExternalWalletAdapters",
520
- value: function () {
521
- var _initExternalWalletAdapters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(externalWalletsInitialized, options) {
522
- var _this4 = this;
523
- var adaptersConfig;
524
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
525
- while (1) {
526
- switch (_context6.prev = _context6.next) {
527
- case 0:
528
- if (!externalWalletsInitialized) {
529
- _context6.next = 2;
530
- break;
531
- }
532
- return _context6.abrupt("return");
533
- case 2:
534
- adaptersConfig = {};
535
- Object.keys(this.walletAdapters).forEach( /*#__PURE__*/function () {
536
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(adapterName) {
537
- var adapter;
538
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
539
- while (1) {
540
- switch (_context5.prev = _context5.next) {
541
- case 0:
542
- adapter = _this4.walletAdapters[adapterName];
543
- if (!((adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.EXTERNAL)) {
544
- _context5.next = 9;
545
- break;
546
- }
547
- log.debug("init external wallet", _this4.cachedAdapter, adapterName);
548
- _this4.subscribeToAdapterEvents(adapter);
549
- // we are not initializing cached adapter here as it is already being initialized in initModal before.
550
- if (!(_this4.cachedAdapter === adapterName)) {
551
- _context5.next = 6;
552
- break;
553
- }
554
- return _context5.abrupt("return");
555
- case 6:
556
- if (!(adapter.status === ADAPTER_STATUS.NOT_READY)) {
557
- _context5.next = 9;
558
- break;
559
- }
560
- _context5.next = 9;
561
- return adapter.init({
562
- autoConnect: _this4.cachedAdapter === adapterName
563
- }).then(function () {
564
- adaptersConfig[adapterName] = _this4.modalConfig.adapters[adapterName];
565
- _this4.loginModal.addWalletLogins(adaptersConfig, {
566
- showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
567
- });
568
- return undefined;
569
- }).catch(function (error) {
570
- return log.error(error, "error while initializing adapter");
571
- });
572
- case 9:
573
- case "end":
574
- return _context5.stop();
575
- }
576
- }
577
- }, _callee5);
578
- }));
579
- return function (_x6) {
580
- return _ref3.apply(this, arguments);
581
- };
582
- }());
583
- case 4:
584
- case "end":
585
- return _context6.stop();
586
- }
587
- }
588
- }, _callee6, this);
589
- }));
590
- function initExternalWalletAdapters(_x4, _x5) {
591
- return _initExternalWalletAdapters.apply(this, arguments);
264
+ this.modalConfig.adapters[adapterName] = adapterConfig;
265
+ // check if adapter is configured/added by user and exist in walletAdapters map.
266
+ const adapter = this.walletAdapters[adapterName];
267
+ log.debug("adapter config", adapterName, (_this$modalConfig$ada2 = this.modalConfig.adapters) === null || _this$modalConfig$ada2 === void 0 ? void 0 : _this$modalConfig$ada2[adapterName].showOnModal, adapter);
268
+ // if adapter is not custom configured then check if it is available in default adapters.
269
+ // and if adapter is not hidden by user
270
+ if (!adapter && (_this$modalConfig$ada3 = this.modalConfig.adapters) !== null && _this$modalConfig$ada3 !== void 0 && _this$modalConfig$ada3[adapterName].showOnModal) {
271
+ // if adapter is not configured and some default configuration is available, use it.
272
+ const ad = await getDefaultAdapterModule({
273
+ name: adapterName,
274
+ customChainConfig: this.options.chainConfig,
275
+ clientId: this.options.clientId,
276
+ sessionTime: this.options.sessionTime,
277
+ web3AuthNetwork: this.options.web3AuthNetwork
278
+ });
279
+ this.walletAdapters[adapterName] = ad;
280
+ return adapterName;
281
+ } else 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 === this.cachedAdapter) {
282
+ var _this$modalConfig$ada4;
283
+ if (!((_this$modalConfig$ada4 = this.modalConfig.adapters) !== null && _this$modalConfig$ada4 !== void 0 && _this$modalConfig$ada4[adapterName].showOnModal)) return;
284
+ // add client id to adapter, same web3auth client id can be used in adapter.
285
+ // this id is being overridden if user is also passing client id in adapter's constructor.
286
+ this.walletAdapters[adapterName].setAdapterSettings({
287
+ clientId: this.options.clientId,
288
+ sessionTime: this.options.sessionTime,
289
+ web3AuthNetwork: this.options.web3AuthNetwork
290
+ });
291
+ // if adapter doesn't have any chainConfig then we will set the chainConfig based of passed chainNamespace
292
+ // and chainNamespace.
293
+ if (!adapter.chainConfigProxy) {
294
+ var _this$coreOptions$cha;
295
+ const chainConfig = _objectSpread(_objectSpread({}, getChainConfig(providedChainConfig.chainNamespace, (_this$coreOptions$cha = this.coreOptions.chainConfig) === null || _this$coreOptions$cha === void 0 ? void 0 : _this$coreOptions$cha.chainId)), this.coreOptions.chainConfig);
296
+ this.walletAdapters[adapterName].setAdapterSettings({
297
+ chainConfig
298
+ });
299
+ }
300
+ return adapterName;
592
301
  }
593
- return initExternalWalletAdapters;
594
- }()
595
- }, {
596
- key: "initializeInAppWallet",
597
- value: function initializeInAppWallet(adapterName) {
598
- log.info("adapterInitResults", adapterName);
599
- if (this.walletAdapters[adapterName].type === ADAPTER_CATEGORY.IN_APP) {
600
- var _this$modalConfig$ada, _this$options$uiConfi7;
601
- 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$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.loginMethodsOrder) || OPENLOGIN_PROVIDERS);
302
+ });
303
+ const adapterNames = await Promise.all(adapterConfigurationPromises);
304
+ const hasInAppWallets = Object.values(this.walletAdapters).some(adapter => {
305
+ var _this$modalConfig$ada5, _this$modalConfig$ada6, _this$modalConfig$ada7, _this$modalConfig$ada8, _this$modalConfig$ada9;
306
+ if (adapter.type !== ADAPTER_CATEGORY.IN_APP) return false;
307
+ if (((_this$modalConfig$ada5 = this.modalConfig.adapters) === null || _this$modalConfig$ada5 === void 0 ? void 0 : (_this$modalConfig$ada6 = _this$modalConfig$ada5[adapter.name]) === null || _this$modalConfig$ada6 === void 0 ? void 0 : _this$modalConfig$ada6.showOnModal) !== true) return false;
308
+ if (!((_this$modalConfig$ada7 = this.modalConfig.adapters) !== null && _this$modalConfig$ada7 !== void 0 && (_this$modalConfig$ada8 = _this$modalConfig$ada7[adapter.name]) !== null && _this$modalConfig$ada8 !== void 0 && _this$modalConfig$ada8.loginMethods)) return true;
309
+ const mergedLoginMethods = getAdapterSocialLogins(adapter.name, this.walletAdapters[adapter.name], (_this$modalConfig$ada9 = this.modalConfig.adapters[adapter.name]) === null || _this$modalConfig$ada9 === void 0 ? void 0 : _this$modalConfig$ada9.loginMethods);
310
+ if (Object.values(mergedLoginMethods).some(method => method.showOnModal)) return true;
311
+ return false;
312
+ });
313
+ log.debug(hasInAppWallets, this.walletAdapters, "hasInAppWallets");
314
+ // Now, initialize the adapters.
315
+ const initPromises = adapterNames.map(async adapterName => {
316
+ if (!adapterName) return;
317
+ try {
318
+ const adapter = this.walletAdapters[adapterName];
319
+ // only initialize a external adapter here if it is a cached adapter.
320
+ if (this.cachedAdapter !== adapterName && adapter.type === ADAPTER_CATEGORY.EXTERNAL) {
321
+ return;
322
+ }
323
+ // in-app wallets or cached wallet (being connected or already connected) are initialized first.
324
+ // if adapter is configured thn only initialize in app or cached adapter.
325
+ // external wallets are initialized on INIT_EXTERNAL_WALLET event.
326
+ this.subscribeToAdapterEvents(adapter);
327
+ if (adapter.status === ADAPTER_STATUS.NOT_READY) await adapter.init({
328
+ autoConnect: this.cachedAdapter === adapterName
329
+ });
330
+ // note: not adding cachedWallet to modal if it is external wallet.
331
+ // adding it later if no in-app wallets are available.
332
+ if (adapter.type === ADAPTER_CATEGORY.IN_APP) {
333
+ this.initializeInAppWallet(adapterName);
334
+ }
335
+ } catch (error) {
336
+ log.error(error, "error while initializing adapter");
602
337
  }
338
+ });
339
+ this.status = ADAPTER_STATUS.READY;
340
+ await Promise.all(initPromises);
341
+ const hasExternalWallets = allAdapters.some(adapterName => {
342
+ var _this$walletAdapters$, _this$modalConfig$ada10;
343
+ return ((_this$walletAdapters$ = this.walletAdapters[adapterName]) === null || _this$walletAdapters$ === void 0 ? void 0 : _this$walletAdapters$.type) === ADAPTER_CATEGORY.EXTERNAL && ((_this$modalConfig$ada10 = this.modalConfig.adapters) === null || _this$modalConfig$ada10 === void 0 ? void 0 : _this$modalConfig$ada10[adapterName].showOnModal);
344
+ });
345
+ if (hasExternalWallets) {
346
+ this.loginModal.initExternalWalletContainer();
347
+ }
348
+ // variable to check if we have any in app wallets
349
+ // currently all default in app and external wallets can be hidden or shown based on config.
350
+ if (!hasInAppWallets && hasExternalWallets) {
351
+ // if no in app wallet is available then initialize external wallets in modal
352
+ await this.initExternalWalletAdapters(false, {
353
+ showExternalWalletsOnly: true
354
+ });
603
355
  }
604
- }, {
605
- key: "subscribeToLoginModalEvents",
606
- value: function subscribeToLoginModalEvents() {
607
- var _this5 = this;
608
- this.loginModal.on(LOGIN_MODAL_EVENTS.LOGIN, /*#__PURE__*/function () {
609
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
610
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
611
- while (1) {
612
- switch (_context7.prev = _context7.next) {
613
- case 0:
614
- _context7.prev = 0;
615
- _context7.next = 3;
616
- return _this5.connectTo(params.adapter, params.loginParams);
617
- case 3:
618
- _context7.next = 8;
619
- break;
620
- case 5:
621
- _context7.prev = 5;
622
- _context7.t0 = _context7["catch"](0);
623
- log.error("Error while connecting to adapter: ".concat(params.adapter), _context7.t0);
624
- case 8:
625
- case "end":
626
- return _context7.stop();
627
- }
628
- }
629
- }, _callee7, null, [[0, 5]]);
630
- }));
631
- return function (_x7) {
632
- return _ref4.apply(this, arguments);
633
- };
634
- }());
635
- this.loginModal.on(LOGIN_MODAL_EVENTS.INIT_EXTERNAL_WALLETS, /*#__PURE__*/function () {
636
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
637
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
638
- while (1) {
639
- switch (_context8.prev = _context8.next) {
640
- case 0:
641
- _context8.next = 2;
642
- return _this5.initExternalWalletAdapters(params.externalWalletsInitialized);
643
- case 2:
644
- case "end":
645
- return _context8.stop();
646
- }
647
- }
648
- }, _callee8);
649
- }));
650
- return function (_x8) {
651
- return _ref5.apply(this, arguments);
652
- };
653
- }());
654
- this.loginModal.on(LOGIN_MODAL_EVENTS.DISCONNECT, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
655
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
656
- while (1) {
657
- switch (_context9.prev = _context9.next) {
658
- case 0:
659
- _context9.prev = 0;
660
- _context9.next = 3;
661
- return _this5.logout();
662
- case 3:
663
- _context9.next = 8;
664
- break;
665
- case 5:
666
- _context9.prev = 5;
667
- _context9.t0 = _context9["catch"](0);
668
- log.error("Error while disconnecting", _context9.t0);
669
- case 8:
670
- case "end":
671
- return _context9.stop();
672
- }
673
- }
674
- }, _callee9, null, [[0, 5]]);
675
- })));
676
- this.loginModal.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, /*#__PURE__*/function () {
677
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(visibility) {
678
- var _this5$walletAdapters;
679
- var walletConnectStatus;
680
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
681
- while (1) {
682
- switch (_context10.prev = _context10.next) {
683
- case 0:
684
- log.debug("is login modal visible", visibility);
685
- _this5.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
686
- walletConnectStatus = (_this5$walletAdapters = _this5.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1]) === null || _this5$walletAdapters === void 0 ? void 0 : _this5$walletAdapters.status;
687
- if (visibility && walletConnectStatus === ADAPTER_STATUS.READY) {
688
- // refreshing session for wallet connect whenever modal is opened.
689
- try {
690
- _this5.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1].connect();
691
- } catch (error) {
692
- log.error("Error while disconnecting to wallet connect in core", error);
693
- }
694
- }
695
- case 4:
696
- case "end":
697
- return _context10.stop();
698
- }
699
- }
700
- }, _callee10);
701
- }));
702
- return function (_x9) {
703
- return _ref7.apply(this, arguments);
704
- };
705
- }());
356
+ }
357
+ async connect() {
358
+ // if (!this.loginModal.initialized) throw new Error("Login modal is not initialized");
359
+ // if already connected return provider
360
+ if (this.provider) return this.provider;
361
+ this.loginModal.open();
362
+ return new Promise((resolve, reject) => {
363
+ this.once(ADAPTER_EVENTS.CONNECTED, () => {
364
+ return resolve(this.provider);
365
+ });
366
+ this.once(ADAPTER_EVENTS.ERRORED, err => {
367
+ return reject(err);
368
+ });
369
+ });
370
+ }
371
+ async initExternalWalletAdapters(externalWalletsInitialized, options) {
372
+ if (externalWalletsInitialized) return;
373
+ const adaptersConfig = {};
374
+ Object.keys(this.walletAdapters).forEach(async adapterName => {
375
+ const adapter = this.walletAdapters[adapterName];
376
+ if ((adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.EXTERNAL) {
377
+ log.debug("init external wallet", this.cachedAdapter, adapterName);
378
+ this.subscribeToAdapterEvents(adapter);
379
+ // we are not initializing cached adapter here as it is already being initialized in initModal before.
380
+ if (this.cachedAdapter === adapterName) {
381
+ return;
382
+ }
383
+ if (adapter.status === ADAPTER_STATUS.NOT_READY) await adapter.init({
384
+ autoConnect: this.cachedAdapter === adapterName
385
+ }).then(() => {
386
+ adaptersConfig[adapterName] = this.modalConfig.adapters[adapterName];
387
+ this.loginModal.addWalletLogins(adaptersConfig, {
388
+ showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
389
+ });
390
+ return undefined;
391
+ }).catch(error => log.error(error, "error while initializing adapter"));
392
+ }
393
+ });
394
+ }
395
+ initializeInAppWallet(adapterName) {
396
+ log.info("adapterInitResults", adapterName);
397
+ if (this.walletAdapters[adapterName].type === ADAPTER_CATEGORY.IN_APP) {
398
+ var _this$modalConfig$ada11, _this$options$uiConfi7;
399
+ this.loginModal.addSocialLogins(adapterName, getAdapterSocialLogins(adapterName, this.walletAdapters[adapterName], (_this$modalConfig$ada11 = this.modalConfig.adapters[adapterName]) === null || _this$modalConfig$ada11 === void 0 ? void 0 : _this$modalConfig$ada11.loginMethods), ((_this$options$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.loginMethodsOrder) || OPENLOGIN_PROVIDERS);
706
400
  }
707
- }]);
708
- return Web3Auth;
709
- }(Web3AuthCore);
401
+ }
402
+ subscribeToLoginModalEvents() {
403
+ this.loginModal.on(LOGIN_MODAL_EVENTS.LOGIN, async params => {
404
+ try {
405
+ await this.connectTo(params.adapter, params.loginParams);
406
+ } catch (error) {
407
+ log.error(`Error while connecting to adapter: ${params.adapter}`, error);
408
+ }
409
+ });
410
+ this.loginModal.on(LOGIN_MODAL_EVENTS.INIT_EXTERNAL_WALLETS, async params => {
411
+ await this.initExternalWalletAdapters(params.externalWalletsInitialized);
412
+ });
413
+ this.loginModal.on(LOGIN_MODAL_EVENTS.DISCONNECT, async () => {
414
+ try {
415
+ await this.logout();
416
+ } catch (error) {
417
+ log.error(`Error while disconnecting`, error);
418
+ }
419
+ });
420
+ this.loginModal.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, async visibility => {
421
+ var _this$walletAdapters$2;
422
+ log.debug("is login modal visible", visibility);
423
+ this.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
424
+ const walletConnectStatus = (_this$walletAdapters$2 = this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1]) === null || _this$walletAdapters$2 === void 0 ? void 0 : _this$walletAdapters$2.status;
425
+ if (visibility && walletConnectStatus === ADAPTER_STATUS.READY) {
426
+ // refreshing session for wallet connect whenever modal is opened.
427
+ try {
428
+ this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1].connect();
429
+ } catch (error) {
430
+ log.error(`Error while disconnecting to wallet connect in core`, error);
431
+ }
432
+ }
433
+ });
434
+ }
435
+ }
710
436
 
711
437
  export { Web3Auth, defaultEvmDappModalConfig, defaultEvmWalletModalConfig, defaultOtherModalConfig, defaultSolanaDappModalConfig, defaultSolanaWalletModalConfig };
712
438
  //# sourceMappingURL=modal.esm.js.map