@web3auth/modal 8.12.6 → 9.0.0-alpha.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/LICENSE +2 -2
- package/dist/lib.cjs/config.js +97 -0
- package/dist/lib.cjs/index.js +14 -0
- package/dist/lib.cjs/modalManager.js +426 -0
- package/dist/lib.esm/config.js +90 -0
- package/dist/lib.esm/index.js +2 -0
- package/dist/lib.esm/modalManager.js +424 -0
- package/dist/modal.cjs.js +37 -18
- package/dist/modal.esm.js +31 -11
- package/dist/modal.umd.min.js +1 -1
- package/dist/modal.umd.min.js.LICENSE.txt +0 -2
- package/dist/types/config.d.ts +1 -0
- package/dist/types/interface.d.ts +1 -1
- package/package.json +10 -11
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import { cloneDeep, WalletInitializationError, fetchProjectConfig, log, fetchWalletRegistry, WALLET_ADAPTERS, getChainConfig, ADAPTER_CATEGORY, ADAPTER_STATUS, ADAPTER_EVENTS } from '@web3auth/base';
|
|
4
|
+
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
5
|
+
import { Web3AuthNoModal } from '@web3auth/no-modal';
|
|
6
|
+
import { LOGIN_PROVIDER, getOpenloginDefaultOptions, OpenloginAdapter } from '@web3auth/openlogin-adapter';
|
|
7
|
+
import { getUserLanguage, LoginModal, capitalizeFirstLetter, getAdapterSocialLogins, LOGIN_MODAL_EVENTS, OPENLOGIN_PROVIDERS } from '@web3auth/ui';
|
|
8
|
+
import deepmerge from 'deepmerge';
|
|
9
|
+
import { defaultOtherModalConfig, walletRegistryUrl } from './config.js';
|
|
10
|
+
|
|
11
|
+
class Web3Auth extends Web3AuthNoModal {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
_defineProperty(this, "loginModal", void 0);
|
|
15
|
+
_defineProperty(this, "options", void 0);
|
|
16
|
+
_defineProperty(this, "modalConfig", cloneDeep(defaultOtherModalConfig));
|
|
17
|
+
this.options = _objectSpread({}, options);
|
|
18
|
+
if (!this.options.uiConfig) this.options.uiConfig = {};
|
|
19
|
+
if (!this.coreOptions.privateKeyProvider) throw WalletInitializationError.invalidParams("privateKeyProvider is required");
|
|
20
|
+
}
|
|
21
|
+
setModalConfig(modalConfig) {
|
|
22
|
+
super.checkInitRequirements();
|
|
23
|
+
this.modalConfig = modalConfig;
|
|
24
|
+
}
|
|
25
|
+
async initModal(params) {
|
|
26
|
+
super.checkInitRequirements();
|
|
27
|
+
let projectConfig;
|
|
28
|
+
try {
|
|
29
|
+
projectConfig = await fetchProjectConfig(this.options.clientId, this.options.web3AuthNetwork);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
log.error("Failed to fetch project configurations", e);
|
|
32
|
+
throw WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
33
|
+
}
|
|
34
|
+
const {
|
|
35
|
+
whitelabel
|
|
36
|
+
} = projectConfig;
|
|
37
|
+
this.options.uiConfig = deepmerge(cloneDeep(whitelabel), this.options.uiConfig);
|
|
38
|
+
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
|
|
39
|
+
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
40
|
+
let walletRegistry = {};
|
|
41
|
+
try {
|
|
42
|
+
walletRegistry = await fetchWalletRegistry(walletRegistryUrl);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
log.error("Failed to fetch wallet registry", e);
|
|
45
|
+
}
|
|
46
|
+
this.loginModal = new LoginModal(_objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
|
|
47
|
+
adapterListener: this,
|
|
48
|
+
chainNamespace: this.options.chainConfig.chainNamespace,
|
|
49
|
+
walletRegistry
|
|
50
|
+
}));
|
|
51
|
+
this.subscribeToLoginModalEvents();
|
|
52
|
+
const {
|
|
53
|
+
sms_otp_enabled: smsOtpEnabled,
|
|
54
|
+
whitelist,
|
|
55
|
+
key_export_enabled: keyExportEnabled
|
|
56
|
+
} = projectConfig;
|
|
57
|
+
if (smsOtpEnabled !== undefined) {
|
|
58
|
+
var _params;
|
|
59
|
+
const adapterConfig = {
|
|
60
|
+
[WALLET_ADAPTERS.OPENLOGIN]: {
|
|
61
|
+
label: WALLET_ADAPTERS.OPENLOGIN,
|
|
62
|
+
loginMethods: {
|
|
63
|
+
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
64
|
+
name: LOGIN_PROVIDER.SMS_PASSWORDLESS,
|
|
65
|
+
showOnModal: smsOtpEnabled,
|
|
66
|
+
showOnDesktop: smsOtpEnabled,
|
|
67
|
+
showOnMobile: smsOtpEnabled
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (!((_params = params) !== null && _params !== void 0 && _params.modalConfig)) params = {
|
|
73
|
+
modalConfig: {}
|
|
74
|
+
};
|
|
75
|
+
params.modalConfig = deepmerge(cloneDeep(params.modalConfig), adapterConfig);
|
|
76
|
+
}
|
|
77
|
+
await this.loginModal.initModal();
|
|
78
|
+
const providedChainConfig = this.options.chainConfig;
|
|
79
|
+
// merge default adapters with the custom configured adapters.
|
|
80
|
+
const allAdapters = [...new Set([...Object.keys(this.modalConfig.adapters || {}), ...Object.keys(this.walletAdapters)])];
|
|
81
|
+
const adapterConfigurationPromises = allAdapters.map(async adapterName => {
|
|
82
|
+
var _this$modalConfig$ada, _params2, _this$modalConfig$ada2, _this$modalConfig$ada3;
|
|
83
|
+
// start with the default config of adapter.
|
|
84
|
+
let adapterConfig = ((_this$modalConfig$ada = this.modalConfig.adapters) === null || _this$modalConfig$ada === void 0 ? void 0 : _this$modalConfig$ada[adapterName]) || {
|
|
85
|
+
label: adapterName.split("-").map(capitalizeFirstLetter).join(" "),
|
|
86
|
+
showOnModal: true,
|
|
87
|
+
showOnMobile: true,
|
|
88
|
+
showOnDesktop: true
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// override the default config of adapter if some config is being provided by the user.
|
|
92
|
+
if ((_params2 = params) !== null && _params2 !== void 0 && (_params2 = _params2.modalConfig) !== null && _params2 !== void 0 && _params2[adapterName]) {
|
|
93
|
+
adapterConfig = _objectSpread(_objectSpread({}, adapterConfig), params.modalConfig[adapterName]);
|
|
94
|
+
}
|
|
95
|
+
this.modalConfig.adapters[adapterName] = adapterConfig;
|
|
96
|
+
|
|
97
|
+
// check if adapter is configured/added by user and exist in walletAdapters map.
|
|
98
|
+
const adapter = this.walletAdapters[adapterName];
|
|
99
|
+
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);
|
|
100
|
+
|
|
101
|
+
// if adapter is not custom configured then check if it is available in default adapters.
|
|
102
|
+
// and if adapter is not hidden by user
|
|
103
|
+
if (!adapter && (_this$modalConfig$ada3 = this.modalConfig.adapters) !== null && _this$modalConfig$ada3 !== void 0 && _this$modalConfig$ada3[adapterName].showOnModal) {
|
|
104
|
+
// Adapters to be shown on modal should be pre-configured.
|
|
105
|
+
if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
|
|
106
|
+
var _this$coreOptions$cha;
|
|
107
|
+
const defaultOptions = getOpenloginDefaultOptions();
|
|
108
|
+
const {
|
|
109
|
+
clientId,
|
|
110
|
+
useCoreKitKey,
|
|
111
|
+
chainConfig,
|
|
112
|
+
web3AuthNetwork,
|
|
113
|
+
sessionTime,
|
|
114
|
+
privateKeyProvider
|
|
115
|
+
} = this.coreOptions;
|
|
116
|
+
const finalChainConfig = _objectSpread(_objectSpread({}, getChainConfig(providedChainConfig.chainNamespace, (_this$coreOptions$cha = this.coreOptions.chainConfig) === null || _this$coreOptions$cha === void 0 ? void 0 : _this$coreOptions$cha.chainId)), chainConfig);
|
|
117
|
+
if (!privateKeyProvider) {
|
|
118
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required");
|
|
119
|
+
}
|
|
120
|
+
const finalOpenloginAdapterSettings = _objectSpread(_objectSpread({}, defaultOptions.adapterSettings), {}, {
|
|
121
|
+
clientId,
|
|
122
|
+
network: web3AuthNetwork,
|
|
123
|
+
whiteLabel: this.options.uiConfig
|
|
124
|
+
});
|
|
125
|
+
if (smsOtpEnabled !== undefined) {
|
|
126
|
+
finalOpenloginAdapterSettings.loginConfig = {
|
|
127
|
+
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
128
|
+
showOnModal: smsOtpEnabled,
|
|
129
|
+
showOnDesktop: smsOtpEnabled,
|
|
130
|
+
showOnMobile: smsOtpEnabled,
|
|
131
|
+
showOnSocialBackupFactor: smsOtpEnabled
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (whitelist) {
|
|
136
|
+
finalOpenloginAdapterSettings.originData = whitelist.signed_urls;
|
|
137
|
+
}
|
|
138
|
+
if (this.options.uiConfig.uxMode) {
|
|
139
|
+
finalOpenloginAdapterSettings.uxMode = this.options.uiConfig.uxMode;
|
|
140
|
+
}
|
|
141
|
+
const openloginAdapter = new OpenloginAdapter(_objectSpread(_objectSpread({}, defaultOptions), {}, {
|
|
142
|
+
clientId,
|
|
143
|
+
useCoreKitKey,
|
|
144
|
+
chainConfig: _objectSpread({}, finalChainConfig),
|
|
145
|
+
adapterSettings: finalOpenloginAdapterSettings,
|
|
146
|
+
sessionTime,
|
|
147
|
+
web3AuthNetwork,
|
|
148
|
+
privateKeyProvider
|
|
149
|
+
}));
|
|
150
|
+
this.walletAdapters[adapterName] = openloginAdapter;
|
|
151
|
+
return adapterName;
|
|
152
|
+
}
|
|
153
|
+
throw WalletInitializationError.invalidParams(`Adapter ${adapterName} is not configured`);
|
|
154
|
+
} 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) {
|
|
155
|
+
var _this$modalConfig$ada4;
|
|
156
|
+
if (!((_this$modalConfig$ada4 = this.modalConfig.adapters) !== null && _this$modalConfig$ada4 !== void 0 && _this$modalConfig$ada4[adapterName].showOnModal)) return;
|
|
157
|
+
// add client id to adapter, same web3auth client id can be used in adapter.
|
|
158
|
+
// this id is being overridden if user is also passing client id in adapter's constructor.
|
|
159
|
+
this.walletAdapters[adapterName].setAdapterSettings({
|
|
160
|
+
clientId: this.options.clientId,
|
|
161
|
+
sessionTime: this.options.sessionTime,
|
|
162
|
+
web3AuthNetwork: this.options.web3AuthNetwork,
|
|
163
|
+
useCoreKitKey: this.coreOptions.useCoreKitKey
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// if adapter doesn't have any chainConfig then we will set the chainConfig based of passed chainNamespace
|
|
167
|
+
// and chainNamespace.
|
|
168
|
+
if (!adapter.chainConfigProxy) {
|
|
169
|
+
var _this$coreOptions$cha2;
|
|
170
|
+
const chainConfig = _objectSpread(_objectSpread({}, getChainConfig(providedChainConfig.chainNamespace, (_this$coreOptions$cha2 = this.coreOptions.chainConfig) === null || _this$coreOptions$cha2 === void 0 ? void 0 : _this$coreOptions$cha2.chainId)), this.coreOptions.chainConfig);
|
|
171
|
+
this.walletAdapters[adapterName].setAdapterSettings({
|
|
172
|
+
chainConfig
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
|
|
176
|
+
var _this$options$uiConfi;
|
|
177
|
+
const openloginAdapter = this.walletAdapters[adapterName];
|
|
178
|
+
if (this.coreOptions.privateKeyProvider) {
|
|
179
|
+
if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
180
|
+
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
|
|
181
|
+
}
|
|
182
|
+
openloginAdapter.setAdapterSettings({
|
|
183
|
+
privateKeyProvider: this.coreOptions.privateKeyProvider
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (smsOtpEnabled !== undefined) {
|
|
187
|
+
openloginAdapter.setAdapterSettings({
|
|
188
|
+
loginConfig: {
|
|
189
|
+
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
190
|
+
showOnModal: smsOtpEnabled,
|
|
191
|
+
showOnDesktop: smsOtpEnabled,
|
|
192
|
+
showOnMobile: smsOtpEnabled,
|
|
193
|
+
showOnSocialBackupFactor: smsOtpEnabled
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (whitelist) {
|
|
199
|
+
openloginAdapter.setAdapterSettings({
|
|
200
|
+
originData: whitelist.signed_urls
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if ((_this$options$uiConfi = this.options.uiConfig) !== null && _this$options$uiConfi !== void 0 && _this$options$uiConfi.uxMode) {
|
|
204
|
+
openloginAdapter.setAdapterSettings({
|
|
205
|
+
uxMode: this.options.uiConfig.uxMode
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
openloginAdapter.setAdapterSettings({
|
|
209
|
+
whiteLabel: this.options.uiConfig
|
|
210
|
+
});
|
|
211
|
+
if (!openloginAdapter.privateKeyProvider) {
|
|
212
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required for openlogin adapter");
|
|
213
|
+
}
|
|
214
|
+
} else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
|
|
215
|
+
const walletConnectAdapter = this.walletAdapters[adapterName];
|
|
216
|
+
const {
|
|
217
|
+
wallet_connect_enabled: walletConnectEnabled,
|
|
218
|
+
wallet_connect_project_id: walletConnectProjectId
|
|
219
|
+
} = projectConfig;
|
|
220
|
+
if (walletConnectEnabled === false) {
|
|
221
|
+
var _this$modalConfig$ada5, _this$modalConfig$ada6, _this$modalConfig$ada7;
|
|
222
|
+
// override user specified config by hiding wallet connect
|
|
223
|
+
this.modalConfig.adapters = _objectSpread(_objectSpread({}, (_this$modalConfig$ada5 = this.modalConfig.adapters) !== null && _this$modalConfig$ada5 !== void 0 ? _this$modalConfig$ada5 : {}), {}, {
|
|
224
|
+
[WALLET_ADAPTERS.WALLET_CONNECT_V2]: _objectSpread(_objectSpread({}, (_this$modalConfig$ada6 = (_this$modalConfig$ada7 = this.modalConfig.adapters) === null || _this$modalConfig$ada7 === void 0 ? void 0 : _this$modalConfig$ada7[WALLET_ADAPTERS.WALLET_CONNECT_V2]) !== null && _this$modalConfig$ada6 !== void 0 ? _this$modalConfig$ada6 : {}), {}, {
|
|
225
|
+
showOnModal: false
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
this.modalConfig.adapters[WALLET_ADAPTERS.WALLET_CONNECT_V2].showOnModal = false;
|
|
229
|
+
} else {
|
|
230
|
+
var _walletConnectAdapter;
|
|
231
|
+
if (!(walletConnectAdapter !== null && walletConnectAdapter !== void 0 && (_walletConnectAdapter = walletConnectAdapter.adapterOptions) !== null && _walletConnectAdapter !== void 0 && (_walletConnectAdapter = _walletConnectAdapter.adapterSettings) !== null && _walletConnectAdapter !== void 0 && (_walletConnectAdapter = _walletConnectAdapter.walletConnectInitOptions) !== null && _walletConnectAdapter !== void 0 && _walletConnectAdapter.projectId) && !walletConnectProjectId) throw WalletInitializationError.invalidParams("Invalid wallet connect project id. Please configure it on the dashboard");
|
|
232
|
+
if (walletConnectProjectId) {
|
|
233
|
+
walletConnectAdapter.setAdapterSettings({
|
|
234
|
+
adapterSettings: {
|
|
235
|
+
walletConnectInitOptions: {
|
|
236
|
+
projectId: walletConnectProjectId
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return adapterName;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const adapterNames = await Promise.all(adapterConfigurationPromises);
|
|
247
|
+
const hasInAppWallets = Object.values(this.walletAdapters).some(adapter => {
|
|
248
|
+
var _this$modalConfig$ada8, _this$modalConfig$ada9, _adapter$name;
|
|
249
|
+
if (adapter.type !== ADAPTER_CATEGORY.IN_APP) return false;
|
|
250
|
+
if (((_this$modalConfig$ada8 = this.modalConfig.adapters) === null || _this$modalConfig$ada8 === void 0 || (_this$modalConfig$ada8 = _this$modalConfig$ada8[adapter.name]) === null || _this$modalConfig$ada8 === void 0 ? void 0 : _this$modalConfig$ada8.showOnModal) !== true) return false;
|
|
251
|
+
if (!((_this$modalConfig$ada9 = this.modalConfig.adapters) !== null && _this$modalConfig$ada9 !== void 0 && (_this$modalConfig$ada9 = _this$modalConfig$ada9[adapter.name]) !== null && _this$modalConfig$ada9 !== void 0 && _this$modalConfig$ada9.loginMethods)) return true;
|
|
252
|
+
const mergedLoginMethods = getAdapterSocialLogins(adapter.name, (_adapter$name = this.modalConfig.adapters[adapter.name]) === null || _adapter$name === void 0 ? void 0 : _adapter$name.loginMethods);
|
|
253
|
+
if (Object.values(mergedLoginMethods).some(method => method.showOnModal)) return true;
|
|
254
|
+
return false;
|
|
255
|
+
});
|
|
256
|
+
log.debug(hasInAppWallets, this.walletAdapters, adapterNames, "hasInAppWallets");
|
|
257
|
+
|
|
258
|
+
// Now, initialize the adapters.
|
|
259
|
+
const initPromises = adapterNames.map(async adapterName => {
|
|
260
|
+
if (!adapterName) return;
|
|
261
|
+
try {
|
|
262
|
+
const adapter = this.walletAdapters[adapterName];
|
|
263
|
+
// only initialize a external adapter here if it is a cached adapter.
|
|
264
|
+
if (this.cachedAdapter !== adapterName && adapter.type === ADAPTER_CATEGORY.EXTERNAL) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// in-app wallets or cached wallet (being connected or already connected) are initialized first.
|
|
268
|
+
// if adapter is configured then only initialize in app or cached adapter.
|
|
269
|
+
// external wallets are initialized on INIT_EXTERNAL_WALLET event.
|
|
270
|
+
this.subscribeToAdapterEvents(adapter);
|
|
271
|
+
if (adapter.status === ADAPTER_STATUS.NOT_READY) await adapter.init({
|
|
272
|
+
autoConnect: this.cachedAdapter === adapterName
|
|
273
|
+
});
|
|
274
|
+
// note: not adding cachedWallet to modal if it is external wallet.
|
|
275
|
+
// adding it later if no in-app wallets are available.
|
|
276
|
+
if (adapter.type === ADAPTER_CATEGORY.IN_APP) {
|
|
277
|
+
this.initializeInAppWallet(adapterName);
|
|
278
|
+
}
|
|
279
|
+
} catch (error) {
|
|
280
|
+
log.error(error, "error while initializing adapter ", adapterName);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
this.commonJRPCProvider = await CommonJRPCProvider.getProviderInstance({
|
|
284
|
+
chainConfig: this.coreOptions.chainConfig
|
|
285
|
+
});
|
|
286
|
+
if (typeof keyExportEnabled === "boolean") {
|
|
287
|
+
this.coreOptions.privateKeyProvider.setKeyExportFlag(keyExportEnabled);
|
|
288
|
+
// dont know if we need to do this.
|
|
289
|
+
this.commonJRPCProvider.setKeyExportFlag(keyExportEnabled);
|
|
290
|
+
}
|
|
291
|
+
await Promise.all(initPromises);
|
|
292
|
+
if (this.status === ADAPTER_STATUS.NOT_READY) {
|
|
293
|
+
this.status = ADAPTER_STATUS.READY;
|
|
294
|
+
this.emit(ADAPTER_EVENTS.READY);
|
|
295
|
+
}
|
|
296
|
+
const hasExternalWallets = allAdapters.some(adapterName => {
|
|
297
|
+
var _this$walletAdapters$, _this$modalConfig$ada10;
|
|
298
|
+
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);
|
|
299
|
+
});
|
|
300
|
+
if (hasExternalWallets) {
|
|
301
|
+
this.loginModal.initExternalWalletContainer();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// variable to check if we have any in app wallets
|
|
305
|
+
// currently all default in app and external wallets can be hidden or shown based on config.
|
|
306
|
+
if (!hasInAppWallets && hasExternalWallets) {
|
|
307
|
+
// if no in app wallet is available then initialize external wallets in modal
|
|
308
|
+
await this.initExternalWalletAdapters(false, {
|
|
309
|
+
showExternalWalletsOnly: true
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
async connect() {
|
|
314
|
+
if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
|
|
315
|
+
// if already connected return provider
|
|
316
|
+
if (this.connectedAdapterName && this.status === ADAPTER_STATUS.CONNECTED && this.provider) return this.provider;
|
|
317
|
+
this.loginModal.open();
|
|
318
|
+
return new Promise((resolve, reject) => {
|
|
319
|
+
this.once(ADAPTER_EVENTS.CONNECTED, () => {
|
|
320
|
+
return resolve(this.provider);
|
|
321
|
+
});
|
|
322
|
+
this.once(ADAPTER_EVENTS.ERRORED, err => {
|
|
323
|
+
return reject(err);
|
|
324
|
+
});
|
|
325
|
+
this.once(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility => {
|
|
326
|
+
// modal is closed but user is not connected to any wallet.
|
|
327
|
+
if (!visibility && this.status !== ADAPTER_STATUS.CONNECTED) {
|
|
328
|
+
return reject(new Error("User closed the modal"));
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
async initExternalWalletAdapters(externalWalletsInitialized, options) {
|
|
334
|
+
if (externalWalletsInitialized) return;
|
|
335
|
+
const adaptersConfig = {};
|
|
336
|
+
Object.keys(this.walletAdapters).forEach(async adapterName => {
|
|
337
|
+
const adapter = this.walletAdapters[adapterName];
|
|
338
|
+
if ((adapter === null || adapter === void 0 ? void 0 : adapter.type) === ADAPTER_CATEGORY.EXTERNAL) {
|
|
339
|
+
log.debug("init external wallet", this.cachedAdapter, adapterName);
|
|
340
|
+
this.subscribeToAdapterEvents(adapter);
|
|
341
|
+
// we are not initializing cached adapter here as it is already being initialized in initModal before.
|
|
342
|
+
if (this.cachedAdapter === adapterName) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (adapter.status === ADAPTER_STATUS.NOT_READY) {
|
|
346
|
+
await adapter.init({
|
|
347
|
+
autoConnect: this.cachedAdapter === adapterName
|
|
348
|
+
}).then(() => {
|
|
349
|
+
const adapterModalConfig = this.modalConfig.adapters[adapterName];
|
|
350
|
+
adaptersConfig[adapterName] = _objectSpread(_objectSpread({}, adapterModalConfig), {}, {
|
|
351
|
+
isInjected: adapter.isInjected
|
|
352
|
+
});
|
|
353
|
+
this.loginModal.addWalletLogins(adaptersConfig, {
|
|
354
|
+
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
355
|
+
});
|
|
356
|
+
return undefined;
|
|
357
|
+
}).catch(error => log.error(error, "error while initializing adapter", adapterName));
|
|
358
|
+
} else if (adapter.status === ADAPTER_STATUS.READY) {
|
|
359
|
+
const adapterModalConfig = this.modalConfig.adapters[adapterName];
|
|
360
|
+
adaptersConfig[adapterName] = _objectSpread(_objectSpread({}, adapterModalConfig), {}, {
|
|
361
|
+
isInjected: adapter.isInjected
|
|
362
|
+
});
|
|
363
|
+
this.loginModal.addWalletLogins(adaptersConfig, {
|
|
364
|
+
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
initializeInAppWallet(adapterName) {
|
|
371
|
+
log.info("adapterInitResults", adapterName);
|
|
372
|
+
if (this.walletAdapters[adapterName].type === ADAPTER_CATEGORY.IN_APP) {
|
|
373
|
+
var _adapterName, _this$options$uiConfi2, _this$options$uiConfi3, _this$options$uiConfi4;
|
|
374
|
+
this.loginModal.addSocialLogins(adapterName, getAdapterSocialLogins(adapterName, (_adapterName = this.modalConfig.adapters[adapterName]) === null || _adapterName === void 0 ? void 0 : _adapterName.loginMethods), ((_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.loginMethodsOrder) || OPENLOGIN_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
|
|
375
|
+
loginGridCol: ((_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.loginGridCol) || 3,
|
|
376
|
+
primaryButton: ((_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.primaryButton) || "socialLogin"
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
subscribeToLoginModalEvents() {
|
|
381
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.LOGIN, async params => {
|
|
382
|
+
try {
|
|
383
|
+
await this.connectTo(params.adapter, params.loginParams);
|
|
384
|
+
} catch (error) {
|
|
385
|
+
log.error(`Error while connecting to adapter: ${params.adapter}`, error);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.INIT_EXTERNAL_WALLETS, async params => {
|
|
389
|
+
await this.initExternalWalletAdapters(params.externalWalletsInitialized);
|
|
390
|
+
});
|
|
391
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.DISCONNECT, async () => {
|
|
392
|
+
try {
|
|
393
|
+
await this.logout();
|
|
394
|
+
} catch (error) {
|
|
395
|
+
log.error(`Error while disconnecting`, error);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
this.loginModal.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, async visibility => {
|
|
399
|
+
log.debug("is login modal visible", visibility);
|
|
400
|
+
this.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
|
|
401
|
+
const adapter = this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V2];
|
|
402
|
+
if (adapter) {
|
|
403
|
+
const walletConnectStatus = adapter === null || adapter === void 0 ? void 0 : adapter.status;
|
|
404
|
+
log.debug("trying refreshing wc session", visibility, walletConnectStatus);
|
|
405
|
+
if (visibility && (walletConnectStatus === ADAPTER_STATUS.READY || walletConnectStatus === ADAPTER_STATUS.CONNECTING)) {
|
|
406
|
+
log.debug("refreshing wc session");
|
|
407
|
+
|
|
408
|
+
// refreshing session for wallet connect whenever modal is opened.
|
|
409
|
+
try {
|
|
410
|
+
adapter.connect();
|
|
411
|
+
} catch (error) {
|
|
412
|
+
log.error(`Error while disconnecting to wallet connect in core`, error);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (!visibility && this.status === ADAPTER_STATUS.CONNECTED && (walletConnectStatus === ADAPTER_STATUS.READY || walletConnectStatus === ADAPTER_STATUS.CONNECTING)) {
|
|
416
|
+
log.debug("this stops wc adapter from trying to reconnect once proposal expires");
|
|
417
|
+
adapter.status = ADAPTER_STATUS.READY;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export { Web3Auth };
|
package/dist/modal.cjs.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
/* harmony export */ Gu: () => (/* binding */ defaultSolanaDappModalConfig),
|
|
10
10
|
/* harmony export */ KT: () => (/* binding */ defaultSolanaWalletModalConfig),
|
|
11
11
|
/* harmony export */ Lu: () => (/* binding */ defaultOtherModalConfig),
|
|
12
|
+
/* harmony export */ e4: () => (/* binding */ walletRegistryUrl),
|
|
12
13
|
/* harmony export */ eA: () => (/* binding */ defaultEvmWalletModalConfig),
|
|
13
14
|
/* harmony export */ g2: () => (/* binding */ defaultEvmDappModalConfig)
|
|
14
15
|
/* harmony export */ });
|
|
@@ -100,6 +101,7 @@ const defaultOtherModalConfig = {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
};
|
|
104
|
+
const walletRegistryUrl = "https://assets.web3auth.io/v1/wallet-registry.json";
|
|
103
105
|
|
|
104
106
|
/***/ }),
|
|
105
107
|
|
|
@@ -110,7 +112,7 @@ const defaultOtherModalConfig = {
|
|
|
110
112
|
|
|
111
113
|
/***/ }),
|
|
112
114
|
|
|
113
|
-
/***/
|
|
115
|
+
/***/ 859:
|
|
114
116
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
115
117
|
|
|
116
118
|
"use strict";
|
|
@@ -136,12 +138,9 @@ const no_modal_namespaceObject = require("@web3auth/no-modal");
|
|
|
136
138
|
const openlogin_adapter_namespaceObject = require("@web3auth/openlogin-adapter");
|
|
137
139
|
;// CONCATENATED MODULE: external "@web3auth/ui"
|
|
138
140
|
const ui_namespaceObject = require("@web3auth/ui");
|
|
139
|
-
;// CONCATENATED MODULE: external "
|
|
140
|
-
const
|
|
141
|
-
var
|
|
142
|
-
;// CONCATENATED MODULE: external "lodash.merge"
|
|
143
|
-
const external_lodash_merge_namespaceObject = require("lodash.merge");
|
|
144
|
-
var external_lodash_merge_default = /*#__PURE__*/__webpack_require__.n(external_lodash_merge_namespaceObject);
|
|
141
|
+
;// CONCATENATED MODULE: external "deepmerge"
|
|
142
|
+
const external_deepmerge_namespaceObject = require("deepmerge");
|
|
143
|
+
var external_deepmerge_default = /*#__PURE__*/__webpack_require__.n(external_deepmerge_namespaceObject);
|
|
145
144
|
// EXTERNAL MODULE: ./src/config.ts
|
|
146
145
|
var config = __webpack_require__(149);
|
|
147
146
|
;// CONCATENATED MODULE: ./src/modalManager.ts
|
|
@@ -154,13 +153,12 @@ var config = __webpack_require__(149);
|
|
|
154
153
|
|
|
155
154
|
|
|
156
155
|
|
|
157
|
-
|
|
158
156
|
class Web3Auth extends no_modal_namespaceObject.Web3AuthNoModal {
|
|
159
157
|
constructor(options) {
|
|
160
158
|
super(options);
|
|
161
159
|
defineProperty_default()(this, "loginModal", void 0);
|
|
162
160
|
defineProperty_default()(this, "options", void 0);
|
|
163
|
-
defineProperty_default()(this, "modalConfig", config/* defaultOtherModalConfig */.Lu);
|
|
161
|
+
defineProperty_default()(this, "modalConfig", (0,base_.cloneDeep)(config/* defaultOtherModalConfig */.Lu));
|
|
164
162
|
this.options = objectSpread2_default()({}, options);
|
|
165
163
|
if (!this.options.uiConfig) this.options.uiConfig = {};
|
|
166
164
|
if (!this.coreOptions.privateKeyProvider) throw base_.WalletInitializationError.invalidParams("privateKeyProvider is required");
|
|
@@ -181,16 +179,25 @@ class Web3Auth extends no_modal_namespaceObject.Web3AuthNoModal {
|
|
|
181
179
|
const {
|
|
182
180
|
whitelabel
|
|
183
181
|
} = projectConfig;
|
|
184
|
-
this.options.uiConfig =
|
|
182
|
+
this.options.uiConfig = external_deepmerge_default()((0,base_.cloneDeep)(whitelabel), this.options.uiConfig);
|
|
185
183
|
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = (0,ui_namespaceObject.getUserLanguage)(this.options.uiConfig.defaultLanguage);
|
|
186
184
|
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
|
|
185
|
+
let walletRegistry = {};
|
|
186
|
+
try {
|
|
187
|
+
walletRegistry = await (0,base_.fetchWalletRegistry)(config/* walletRegistryUrl */.e4);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
base_.log.error("Failed to fetch wallet registry", e);
|
|
190
|
+
}
|
|
187
191
|
this.loginModal = new ui_namespaceObject.LoginModal(objectSpread2_default()(objectSpread2_default()({}, this.options.uiConfig), {}, {
|
|
188
|
-
adapterListener: this
|
|
192
|
+
adapterListener: this,
|
|
193
|
+
chainNamespace: this.options.chainConfig.chainNamespace,
|
|
194
|
+
walletRegistry
|
|
189
195
|
}));
|
|
190
196
|
this.subscribeToLoginModalEvents();
|
|
191
197
|
const {
|
|
192
198
|
sms_otp_enabled: smsOtpEnabled,
|
|
193
|
-
whitelist
|
|
199
|
+
whitelist,
|
|
200
|
+
key_export_enabled: keyExportEnabled
|
|
194
201
|
} = projectConfig;
|
|
195
202
|
if (smsOtpEnabled !== undefined) {
|
|
196
203
|
var _params;
|
|
@@ -210,7 +217,7 @@ class Web3Auth extends no_modal_namespaceObject.Web3AuthNoModal {
|
|
|
210
217
|
if (!((_params = params) !== null && _params !== void 0 && _params.modalConfig)) params = {
|
|
211
218
|
modalConfig: {}
|
|
212
219
|
};
|
|
213
|
-
params.modalConfig =
|
|
220
|
+
params.modalConfig = external_deepmerge_default()((0,base_.cloneDeep)(params.modalConfig), adapterConfig);
|
|
214
221
|
}
|
|
215
222
|
await this.loginModal.initModal();
|
|
216
223
|
const providedChainConfig = this.options.chainConfig;
|
|
@@ -421,6 +428,11 @@ class Web3Auth extends no_modal_namespaceObject.Web3AuthNoModal {
|
|
|
421
428
|
this.commonJRPCProvider = await base_provider_namespaceObject.CommonJRPCProvider.getProviderInstance({
|
|
422
429
|
chainConfig: this.coreOptions.chainConfig
|
|
423
430
|
});
|
|
431
|
+
if (typeof keyExportEnabled === "boolean") {
|
|
432
|
+
this.coreOptions.privateKeyProvider.setKeyExportFlag(keyExportEnabled);
|
|
433
|
+
// dont know if we need to do this.
|
|
434
|
+
this.commonJRPCProvider.setKeyExportFlag(keyExportEnabled);
|
|
435
|
+
}
|
|
424
436
|
await Promise.all(initPromises);
|
|
425
437
|
if (this.status === base_.ADAPTER_STATUS.NOT_READY) {
|
|
426
438
|
this.status = base_.ADAPTER_STATUS.READY;
|
|
@@ -479,14 +491,20 @@ class Web3Auth extends no_modal_namespaceObject.Web3AuthNoModal {
|
|
|
479
491
|
await adapter.init({
|
|
480
492
|
autoConnect: this.cachedAdapter === adapterName
|
|
481
493
|
}).then(() => {
|
|
482
|
-
|
|
494
|
+
const adapterModalConfig = this.modalConfig.adapters[adapterName];
|
|
495
|
+
adaptersConfig[adapterName] = objectSpread2_default()(objectSpread2_default()({}, adapterModalConfig), {}, {
|
|
496
|
+
isInjected: adapter.isInjected
|
|
497
|
+
});
|
|
483
498
|
this.loginModal.addWalletLogins(adaptersConfig, {
|
|
484
499
|
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
485
500
|
});
|
|
486
501
|
return undefined;
|
|
487
502
|
}).catch(error => base_.log.error(error, "error while initializing adapter", adapterName));
|
|
488
503
|
} else if (adapter.status === base_.ADAPTER_STATUS.READY) {
|
|
489
|
-
|
|
504
|
+
const adapterModalConfig = this.modalConfig.adapters[adapterName];
|
|
505
|
+
adaptersConfig[adapterName] = objectSpread2_default()(objectSpread2_default()({}, adapterModalConfig), {}, {
|
|
506
|
+
isInjected: adapter.isInjected
|
|
507
|
+
});
|
|
490
508
|
this.loginModal.addWalletLogins(adaptersConfig, {
|
|
491
509
|
showExternalWalletsOnly: !!(options !== null && options !== void 0 && options.showExternalWalletsOnly)
|
|
492
510
|
});
|
|
@@ -637,15 +655,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
637
655
|
/* harmony export */ defaultEvmWalletModalConfig: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.eA),
|
|
638
656
|
/* harmony export */ defaultOtherModalConfig: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.Lu),
|
|
639
657
|
/* harmony export */ defaultSolanaDappModalConfig: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.Gu),
|
|
640
|
-
/* harmony export */ defaultSolanaWalletModalConfig: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.KT)
|
|
658
|
+
/* harmony export */ defaultSolanaWalletModalConfig: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.KT),
|
|
659
|
+
/* harmony export */ walletRegistryUrl: () => (/* reexport safe */ _config__WEBPACK_IMPORTED_MODULE_0__.e4)
|
|
641
660
|
/* harmony export */ });
|
|
642
661
|
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(149);
|
|
643
662
|
/* harmony import */ var _interface__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(624);
|
|
644
663
|
/* harmony import */ var _interface__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_interface__WEBPACK_IMPORTED_MODULE_1__);
|
|
645
664
|
/* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
646
|
-
/* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _interface__WEBPACK_IMPORTED_MODULE_1__) if(["default","defaultEvmDappModalConfig","defaultEvmWalletModalConfig","defaultOtherModalConfig","defaultSolanaDappModalConfig","defaultSolanaWalletModalConfig"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _interface__WEBPACK_IMPORTED_MODULE_1__[__WEBPACK_IMPORT_KEY__]
|
|
665
|
+
/* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _interface__WEBPACK_IMPORTED_MODULE_1__) if(["default","defaultEvmDappModalConfig","defaultEvmWalletModalConfig","defaultOtherModalConfig","defaultSolanaDappModalConfig","defaultSolanaWalletModalConfig","walletRegistryUrl"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _interface__WEBPACK_IMPORTED_MODULE_1__[__WEBPACK_IMPORT_KEY__]
|
|
647
666
|
/* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
648
|
-
/* harmony import */ var _modalManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
667
|
+
/* harmony import */ var _modalManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(859);
|
|
649
668
|
|
|
650
669
|
|
|
651
670
|
|