@web3auth/no-modal 8.0.1 → 8.2.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.
@@ -68,6 +68,14 @@ const base_namespaceObject = require("@web3auth/base");
68
68
  const base_plugin_namespaceObject = require("@web3auth/base-plugin");
69
69
  ;// CONCATENATED MODULE: external "@web3auth/base-provider"
70
70
  const base_provider_namespaceObject = require("@web3auth/base-provider");
71
+ ;// CONCATENATED MODULE: external "@web3auth/openlogin-adapter"
72
+ const openlogin_adapter_namespaceObject = require("@web3auth/openlogin-adapter");
73
+ ;// CONCATENATED MODULE: external "lodash.clonedeep"
74
+ const external_lodash_clonedeep_namespaceObject = require("lodash.clonedeep");
75
+ var external_lodash_clonedeep_default = /*#__PURE__*/__webpack_require__.n(external_lodash_clonedeep_namespaceObject);
76
+ ;// CONCATENATED MODULE: external "lodash.merge"
77
+ const external_lodash_merge_namespaceObject = require("lodash.merge");
78
+ var external_lodash_merge_default = /*#__PURE__*/__webpack_require__.n(external_lodash_merge_namespaceObject);
71
79
  ;// CONCATENATED MODULE: ./src/noModal.ts
72
80
 
73
81
 
@@ -75,6 +83,9 @@ const base_provider_namespaceObject = require("@web3auth/base-provider");
75
83
 
76
84
 
77
85
 
86
+
87
+
88
+
78
89
  const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
79
90
  class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
80
91
  constructor(options) {
@@ -118,9 +129,13 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
118
129
  this.commonJRPCProvider = await base_provider_namespaceObject.CommonJRPCProvider.getProviderInstance({
119
130
  chainConfig: this.coreOptions.chainConfig
120
131
  });
121
- // TODO: get stuff from dashboard here
122
- // disable sms login
123
- const initPromises = Object.keys(this.walletAdapters).map(adapterName => {
132
+ let projectConfig;
133
+ try {
134
+ projectConfig = await (0,base_namespaceObject.fetchProjectConfig)(this.coreOptions.clientId);
135
+ } catch (e) {
136
+ throw base_namespaceObject.WalletInitializationError.notReady("failed to fetch project configurations");
137
+ }
138
+ const initPromises = Object.keys(this.walletAdapters).map(async adapterName => {
124
139
  this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
125
140
  // if adapter doesn't have any chain config yet then set it based on provided namespace and chainId.
126
141
  // if no chainNamespace or chainId is being provided, it will connect with mainnet.
@@ -144,6 +159,25 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
144
159
  }
145
160
  if (adapterName === base_namespaceObject.WALLET_ADAPTERS.OPENLOGIN) {
146
161
  const openloginAdapter = this.walletAdapters[adapterName];
162
+ const {
163
+ whitelabel
164
+ } = projectConfig;
165
+ this.coreOptions.uiConfig = external_lodash_merge_default()(external_lodash_clonedeep_default()(whitelabel), this.coreOptions.uiConfig);
166
+ const {
167
+ sms_otp_enabled: smsOtpEnabled
168
+ } = projectConfig;
169
+ if (smsOtpEnabled !== undefined) {
170
+ openloginAdapter.setAdapterSettings({
171
+ loginConfig: {
172
+ [openlogin_adapter_namespaceObject.LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
173
+ showOnModal: smsOtpEnabled,
174
+ showOnDesktop: smsOtpEnabled,
175
+ showOnMobile: smsOtpEnabled,
176
+ showOnSocialBackupFactor: smsOtpEnabled
177
+ }
178
+ }
179
+ });
180
+ }
147
181
  if (this.coreOptions.privateKeyProvider) {
148
182
  if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
149
183
  throw base_namespaceObject.WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
@@ -160,11 +194,18 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
160
194
  }
161
195
  } else if (adapterName === base_namespaceObject.WALLET_ADAPTERS.WALLET_CONNECT_V2) {
162
196
  const walletConnectAdapter = this.walletAdapters[adapterName];
197
+ const {
198
+ wallet_connect_enabled: walletConnectEnabled,
199
+ wallet_connect_project_id: walletConnectProjectId
200
+ } = projectConfig;
201
+ if (walletConnectEnabled === false) {
202
+ throw base_namespaceObject.WalletInitializationError.invalidParams("Please enable wallet connect v2 addon on dashboard");
203
+ }
204
+ if (!walletConnectProjectId) throw base_namespaceObject.WalletInitializationError.invalidParams("Invalid wallet connect project id. Please configure it on the dashboard");
163
205
  walletConnectAdapter.setAdapterSettings({
164
206
  adapterSettings: {
165
207
  walletConnectInitOptions: {
166
- // Using a default wallet connect project id for web3auth modal integration
167
- projectId: "d3c63f19f9582f8ba48e982057eb096b" // TODO: get from dashboard
208
+ projectId: walletConnectProjectId
168
209
  }
169
210
  }
170
211
  });
@@ -173,8 +214,8 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
173
214
  autoConnect: this.cachedAdapter === adapterName
174
215
  }).catch(e => base_namespaceObject.log.error(e));
175
216
  });
176
- this.status = base_namespaceObject.ADAPTER_STATUS.READY;
177
217
  await Promise.all(initPromises);
218
+ this.status = base_namespaceObject.ADAPTER_STATUS.READY;
178
219
  }
179
220
  getAdapter(adapterName) {
180
221
  return this.walletAdapters[adapterName] || null;
@@ -340,5 +381,4 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
340
381
 
341
382
  module.exports = __webpack_exports__;
342
383
  /******/ })()
343
- ;
344
- //# sourceMappingURL=noModal.cjs.js.map
384
+ ;
@@ -1,9 +1,12 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import { SafeEventEmitter } from '@toruslabs/openlogin-jrpc';
4
- import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, WALLET_ADAPTERS, ADAPTER_NAMESPACES, WalletLoginError, ADAPTER_EVENTS } from '@web3auth/base';
4
+ import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, ADAPTER_NAMESPACES, WalletLoginError, ADAPTER_EVENTS } from '@web3auth/base';
5
5
  import { PLUGIN_NAMESPACES } from '@web3auth/base-plugin';
6
6
  import { CommonJRPCProvider } from '@web3auth/base-provider';
7
+ import { LOGIN_PROVIDER } from '@web3auth/openlogin-adapter';
8
+ import clonedeep from 'lodash.clonedeep';
9
+ import merge from 'lodash.merge';
7
10
 
8
11
  const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
9
12
  class Web3AuthNoModal extends SafeEventEmitter {
@@ -48,9 +51,13 @@ class Web3AuthNoModal extends SafeEventEmitter {
48
51
  this.commonJRPCProvider = await CommonJRPCProvider.getProviderInstance({
49
52
  chainConfig: this.coreOptions.chainConfig
50
53
  });
51
- // TODO: get stuff from dashboard here
52
- // disable sms login
53
- const initPromises = Object.keys(this.walletAdapters).map(adapterName => {
54
+ let projectConfig;
55
+ try {
56
+ projectConfig = await fetchProjectConfig(this.coreOptions.clientId);
57
+ } catch (e) {
58
+ throw WalletInitializationError.notReady("failed to fetch project configurations");
59
+ }
60
+ const initPromises = Object.keys(this.walletAdapters).map(async adapterName => {
54
61
  this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
55
62
  // if adapter doesn't have any chain config yet then set it based on provided namespace and chainId.
56
63
  // if no chainNamespace or chainId is being provided, it will connect with mainnet.
@@ -74,6 +81,25 @@ class Web3AuthNoModal extends SafeEventEmitter {
74
81
  }
75
82
  if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
76
83
  const openloginAdapter = this.walletAdapters[adapterName];
84
+ const {
85
+ whitelabel
86
+ } = projectConfig;
87
+ this.coreOptions.uiConfig = merge(clonedeep(whitelabel), this.coreOptions.uiConfig);
88
+ const {
89
+ sms_otp_enabled: smsOtpEnabled
90
+ } = projectConfig;
91
+ if (smsOtpEnabled !== undefined) {
92
+ openloginAdapter.setAdapterSettings({
93
+ loginConfig: {
94
+ [LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
95
+ showOnModal: smsOtpEnabled,
96
+ showOnDesktop: smsOtpEnabled,
97
+ showOnMobile: smsOtpEnabled,
98
+ showOnSocialBackupFactor: smsOtpEnabled
99
+ }
100
+ }
101
+ });
102
+ }
77
103
  if (this.coreOptions.privateKeyProvider) {
78
104
  if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
79
105
  throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
@@ -90,11 +116,18 @@ class Web3AuthNoModal extends SafeEventEmitter {
90
116
  }
91
117
  } else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
92
118
  const walletConnectAdapter = this.walletAdapters[adapterName];
119
+ const {
120
+ wallet_connect_enabled: walletConnectEnabled,
121
+ wallet_connect_project_id: walletConnectProjectId
122
+ } = projectConfig;
123
+ if (walletConnectEnabled === false) {
124
+ throw WalletInitializationError.invalidParams("Please enable wallet connect v2 addon on dashboard");
125
+ }
126
+ if (!walletConnectProjectId) throw WalletInitializationError.invalidParams("Invalid wallet connect project id. Please configure it on the dashboard");
93
127
  walletConnectAdapter.setAdapterSettings({
94
128
  adapterSettings: {
95
129
  walletConnectInitOptions: {
96
- // Using a default wallet connect project id for web3auth modal integration
97
- projectId: "d3c63f19f9582f8ba48e982057eb096b" // TODO: get from dashboard
130
+ projectId: walletConnectProjectId
98
131
  }
99
132
  }
100
133
  });
@@ -103,8 +136,8 @@ class Web3AuthNoModal extends SafeEventEmitter {
103
136
  autoConnect: this.cachedAdapter === adapterName
104
137
  }).catch(e => log.error(e));
105
138
  });
106
- this.status = ADAPTER_STATUS.READY;
107
139
  await Promise.all(initPromises);
140
+ this.status = ADAPTER_STATUS.READY;
108
141
  }
109
142
  getAdapter(adapterName) {
110
143
  return this.walletAdapters[adapterName] || null;
@@ -268,4 +301,3 @@ class Web3AuthNoModal extends SafeEventEmitter {
268
301
  }
269
302
 
270
303
  export { Web3AuthNoModal };
271
- //# sourceMappingURL=noModal.esm.js.map