@web3auth/modal 10.0.0-beta.8 → 10.0.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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/dist/lib.cjs/packages/modal/src/config.js +1 -1
  3. package/dist/lib.cjs/packages/modal/src/connectors/coinbase-connector/index.js +12 -0
  4. package/dist/lib.cjs/packages/modal/src/modalManager.js +152 -91
  5. package/dist/lib.cjs/packages/modal/src/providers/ethereum-mpc-provider/index.js +12 -0
  6. package/dist/lib.cjs/packages/modal/src/providers/xrpl-provider/index.js +12 -0
  7. package/dist/lib.cjs/packages/modal/src/react/Web3AuthProvider.js +3 -1
  8. package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +23 -19
  9. package/dist/lib.cjs/packages/modal/src/react/hooks/useIdentityToken.js +3 -3
  10. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3AuthConnect.js +17 -1
  11. package/dist/lib.cjs/packages/modal/src/react/solana/hooks/useSolanaWallet.js +4 -0
  12. package/dist/lib.cjs/packages/modal/src/react/wagmi/constants.js +16 -0
  13. package/dist/lib.cjs/packages/modal/src/react/wagmi/provider.js +15 -10
  14. package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +17 -1
  15. package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +8 -5
  16. package/dist/lib.cjs/packages/modal/src/ui/components/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +1 -0
  17. package/dist/lib.cjs/packages/modal/src/ui/components/Footer/Footer.js +1 -1
  18. package/dist/lib.cjs/packages/modal/src/ui/components/Login/Login.js +23 -4
  19. package/dist/lib.cjs/packages/modal/src/ui/components/Root/Root.js +6 -1
  20. package/dist/lib.cjs/packages/modal/src/ui/components/Widget/Widget.js +2 -2
  21. package/dist/lib.cjs/packages/modal/src/ui/context/AnalyticsContext.js +9 -0
  22. package/dist/lib.cjs/packages/modal/src/ui/css/index.css.js +1 -1
  23. package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +42 -15
  24. package/dist/lib.cjs/packages/modal/src/utils.js +22 -0
  25. package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +11 -2
  26. package/dist/lib.cjs/packages/modal/src/vue/composables/useIdentityToken.js +3 -3
  27. package/dist/lib.cjs/packages/modal/src/vue/composables/useManageMFA.js +1 -1
  28. package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3AuthConnect.js +17 -1
  29. package/dist/lib.cjs/packages/modal/src/vue/solana/composables/useSolanaWallet.js +19 -13
  30. package/dist/lib.cjs/packages/modal/src/vue/wagmi/constants.js +16 -0
  31. package/dist/lib.cjs/packages/modal/src/vue/wagmi/provider.js +35 -16
  32. package/dist/lib.cjs/types/connectors/coinbase-connector/index.d.ts +1 -0
  33. package/dist/lib.cjs/types/interface.d.ts +0 -3
  34. package/dist/lib.cjs/types/modalManager.d.ts +5 -4
  35. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/index.d.ts +1 -0
  36. package/dist/lib.cjs/types/providers/xrpl-provider/index.d.ts +1 -0
  37. package/dist/lib.cjs/types/react/Web3AuthProvider.d.ts +1 -1
  38. package/dist/lib.cjs/types/react/hooks/useIdentityToken.d.ts +2 -2
  39. package/dist/lib.cjs/types/react/hooks/useWeb3AuthConnect.d.ts +2 -1
  40. package/dist/lib.cjs/types/react/interfaces.d.ts +2 -1
  41. package/dist/lib.cjs/types/react/wagmi/constants.d.ts +43 -0
  42. package/dist/lib.cjs/types/react/wagmi/provider.d.ts +1 -2
  43. package/dist/lib.cjs/types/ui/context/AnalyticsContext.d.ts +4 -0
  44. package/dist/lib.cjs/types/ui/interfaces.d.ts +3 -2
  45. package/dist/lib.cjs/types/ui/loginModal.d.ts +1 -0
  46. package/dist/lib.cjs/types/utils.d.ts +17 -0
  47. package/dist/lib.cjs/types/vue/composables/useIdentityToken.d.ts +1 -1
  48. package/dist/lib.cjs/types/vue/composables/useWeb3AuthConnect.d.ts +2 -1
  49. package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +43 -0
  50. package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +1 -0
  51. package/dist/lib.esm/packages/modal/src/config.js +1 -1
  52. package/dist/lib.esm/packages/modal/src/connectors/coinbase-connector/index.js +1 -0
  53. package/dist/lib.esm/packages/modal/src/modalManager.js +160 -97
  54. package/dist/lib.esm/packages/modal/src/providers/ethereum-mpc-provider/index.js +1 -0
  55. package/dist/lib.esm/packages/modal/src/providers/xrpl-provider/index.js +1 -0
  56. package/dist/lib.esm/packages/modal/src/react/Web3AuthProvider.js +3 -1
  57. package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +25 -21
  58. package/dist/lib.esm/packages/modal/src/react/hooks/useIdentityToken.js +3 -3
  59. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3AuthConnect.js +17 -1
  60. package/dist/lib.esm/packages/modal/src/react/solana/hooks/useSolanaWallet.js +5 -1
  61. package/dist/lib.esm/packages/modal/src/react/wagmi/constants.js +14 -0
  62. package/dist/lib.esm/packages/modal/src/react/wagmi/provider.js +18 -14
  63. package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWallet.js +19 -2
  64. package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletChainFilter/ConnectWalletChainFilter.js +8 -5
  65. package/dist/lib.esm/packages/modal/src/ui/components/ConnectWallet/ConnectWalletQrCode/ConnectWalletQrCode.js +1 -0
  66. package/dist/lib.esm/packages/modal/src/ui/components/Footer/Footer.js +1 -1
  67. package/dist/lib.esm/packages/modal/src/ui/components/Login/Login.js +24 -5
  68. package/dist/lib.esm/packages/modal/src/ui/components/Root/Root.js +6 -1
  69. package/dist/lib.esm/packages/modal/src/ui/components/Widget/Widget.js +2 -2
  70. package/dist/lib.esm/packages/modal/src/ui/context/AnalyticsContext.js +7 -0
  71. package/dist/lib.esm/packages/modal/src/ui/css/index.css.js +1 -1
  72. package/dist/lib.esm/packages/modal/src/ui/loginModal.js +41 -14
  73. package/dist/lib.esm/packages/modal/src/utils.js +20 -0
  74. package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +12 -3
  75. package/dist/lib.esm/packages/modal/src/vue/composables/useIdentityToken.js +3 -3
  76. package/dist/lib.esm/packages/modal/src/vue/composables/useManageMFA.js +1 -1
  77. package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3AuthConnect.js +17 -1
  78. package/dist/lib.esm/packages/modal/src/vue/solana/composables/useSolanaWallet.js +20 -14
  79. package/dist/lib.esm/packages/modal/src/vue/wagmi/constants.js +14 -0
  80. package/dist/lib.esm/packages/modal/src/vue/wagmi/provider.js +39 -20
  81. package/dist/modal.umd.min.js +1 -1
  82. package/dist/modal.umd.min.js.LICENSE.txt +6 -8
  83. package/package.json +42 -33
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import { serializeError } from '@web3auth/auth';
4
- import { Web3AuthNoModal, cloneDeep, WALLET_CONNECTORS, log, CONNECTOR_STATUS, withAbort, CONNECTOR_EVENTS, WalletInitializationError, fetchProjectConfig, fetchWalletRegistry, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES } from '@web3auth/no-modal';
4
+ import { Web3AuthNoModal, cloneDeep, WALLET_CONNECTORS, LOGIN_MODE, log, CONNECTOR_STATUS, sdkVersion, ANALYTICS_SDK_TYPE, withAbort, CONNECTOR_EVENTS, ANALYTICS_EVENTS, getErrorAnalyticsProperties, WalletInitializationError, fetchProjectConfig, fetchWalletRegistry, CONNECTOR_CATEGORY, CONNECTOR_NAMES, CONNECTOR_NAMESPACES } from '@web3auth/no-modal';
5
5
  import deepmerge from 'deepmerge';
6
6
  import { defaultConnectorsModalConfig, walletRegistryUrl } from './config.js';
7
7
  import { AUTH_PROVIDERS_NAMES, AUTH_PROVIDERS, capitalizeFirstLetter } from './ui/config.js';
@@ -10,8 +10,8 @@ import { LoginModal } from './ui/loginModal.js';
10
10
  import { getUserLanguage } from './ui/utils.js';
11
11
 
12
12
  class Web3Auth extends Web3AuthNoModal {
13
- constructor(options) {
14
- super(options);
13
+ constructor(options, initialState) {
14
+ super(options, initialState);
15
15
  _defineProperty(this, "loginModal", void 0);
16
16
  _defineProperty(this, "options", void 0);
17
17
  _defineProperty(this, "modalConfig", cloneDeep(defaultConnectorsModalConfig));
@@ -25,14 +25,14 @@ class Web3Auth extends Web3AuthNoModal {
25
25
  });
26
26
  _defineProperty(this, "onSocialLogin", async params => {
27
27
  try {
28
- await this.connectTo(WALLET_CONNECTORS.AUTH, params.loginParams);
28
+ await this.connectTo(WALLET_CONNECTORS.AUTH, params.loginParams, LOGIN_MODE.MODAL);
29
29
  } catch (error) {
30
30
  log.error(`Error while connecting to connector: ${params.connector}`, error);
31
31
  }
32
32
  });
33
33
  _defineProperty(this, "onExternalWalletLogin", async params => {
34
34
  try {
35
- await this.connectTo(params.connector, params.loginParams);
35
+ await this.connectTo(params.connector, params.loginParams, LOGIN_MODE.MODAL);
36
36
  } catch (error) {
37
37
  log.error(`Error while connecting to connector: ${params.connector}`, error);
38
38
  }
@@ -98,70 +98,109 @@ class Web3Auth extends Web3AuthNoModal {
98
98
  if (this.options.modalConfig) this.modalConfig = this.options.modalConfig;
99
99
  log.info("modalConfig", this.modalConfig);
100
100
  }
101
- async initModal(options) {
102
- const {
103
- signal
104
- } = options || {};
105
- super.checkInitRequirements();
106
- // get project config and wallet registry
107
- const {
108
- projectConfig,
109
- walletRegistry
110
- } = await this.getProjectAndWalletConfig();
111
-
112
- // init config
113
- this.initUIConfig(projectConfig);
114
- super.initAccountAbstractionConfig(projectConfig);
115
- super.initChainsConfig(projectConfig);
116
- super.initCachedConnectorAndChainId();
117
-
118
- // init login modal
119
- const {
120
- filteredWalletRegistry,
121
- disabledExternalWallets
122
- } = this.filterWalletRegistry(walletRegistry, projectConfig);
123
- this.loginModal = new LoginModal(_objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
124
- connectorListener: this,
125
- web3authClientId: this.options.clientId,
126
- web3authNetwork: this.options.web3AuthNetwork,
127
- authBuildEnv: this.options.authBuildEnv,
128
- chainNamespaces: this.getChainNamespaces(),
129
- walletRegistry: filteredWalletRegistry
130
- }), {
131
- onInitExternalWallets: this.onInitExternalWallets,
132
- onSocialLogin: this.onSocialLogin,
133
- onExternalWalletLogin: this.onExternalWalletLogin,
134
- onModalVisibility: this.onModalVisibility
101
+ async init(options) {
102
+ // init analytics
103
+ const startTime = Date.now();
104
+ this.analytics.init();
105
+ this.analytics.identify(this.options.clientId, {
106
+ web3auth_client_id: this.options.clientId,
107
+ web3auth_network: this.options.web3AuthNetwork
135
108
  });
136
- await withAbort(() => this.loginModal.initModal(), signal);
137
-
138
- // setup common JRPC provider
139
- await withAbort(() => this.setupCommonJRPCProvider(), signal);
140
-
141
- // initialize connectors
142
- this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({
143
- connectors: newConnectors
144
- }) => {
145
- const onAbortHandler = () => {
146
- var _this$connectors;
147
- log.debug("init aborted");
148
- if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
149
- super.cleanup();
150
- }
151
- };
152
- withAbort(() => this.initConnectors({
153
- connectors: newConnectors,
109
+ this.analytics.setGlobalProperties({
110
+ dapp_url: window.location.origin,
111
+ sdk_name: ANALYTICS_SDK_TYPE.WEB_MODAL,
112
+ sdk_version: sdkVersion
113
+ });
114
+ let trackData = {};
115
+ try {
116
+ var _authConnector$authIn, _this$coreOptions$uiC;
117
+ const {
118
+ signal
119
+ } = options || {};
120
+ super.checkInitRequirements();
121
+ // get project config and wallet registry
122
+ const {
154
123
  projectConfig,
124
+ walletRegistry
125
+ } = await this.getProjectAndWalletConfig();
126
+
127
+ // init config
128
+ this.initUIConfig(projectConfig);
129
+ super.initAccountAbstractionConfig(projectConfig);
130
+ super.initChainsConfig(projectConfig);
131
+ super.initCachedConnectorAndChainId();
132
+ super.initWalletServicesConfig(projectConfig);
133
+ trackData = this.getInitializationTrackData();
134
+
135
+ // init login modal
136
+ const {
137
+ filteredWalletRegistry,
155
138
  disabledExternalWallets
156
- }), signal, onAbortHandler);
157
- });
158
- await withAbort(() => super.loadConnectors({
159
- projectConfig,
160
- modalMode: true
161
- }), signal);
139
+ } = this.filterWalletRegistry(walletRegistry, projectConfig);
140
+ this.loginModal = new LoginModal(_objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
141
+ connectorListener: this,
142
+ web3authClientId: this.options.clientId,
143
+ web3authNetwork: this.options.web3AuthNetwork,
144
+ authBuildEnv: this.options.authBuildEnv,
145
+ chainNamespaces: this.getChainNamespaces(),
146
+ walletRegistry: filteredWalletRegistry,
147
+ analytics: this.analytics
148
+ }), {
149
+ onInitExternalWallets: this.onInitExternalWallets,
150
+ onSocialLogin: this.onSocialLogin,
151
+ onExternalWalletLogin: this.onExternalWalletLogin,
152
+ onModalVisibility: this.onModalVisibility
153
+ });
154
+ await withAbort(() => this.loginModal.initModal(), signal);
162
155
 
163
- // initialize plugins
164
- await withAbort(() => super.initPlugins(), signal);
156
+ // setup common JRPC provider
157
+ await withAbort(() => this.setupCommonJRPCProvider(), signal);
158
+
159
+ // initialize connectors
160
+ this.on(CONNECTOR_EVENTS.CONNECTORS_UPDATED, ({
161
+ connectors: newConnectors
162
+ }) => {
163
+ const onAbortHandler = () => {
164
+ var _this$connectors;
165
+ log.debug("init aborted");
166
+ if (((_this$connectors = this.connectors) === null || _this$connectors === void 0 ? void 0 : _this$connectors.length) > 0) {
167
+ super.cleanup();
168
+ }
169
+ };
170
+ withAbort(() => this.initConnectors({
171
+ connectors: newConnectors,
172
+ projectConfig,
173
+ disabledExternalWallets
174
+ }), signal, onAbortHandler);
175
+ });
176
+ await withAbort(() => super.loadConnectors({
177
+ projectConfig,
178
+ modalMode: true
179
+ }), signal);
180
+
181
+ // initialize plugins
182
+ await withAbort(() => super.initPlugins(), signal);
183
+
184
+ // track completion event
185
+ const authConnector = this.getConnector(WALLET_CONNECTORS.AUTH);
186
+ trackData = _objectSpread(_objectSpread({}, trackData), {}, {
187
+ connectors: this.connectors.map(connector => connector.name),
188
+ plugins: Object.keys(this.plugins),
189
+ auth_ux_mode: (authConnector === null || authConnector === void 0 || (_authConnector$authIn = authConnector.authInstance) === null || _authConnector$authIn === void 0 || (_authConnector$authIn = _authConnector$authIn.options) === null || _authConnector$authIn === void 0 ? void 0 : _authConnector$authIn.uxMode) || ((_this$coreOptions$uiC = this.coreOptions.uiConfig) === null || _this$coreOptions$uiC === void 0 ? void 0 : _this$coreOptions$uiC.uxMode)
190
+ });
191
+ this.analytics.track(ANALYTICS_EVENTS.SDK_INITIALIZATION_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
192
+ duration: Date.now() - startTime
193
+ }));
194
+ } catch (error) {
195
+ if (error instanceof DOMException && error.name === "AbortError") return;
196
+
197
+ // track failure event
198
+ this.analytics.track(ANALYTICS_EVENTS.SDK_INITIALIZATION_FAILED, _objectSpread(_objectSpread(_objectSpread({}, trackData), getErrorAnalyticsProperties(error)), {}, {
199
+ duration: Date.now() - startTime
200
+ }));
201
+ log.error("Failed to initialize modal", error);
202
+ throw error;
203
+ }
165
204
  }
166
205
  async connect() {
167
206
  if (!this.loginModal) throw WalletInitializationError.notReady("Login modal is not initialized");
@@ -194,6 +233,50 @@ class Web3Auth extends Web3AuthNoModal {
194
233
  this.once(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, handleVisibility);
195
234
  });
196
235
  }
236
+ initUIConfig(projectConfig) {
237
+ super.initUIConfig(projectConfig);
238
+ this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
239
+ if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
240
+ if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
241
+ this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig, {
242
+ arrayMerge: (_, sourceArray) => sourceArray
243
+ });
244
+
245
+ // merge login methods order from project config and user config, with user config taking precedence
246
+ const defaultAuthConnections = projectConfig.embeddedWalletAuth.filter(x => x.isDefault).map(x => x.authConnection);
247
+ const mergedAuthConnections = [...(this.options.uiConfig.loginMethodsOrder || []), ...defaultAuthConnections];
248
+ const loginMethodsOrder = [];
249
+ const authConnectionSet = new Set();
250
+ for (const authConnection of mergedAuthConnections) {
251
+ if (authConnectionSet.has(authConnection)) continue;
252
+ authConnectionSet.add(authConnection);
253
+ loginMethodsOrder.push(authConnection);
254
+ }
255
+ this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
256
+ }
257
+ getInitializationTrackData() {
258
+ var _this$modalConfig, _this$modalConfig2, _this$modalConfig3, _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3, _this$options$uiConfi4, _this$options$uiConfi5, _this$options$uiConfi6, _this$options$uiConfi7, _this$options$uiConfi8, _this$options$uiConfi9, _this$options$uiConfi0, _this$options$uiConfi1, _this$options$uiConfi10, _this$options$uiConfi11, _this$options$uiConfi12;
259
+ return _objectSpread(_objectSpread({}, super.getInitializationTrackData()), {}, {
260
+ modal_hide_wallet_discovery: (_this$modalConfig = this.modalConfig) === null || _this$modalConfig === void 0 ? void 0 : _this$modalConfig.hideWalletDiscovery,
261
+ modal_connectors: Object.keys(((_this$modalConfig2 = this.modalConfig) === null || _this$modalConfig2 === void 0 ? void 0 : _this$modalConfig2.connectors) || {}),
262
+ modal_auth_connector_login_methods: Object.keys(((_this$modalConfig3 = this.modalConfig) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3.connectors) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3[WALLET_CONNECTORS.AUTH]) === null || _this$modalConfig3 === void 0 ? void 0 : _this$modalConfig3.loginMethods) || {}),
263
+ // UI config
264
+ ui_login_methods_order: (_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.loginMethodsOrder,
265
+ ui_modal_z_index: (_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.modalZIndex,
266
+ ui_display_errors_on_modal: (_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.displayErrorsOnModal,
267
+ ui_login_grid_col: (_this$options$uiConfi4 = this.options.uiConfig) === null || _this$options$uiConfi4 === void 0 ? void 0 : _this$options$uiConfi4.loginGridCol,
268
+ ui_primary_button: (_this$options$uiConfi5 = this.options.uiConfig) === null || _this$options$uiConfi5 === void 0 ? void 0 : _this$options$uiConfi5.primaryButton,
269
+ ui_modal_widget_type: (_this$options$uiConfi6 = this.options.uiConfig) === null || _this$options$uiConfi6 === void 0 ? void 0 : _this$options$uiConfi6.widgetType,
270
+ ui_modal_target_id_used: Boolean((_this$options$uiConfi7 = this.options.uiConfig) === null || _this$options$uiConfi7 === void 0 ? void 0 : _this$options$uiConfi7.targetId),
271
+ ui_modal_logo_alignment: (_this$options$uiConfi8 = this.options.uiConfig) === null || _this$options$uiConfi8 === void 0 ? void 0 : _this$options$uiConfi8.logoAlignment,
272
+ ui_modal_border_radius_type: (_this$options$uiConfi9 = this.options.uiConfig) === null || _this$options$uiConfi9 === void 0 ? void 0 : _this$options$uiConfi9.borderRadiusType,
273
+ ui_modal_button_radius_type: (_this$options$uiConfi0 = this.options.uiConfig) === null || _this$options$uiConfi0 === void 0 ? void 0 : _this$options$uiConfi0.buttonRadiusType,
274
+ ui_modal_sign_in_methods: (_this$options$uiConfi1 = this.options.uiConfig) === null || _this$options$uiConfi1 === void 0 ? void 0 : _this$options$uiConfi1.signInMethods,
275
+ ui_modal_add_previous_login_hint: (_this$options$uiConfi10 = this.options.uiConfig) === null || _this$options$uiConfi10 === void 0 ? void 0 : _this$options$uiConfi10.addPreviousLoginHint,
276
+ ui_modal_display_installed_external_wallets: (_this$options$uiConfi11 = this.options.uiConfig) === null || _this$options$uiConfi11 === void 0 ? void 0 : _this$options$uiConfi11.displayInstalledExternalWallets,
277
+ ui_modal_display_external_wallets_count: (_this$options$uiConfi12 = this.options.uiConfig) === null || _this$options$uiConfi12 === void 0 ? void 0 : _this$options$uiConfi12.displayExternalWalletsCount
278
+ });
279
+ }
197
280
  filterWalletRegistry(walletRegistry, projectConfig) {
198
281
  const {
199
282
  disableAllRecommendedWallets,
@@ -224,7 +307,7 @@ class Web3Auth extends Web3AuthNoModal {
224
307
  };
225
308
  }
226
309
  async getProjectAndWalletConfig() {
227
- var _this$options$account, _this$modalConfig;
310
+ var _this$options$account, _this$modalConfig4;
228
311
  const [projectConfigResult, walletRegistryResult] = await Promise.allSettled([fetchProjectConfig({
229
312
  clientId: this.options.clientId,
230
313
  web3AuthNetwork: this.options.web3AuthNetwork,
@@ -246,7 +329,7 @@ class Web3Auth extends Web3AuthNoModal {
246
329
  default: {}
247
330
  };
248
331
  const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
249
- if (isExternalWalletEnabled && !((_this$modalConfig = this.modalConfig) !== null && _this$modalConfig !== void 0 && _this$modalConfig.hideWalletDiscovery)) {
332
+ if (isExternalWalletEnabled && !((_this$modalConfig4 = this.modalConfig) !== null && _this$modalConfig4 !== void 0 && _this$modalConfig4.hideWalletDiscovery)) {
250
333
  if (walletRegistryResult.status === "fulfilled") {
251
334
  walletRegistry = walletRegistryResult.value;
252
335
  } else {
@@ -258,26 +341,6 @@ class Web3Auth extends Web3AuthNoModal {
258
341
  walletRegistry
259
342
  };
260
343
  }
261
- initUIConfig(projectConfig) {
262
- this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
263
- if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
264
- if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
265
- this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig, {
266
- arrayMerge: (_, sourceArray) => sourceArray
267
- });
268
-
269
- // merge login methods order from project config and user config, with user config taking precedence
270
- const defaultAuthConnections = projectConfig.embeddedWalletAuth.filter(x => x.isDefault).map(x => x.authConnection);
271
- const mergedAuthConnections = [...(this.options.uiConfig.loginMethodsOrder || []), ...defaultAuthConnections];
272
- const loginMethodsOrder = [];
273
- const authConnectionSet = new Set();
274
- for (const authConnection of mergedAuthConnections) {
275
- if (authConnectionSet.has(authConnection)) continue;
276
- authConnectionSet.add(authConnection);
277
- loginMethodsOrder.push(authConnection);
278
- }
279
- this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
280
- }
281
344
  async initConnectors({
282
345
  connectors,
283
346
  projectConfig,
@@ -328,7 +391,7 @@ class Web3Auth extends Web3AuthNoModal {
328
391
  projectConfig,
329
392
  disabledExternalWallets
330
393
  }) {
331
- var _this$modalConfig2;
394
+ var _this$modalConfig5;
332
395
  // Auth connector config: populate this with the default config for auth connectors.
333
396
  const loginMethods = {};
334
397
  const embedWalletConfigMap = new Map();
@@ -360,7 +423,7 @@ class Web3Auth extends Web3AuthNoModal {
360
423
  };
361
424
 
362
425
  // populate the user config data with the dashboard config.
363
- if ((_this$modalConfig2 = this.modalConfig) !== null && _this$modalConfig2 !== void 0 && (_this$modalConfig2 = _this$modalConfig2.connectors) !== null && _this$modalConfig2 !== void 0 && _this$modalConfig2[WALLET_CONNECTORS.AUTH]) {
426
+ if ((_this$modalConfig5 = this.modalConfig) !== null && _this$modalConfig5 !== void 0 && (_this$modalConfig5 = _this$modalConfig5.connectors) !== null && _this$modalConfig5 !== void 0 && _this$modalConfig5[WALLET_CONNECTORS.AUTH]) {
364
427
  if (!this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods) this.modalConfig.connectors[WALLET_CONNECTORS.AUTH].loginMethods = {};
365
428
  }
366
429
  const authProviders = new Set(AUTH_PROVIDERS);
@@ -392,13 +455,13 @@ class Web3Auth extends Web3AuthNoModal {
392
455
  // merge default connectors with the custom configured connectors.
393
456
  const allConnectorNames = [...new Set([...Object.keys(this.modalConfig.connectors || {}), ...this.connectors.map(connector => connector.name)])];
394
457
  const connectorNames = allConnectorNames.map(connectorName => {
395
- var _this$modalConfig3, _this$modalConfig$con, _this$modalConfig$con2;
458
+ var _this$modalConfig6, _this$modalConfig$con, _this$modalConfig$con2;
396
459
  // start with the default config of connector.
397
460
  const defaultConnectorConfig = {
398
461
  label: CONNECTOR_NAMES[connectorName] || connectorName.split("-").map(capitalizeFirstLetter).join(" "),
399
462
  showOnModal: true
400
463
  };
401
- this.modalConfig.connectors[connectorName] = _objectSpread(_objectSpread({}, defaultConnectorConfig), ((_this$modalConfig3 = this.modalConfig) === null || _this$modalConfig3 === void 0 || (_this$modalConfig3 = _this$modalConfig3.connectors) === null || _this$modalConfig3 === void 0 ? void 0 : _this$modalConfig3[connectorName]) || {});
464
+ this.modalConfig.connectors[connectorName] = _objectSpread(_objectSpread({}, defaultConnectorConfig), ((_this$modalConfig6 = this.modalConfig) === null || _this$modalConfig6 === void 0 || (_this$modalConfig6 = _this$modalConfig6.connectors) === null || _this$modalConfig6 === void 0 ? void 0 : _this$modalConfig6[connectorName]) || {});
402
465
 
403
466
  // check if connector is configured/added by user and exist in connectors map.
404
467
  const connector = this.getConnector(connectorName);
@@ -423,9 +486,9 @@ class Web3Auth extends Web3AuthNoModal {
423
486
 
424
487
  // skip WC connector if external wallets are disabled or hideWalletDiscovery is true
425
488
  if (connectorName === WALLET_CONNECTORS.WALLET_CONNECT_V2) {
426
- var _this$modalConfig4;
489
+ var _this$modalConfig7;
427
490
  if (!isExternalWalletEnabled) return;
428
- if ((_this$modalConfig4 = this.modalConfig) !== null && _this$modalConfig4 !== void 0 && _this$modalConfig4.hideWalletDiscovery) return;
491
+ if ((_this$modalConfig7 = this.modalConfig) !== null && _this$modalConfig7 !== void 0 && _this$modalConfig7.hideWalletDiscovery) return;
429
492
  }
430
493
  this.modalConfig.connectors[connectorName] = connectorConfig;
431
494
  return connectorName;
@@ -480,12 +543,12 @@ class Web3Auth extends Web3AuthNoModal {
480
543
  // note: not adding cachedWallet to modal if it is external wallet.
481
544
  // adding it later if no in-app wallets are available.
482
545
  if (connector.type === CONNECTOR_CATEGORY.IN_APP) {
483
- var _this$modalConfig$con6, _this$options$uiConfi, _this$options$uiConfi2, _this$options$uiConfi3;
546
+ var _this$modalConfig$con6, _this$options$uiConfi13, _this$options$uiConfi14, _this$options$uiConfi15;
484
547
  log.info("connectorInitResults", connectorName);
485
548
  const loginMethods = ((_this$modalConfig$con6 = this.modalConfig.connectors[connectorName]) === null || _this$modalConfig$con6 === void 0 ? void 0 : _this$modalConfig$con6.loginMethods) || {};
486
- this.loginModal.addSocialLogins(connectorName, loginMethods, ((_this$options$uiConfi = this.options.uiConfig) === null || _this$options$uiConfi === void 0 ? void 0 : _this$options$uiConfi.loginMethodsOrder) || AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
487
- loginGridCol: ((_this$options$uiConfi2 = this.options.uiConfig) === null || _this$options$uiConfi2 === void 0 ? void 0 : _this$options$uiConfi2.loginGridCol) || 3,
488
- primaryButton: ((_this$options$uiConfi3 = this.options.uiConfig) === null || _this$options$uiConfi3 === void 0 ? void 0 : _this$options$uiConfi3.primaryButton) || "socialLogin"
549
+ this.loginModal.addSocialLogins(connectorName, loginMethods, ((_this$options$uiConfi13 = this.options.uiConfig) === null || _this$options$uiConfi13 === void 0 ? void 0 : _this$options$uiConfi13.loginMethodsOrder) || AUTH_PROVIDERS, _objectSpread(_objectSpread({}, this.options.uiConfig), {}, {
550
+ loginGridCol: ((_this$options$uiConfi14 = this.options.uiConfig) === null || _this$options$uiConfi14 === void 0 ? void 0 : _this$options$uiConfi14.loginGridCol) || 3,
551
+ primaryButton: ((_this$options$uiConfi15 = this.options.uiConfig) === null || _this$options$uiConfi15 === void 0 ? void 0 : _this$options$uiConfi15.primaryButton) || "socialLogin"
489
552
  }));
490
553
  }
491
554
  } catch (error) {
@@ -0,0 +1 @@
1
+ export * from '@web3auth/no-modal/providers/ethereum-mpc-provider';
@@ -0,0 +1 @@
1
+ export * from '@web3auth/no-modal/providers/xrpl-provider';
@@ -4,13 +4,15 @@ import { Web3AuthInnerProvider, Web3AuthInnerContext } from './context/Web3AuthI
4
4
 
5
5
  function Web3AuthProvider({
6
6
  config,
7
+ initialState,
7
8
  children
8
9
  }) {
9
10
  const pluginChild = /*#__PURE__*/createElement(WalletServicesContextProvider, {
10
11
  context: Web3AuthInnerContext
11
12
  }, children);
12
13
  return /*#__PURE__*/createElement(Web3AuthInnerProvider, {
13
- config
14
+ config,
15
+ initialState
14
16
  }, pluginChild);
15
17
  }
16
18
 
@@ -1,45 +1,42 @@
1
- import { WalletInitializationError, CONNECTOR_EVENTS, CONNECTOR_STATUS } from '@web3auth/no-modal';
2
- import { createContext, useState, useCallback, useEffect, useMemo, createElement } from 'react';
1
+ import { CONNECTOR_STATUS, WalletInitializationError, CONNECTOR_EVENTS, ANALYTICS_INTEGRATION_TYPE } from '@web3auth/no-modal';
2
+ import { createContext, useState, useMemo, useCallback, useEffect, createElement } from 'react';
3
3
  import { Web3Auth } from '../../modalManager.js';
4
4
 
5
5
  const Web3AuthInnerContext = /*#__PURE__*/createContext(null);
6
6
  function Web3AuthInnerProvider(params) {
7
7
  const {
8
8
  children,
9
- config
9
+ config,
10
+ initialState
10
11
  } = params;
11
- const [web3Auth, setWeb3Auth] = useState(null);
12
+ const {
13
+ web3AuthOptions
14
+ } = config;
12
15
  const [isInitializing, setIsInitializing] = useState(false);
13
16
  const [initError, setInitError] = useState(null);
14
- const [isConnected, setIsConnected] = useState(false);
15
17
  const [provider, setProvider] = useState(null);
16
18
  const [isInitialized, setIsInitialized] = useState(false);
17
- const [status, setStatus] = useState(null);
18
19
  const [isMFAEnabled, setIsMFAEnabled] = useState(false);
20
+ const web3Auth = useMemo(() => {
21
+ setProvider(null);
22
+ return new Web3Auth(web3AuthOptions, initialState);
23
+ }, [web3AuthOptions, initialState]);
24
+ const [isConnected, setIsConnected] = useState(web3Auth.status === CONNECTOR_STATUS.CONNECTED);
25
+ const [status, setStatus] = useState(web3Auth.status);
19
26
  const getPlugin = useCallback(name => {
20
27
  if (!web3Auth) throw WalletInitializationError.notReady();
21
28
  return web3Auth.getPlugin(name);
22
29
  }, [web3Auth]);
23
- useEffect(() => {
24
- const resetHookState = () => {
25
- setProvider(null);
26
- setIsConnected(false);
27
- setStatus(null);
28
- };
29
- resetHookState();
30
- const {
31
- web3AuthOptions
32
- } = config;
33
- const web3AuthInstance = new Web3Auth(web3AuthOptions);
34
- setWeb3Auth(web3AuthInstance);
35
- }, [config]);
36
30
  useEffect(() => {
37
31
  const controller = new AbortController();
38
32
  async function init() {
39
33
  try {
40
34
  setInitError(null);
41
35
  setIsInitializing(true);
42
- await web3Auth.initModal({
36
+ web3Auth.setAnalyticsProperties({
37
+ integration_type: ANALYTICS_INTEGRATION_TYPE.REACT_HOOKS
38
+ });
39
+ await web3Auth.init({
43
40
  signal: controller.signal
44
41
  });
45
42
  } catch (error) {
@@ -77,7 +74,12 @@ function Web3AuthInnerProvider(params) {
77
74
  setStatus(web3Auth.status);
78
75
  };
79
76
  const errorListener = () => {
80
- setStatus(CONNECTOR_STATUS.ERRORED);
77
+ setStatus(web3Auth.status);
78
+ };
79
+ const rehydrationErrorListener = () => {
80
+ setStatus(web3Auth.status);
81
+ setIsConnected(false);
82
+ setProvider(null);
81
83
  };
82
84
  const mfaEnabledListener = isMFAEnabled => {
83
85
  if (typeof isMFAEnabled === "boolean") setIsMFAEnabled(isMFAEnabled);
@@ -91,6 +93,7 @@ function Web3AuthInnerProvider(params) {
91
93
  web3Auth.on(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
92
94
  web3Auth.on(CONNECTOR_EVENTS.CONNECTING, connectingListener);
93
95
  web3Auth.on(CONNECTOR_EVENTS.ERRORED, errorListener);
96
+ web3Auth.on(CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
94
97
  web3Auth.on(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
95
98
  }
96
99
  return () => {
@@ -101,6 +104,7 @@ function Web3AuthInnerProvider(params) {
101
104
  web3Auth.off(CONNECTOR_EVENTS.DISCONNECTED, disconnectedListener);
102
105
  web3Auth.off(CONNECTOR_EVENTS.CONNECTING, connectingListener);
103
106
  web3Auth.off(CONNECTOR_EVENTS.ERRORED, errorListener);
107
+ web3Auth.off(CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
104
108
  web3Auth.off(CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
105
109
  web3Auth.cleanup();
106
110
  }
@@ -9,11 +9,11 @@ const useIdentityToken = () => {
9
9
  const [loading, setLoading] = useState(false);
10
10
  const [error, setError] = useState(null);
11
11
  const [token, setToken] = useState(null);
12
- const authenticateUser = useCallback(async () => {
12
+ const getIdentityToken = useCallback(async () => {
13
13
  setLoading(true);
14
14
  setError(null);
15
15
  try {
16
- const userAuthInfo = await web3Auth.authenticateUser();
16
+ const userAuthInfo = await web3Auth.getIdentityToken();
17
17
  if (userAuthInfo !== null && userAuthInfo !== void 0 && userAuthInfo.idToken) {
18
18
  setToken(userAuthInfo.idToken);
19
19
  }
@@ -33,7 +33,7 @@ const useIdentityToken = () => {
33
33
  loading,
34
34
  error,
35
35
  token,
36
- authenticateUser
36
+ getIdentityToken
37
37
  };
38
38
  };
39
39
 
@@ -33,12 +33,28 @@ const useWeb3AuthConnect = () => {
33
33
  setLoading(false);
34
34
  }
35
35
  }, [web3Auth]);
36
+ const connectTo = useCallback(async (connector, params) => {
37
+ setLoading(true);
38
+ setError(null);
39
+ try {
40
+ const provider = await web3Auth.connectTo(connector, params);
41
+ if (provider) {
42
+ setConnectorName(web3Auth.connectedConnectorName);
43
+ }
44
+ return provider;
45
+ } catch (error) {
46
+ setError(error);
47
+ } finally {
48
+ setLoading(false);
49
+ }
50
+ }, [web3Auth]);
36
51
  return {
37
52
  isConnected,
38
53
  loading,
39
54
  error,
40
55
  connectorName,
41
- connect
56
+ connect,
57
+ connectTo
42
58
  };
43
59
  };
44
60
 
@@ -1,5 +1,5 @@
1
1
  import { Connection } from '@solana/web3.js';
2
- import { SolanaWallet } from '@web3auth/no-modal';
2
+ import { SolanaWallet, CHAIN_NAMESPACES } from '@web3auth/no-modal';
3
3
  import { useState, useMemo, useEffect } from 'react';
4
4
  import { useWeb3Auth } from '../../hooks/useWeb3Auth.js';
5
5
 
@@ -19,6 +19,10 @@ const useSolanaWallet = () => {
19
19
  }, [web3Auth, provider]);
20
20
  useEffect(() => {
21
21
  const init = async () => {
22
+ var _web3Auth$currentChai;
23
+ if (!(web3Auth !== null && web3Auth !== void 0 && (_web3Auth$currentChai = web3Auth.currentChain) !== null && _web3Auth$currentChai !== void 0 && _web3Auth$currentChai.chainNamespace) || web3Auth.currentChain.chainNamespace !== CHAIN_NAMESPACES.SOLANA) {
24
+ return;
25
+ }
22
26
  if (!solanaWallet) return;
23
27
  const accounts = await solanaWallet.requestAccounts();
24
28
  if ((accounts === null || accounts === void 0 ? void 0 : accounts.length) > 0) {
@@ -0,0 +1,14 @@
1
+ import { createConfig, http } from 'wagmi';
2
+ import { mainnet } from 'wagmi/chains';
3
+
4
+ const defaultWagmiConfig = createConfig({
5
+ chains: [mainnet],
6
+ connectors: [],
7
+ // or your basic wallets
8
+ ssr: true,
9
+ transports: {
10
+ [mainnet.id]: http(mainnet.rpcUrls.default.http[0])
11
+ }
12
+ });
13
+
14
+ export { defaultWagmiConfig };