@web3auth/modal 4.6.2 → 5.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.
@@ -1,8 +1,8 @@
1
1
  import { SafeEventEmitterProvider, WALLET_ADAPTER_TYPE } from "@web3auth/base";
2
- import { Web3AuthCore, Web3AuthCoreOptions } from "@web3auth/core";
2
+ import { Web3AuthNoModal, Web3AuthNoModalOptions } from "@web3auth/no-modal";
3
3
  import { LoginModal, UIConfig } from "@web3auth/ui";
4
4
  import { IWeb3AuthModal, ModalConfig } from "./interface";
5
- export interface Web3AuthOptions extends Web3AuthCoreOptions {
5
+ export interface Web3AuthOptions extends Web3AuthNoModalOptions {
6
6
  /**
7
7
  * web3auth instance provides different adapters for different type of usages. If you are dapp and want to
8
8
  * use external wallets like metamask, then you can use the `DAPP` authMode.
@@ -17,7 +17,7 @@ export interface Web3AuthOptions extends Web3AuthCoreOptions {
17
17
  */
18
18
  uiConfig?: Omit<UIConfig, "adapterListener">;
19
19
  }
20
- export declare class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
20
+ export declare class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
21
21
  loginModal: LoginModal;
22
22
  readonly options: Web3AuthOptions;
23
23
  private modalConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web3auth/modal",
3
- "version": "4.6.2",
3
+ "version": "5.0.0",
4
4
  "homepage": "https://github.com/Web3Auth/Web3Auth#readme",
5
5
  "license": "ISC",
6
6
  "main": "dist/modal.cjs.js",
@@ -19,28 +19,29 @@
19
19
  "pre-commit": "lint-staged --cwd ."
20
20
  },
21
21
  "dependencies": {
22
- "@web3auth/base": "^4.6.0",
23
- "@web3auth/core": "^4.6.0",
24
- "@web3auth/metamask-adapter": "^4.6.0",
25
- "@web3auth/openlogin-adapter": "^4.6.0",
26
- "@web3auth/phantom-adapter": "^4.6.0",
27
- "@web3auth/torus-evm-adapter": "^4.6.0",
28
- "@web3auth/torus-solana-adapter": "^4.6.0",
29
- "@web3auth/ui": "^4.6.2",
30
- "@web3auth/wallet-connect-v1-adapter": "^4.6.0"
22
+ "@web3auth/base": "^5.0.0",
23
+ "@web3auth/metamask-adapter": "^5.0.0",
24
+ "@web3auth/no-modal": "^5.0.0",
25
+ "@web3auth/openlogin-adapter": "^5.0.0",
26
+ "@web3auth/phantom-adapter": "^5.0.0",
27
+ "@web3auth/torus-evm-adapter": "^5.0.0",
28
+ "@web3auth/torus-solana-adapter": "^5.0.0",
29
+ "@web3auth/ui": "^5.0.0",
30
+ "@web3auth/wallet-connect-v1-adapter": "^5.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@svgr/webpack": "^6.5.1",
34
34
  "@toruslabs/isomorphic-style-loader": "^5.3.3",
35
- "@toruslabs/openlogin": "^3.1.0",
35
+ "@toruslabs/openlogin": "^3.2.1",
36
36
  "css-loader": "^6.7.3",
37
37
  "postcss-prefix-selector": "^1.16.0",
38
- "style-loader": "^3.3.1",
39
- "tailwindcss": "^3.2.6",
38
+ "style-loader": "^3.3.2",
39
+ "tailwindcss": "^3.2.7",
40
40
  "url-loader": "^4.1.1"
41
41
  },
42
42
  "peerDependencies": {
43
- "@babel/runtime": "7.x"
43
+ "@babel/runtime": "7.x",
44
+ "@solana/web3.js": "^1.x"
44
45
  },
45
46
  "files": [
46
47
  "dist",
@@ -63,5 +64,5 @@
63
64
  "publishConfig": {
64
65
  "access": "public"
65
66
  },
66
- "gitHead": "4c7feb39f21f4c944c8430f09198bf3e8e7fb976"
67
+ "gitHead": "8702657a42f44ff5ebc0a4be796e68a10f506dde"
67
68
  }
@@ -12,7 +12,7 @@ import {
12
12
  WALLET_ADAPTER_TYPE,
13
13
  WALLET_ADAPTERS,
14
14
  } from "@web3auth/base";
15
- import { Web3AuthCore, Web3AuthCoreOptions } from "@web3auth/core";
15
+ import { Web3AuthNoModal, Web3AuthNoModalOptions } from "@web3auth/no-modal";
16
16
  import { getAdapterSocialLogins, LOGIN_MODAL_EVENTS, LoginModal, OPENLOGIN_PROVIDERS, UIConfig } from "@web3auth/ui";
17
17
 
18
18
  import {
@@ -26,7 +26,7 @@ import { getDefaultAdapterModule } from "./default";
26
26
  import { AdaptersModalConfig, IWeb3AuthModal, ModalConfig } from "./interface";
27
27
  import { getUserLanguage } from "./utils";
28
28
 
29
- export interface Web3AuthOptions extends Web3AuthCoreOptions {
29
+ export interface Web3AuthOptions extends Web3AuthNoModalOptions {
30
30
  /**
31
31
  * web3auth instance provides different adapters for different type of usages. If you are dapp and want to
32
32
  * use external wallets like metamask, then you can use the `DAPP` authMode.
@@ -42,7 +42,7 @@ export interface Web3AuthOptions extends Web3AuthCoreOptions {
42
42
  uiConfig?: Omit<UIConfig, "adapterListener">;
43
43
  }
44
44
 
45
- export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
45
+ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
46
46
  public loginModal: LoginModal;
47
47
 
48
48
  readonly options: Web3AuthOptions;
@@ -86,6 +86,9 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
86
86
  displayErrorsOnModal: this.options.uiConfig?.displayErrorsOnModal,
87
87
  defaultLanguage,
88
88
  modalZIndex: this.options.uiConfig?.modalZIndex || "99998",
89
+ web3AuthNetwork: this.options.web3AuthNetwork,
90
+ loginGridCol: this.options.uiConfig?.loginGridCol || 3,
91
+ primaryButton: this.options.uiConfig?.primaryButton || "socialLogin",
89
92
  });
90
93
  this.subscribeToLoginModalEvents();
91
94
  }
@@ -130,7 +133,6 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
130
133
  });
131
134
 
132
135
  this.walletAdapters[adapterName] = ad;
133
-
134
136
  return adapterName;
135
137
  } else if (adapter?.type === ADAPTER_CATEGORY.IN_APP || adapter?.type === ADAPTER_CATEGORY.EXTERNAL || adapterName === this.cachedAdapter) {
136
138
  if (!this.modalConfig.adapters?.[adapterName].showOnModal) return;
@@ -156,7 +158,7 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
156
158
  }
157
159
  });
158
160
 
159
- const adapterNames = await Promise.all(adapterConfigurationPromises);
161
+ let adapterNames = await Promise.all(adapterConfigurationPromises);
160
162
  const hasInAppWallets = Object.values(this.walletAdapters).some((adapter) => {
161
163
  if (adapter.type !== ADAPTER_CATEGORY.IN_APP) return false;
162
164
  if (this.modalConfig.adapters?.[adapter.name]?.showOnModal !== true) return false;
@@ -169,7 +171,13 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
169
171
  if (Object.values(mergedLoginMethods).some((method: LoginMethodConfig[keyof LoginMethodConfig]) => method.showOnModal)) return true;
170
172
  return false;
171
173
  });
172
- log.debug(hasInAppWallets, this.walletAdapters, "hasInAppWallets");
174
+ log.debug(hasInAppWallets, this.walletAdapters, adapterNames, "hasInAppWallets");
175
+
176
+ // if both wc1 and wc2 are configured, give precedence to wc2.
177
+ if (this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1] && this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V2]) {
178
+ delete this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1];
179
+ adapterNames = adapterNames.filter((ad) => ad !== WALLET_ADAPTERS.WALLET_CONNECT_V1);
180
+ }
173
181
  // Now, initialize the adapters.
174
182
  const initPromises = adapterNames.map(async (adapterName) => {
175
183
  if (!adapterName) return;
@@ -263,7 +271,12 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
263
271
  this.walletAdapters[adapterName],
264
272
  (this.modalConfig.adapters as Record<WALLET_ADAPTER_TYPE, ModalConfig>)[adapterName]?.loginMethods
265
273
  ),
266
- this.options.uiConfig?.loginMethodsOrder || OPENLOGIN_PROVIDERS
274
+ this.options.uiConfig?.loginMethodsOrder || OPENLOGIN_PROVIDERS,
275
+ {
276
+ ...this.options.uiConfig,
277
+ loginGridCol: this.options.uiConfig?.loginGridCol || 3,
278
+ primaryButton: this.options.uiConfig?.primaryButton || "socialLogin",
279
+ }
267
280
  );
268
281
  }
269
282
  }
@@ -289,13 +302,19 @@ export class Web3Auth extends Web3AuthCore implements IWeb3AuthModal {
289
302
  this.loginModal.on(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, async (visibility: boolean) => {
290
303
  log.debug("is login modal visible", visibility);
291
304
  this.emit(LOGIN_MODAL_EVENTS.MODAL_VISIBILITY, visibility);
292
- const walletConnectStatus = this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1]?.status;
293
- if (visibility && walletConnectStatus === ADAPTER_STATUS.READY) {
294
- // refreshing session for wallet connect whenever modal is opened.
295
- try {
296
- this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1].connect();
297
- } catch (error) {
298
- log.error(`Error while disconnecting to wallet connect in core`, error);
305
+ const adapter = this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V2] || this.walletAdapters[WALLET_ADAPTERS.WALLET_CONNECT_V1];
306
+ if (adapter) {
307
+ const walletConnectStatus = adapter?.status;
308
+ log.debug("trying refreshing wc session", visibility, walletConnectStatus);
309
+ if (visibility && (walletConnectStatus === ADAPTER_STATUS.READY || walletConnectStatus === ADAPTER_STATUS.CONNECTING)) {
310
+ log.debug("refreshing wc session");
311
+
312
+ // refreshing session for wallet connect whenever modal is opened.
313
+ try {
314
+ adapter.connect();
315
+ } catch (error) {
316
+ log.error(`Error while disconnecting to wallet connect in core`, error);
317
+ }
299
318
  }
300
319
  }
301
320
  });