@web3auth/no-modal 10.13.2 → 10.14.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.
@@ -147,7 +147,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
147
147
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
148
148
  };
149
149
  };
150
- const sdkVersion = "10.13.2";
150
+ const sdkVersion = "10.14.0";
151
151
  const getErrorAnalyticsProperties = error => {
152
152
  try {
153
153
  const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -1,7 +1,7 @@
1
- import { ComputedRef } from "vue";
1
+ import { Ref } from "vue";
2
2
  import { ChainNamespaceType } from "../../base";
3
3
  export type IUseChain = {
4
- chainId: ComputedRef<string | null>;
5
- chainNamespace: ComputedRef<ChainNamespaceType | null>;
4
+ chainId: Ref<string | null>;
5
+ chainNamespace: Ref<ChainNamespaceType | null>;
6
6
  };
7
7
  export declare const useChain: () => IUseChain;
@@ -1,5 +1,5 @@
1
1
  import { Ref, ShallowRef } from "vue";
2
- import type { CONNECTOR_STATUS_TYPE, IPlugin, IProvider, IWeb3AuthCoreOptions } from "../base";
2
+ import type { ChainNamespaceType, CONNECTOR_STATUS_TYPE, IPlugin, IProvider, IWeb3AuthCoreOptions } from "../base";
3
3
  import type { Web3AuthNoModal } from "../noModal";
4
4
  import { WalletServicesPluginType } from "../plugins/wallet-services-plugin";
5
5
  export type Web3AuthContextConfig = {
@@ -17,6 +17,8 @@ interface IBaseWeb3AuthComposableContext {
17
17
  isInitialized: Ref<boolean>;
18
18
  status: Ref<CONNECTOR_STATUS_TYPE | null>;
19
19
  isMFAEnabled: Ref<boolean>;
20
+ chainId: Ref<string | null>;
21
+ chainNamespace: Ref<ChainNamespaceType | null>;
20
22
  getPlugin: (pluginName: string) => IPlugin | null;
21
23
  setIsMFAEnabled: (isMfaEnabled: boolean) => void;
22
24
  }
@@ -32,6 +32,8 @@ const Web3AuthProvider = vue.defineComponent({
32
32
  const provider = vue.ref(null);
33
33
  const isMFAEnabled = vue.ref(false);
34
34
  const status = vue.ref(null);
35
+ const chainId = vue.ref(null);
36
+ const chainNamespace = vue.ref(null);
35
37
  const isInitializing = vue.ref(false);
36
38
  const initError = vue.ref(null);
37
39
  const isInitialized = vue.ref(false);
@@ -51,6 +53,8 @@ const Web3AuthProvider = vue.defineComponent({
51
53
  isConnected.value = false;
52
54
  isAuthorized.value = false;
53
55
  status.value = null;
56
+ chainId.value = null;
57
+ chainNamespace.value = null;
54
58
  };
55
59
  onInvalidate(() => {
56
60
  if (web3Auth.value) {
@@ -104,9 +108,12 @@ const Web3AuthProvider = vue.defineComponent({
104
108
  status.value = web3Auth.value.status;
105
109
  // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
106
110
  if (web3Auth.value.status === constants.CONNECTOR_STATUS.CONNECTED) {
111
+ var _web3Auth$value$curre, _web3Auth$value$curre2;
107
112
  if (!isInitialized.value) isInitialized.value = true;
108
113
  isConnected.value = true;
109
114
  provider.value = newWeb3Auth.provider;
115
+ chainId.value = web3Auth.value.currentChainId;
116
+ chainNamespace.value = (_web3Auth$value$curre = (_web3Auth$value$curre2 = web3Auth.value.currentChain) === null || _web3Auth$value$curre2 === void 0 ? void 0 : _web3Auth$value$curre2.chainNamespace) !== null && _web3Auth$value$curre !== void 0 ? _web3Auth$value$curre : null;
110
117
  }
111
118
  };
112
119
  const authorizedListener = () => {
@@ -160,6 +167,23 @@ const Web3AuthProvider = vue.defineComponent({
160
167
  }, {
161
168
  immediate: true
162
169
  });
170
+ // Listen for chain changes on the provider
171
+ vue.watch(provider, (newProvider, prevProvider) => {
172
+ const handleChainChange = newChainId => {
173
+ var _web3Auth$value$curre3, _web3Auth$value;
174
+ chainId.value = newChainId;
175
+ chainNamespace.value = (_web3Auth$value$curre3 = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre3 !== void 0 ? _web3Auth$value$curre3 : null;
176
+ };
177
+ // unregister previous listener
178
+ if (prevProvider && newProvider !== prevProvider) {
179
+ prevProvider.removeListener("chainChanged", handleChainChange);
180
+ }
181
+ if (newProvider && newProvider !== prevProvider) {
182
+ newProvider.on("chainChanged", handleChainChange);
183
+ }
184
+ }, {
185
+ immediate: true
186
+ });
163
187
  vue.provide(index.Web3AuthContextKey, {
164
188
  web3Auth,
165
189
  isConnected,
@@ -169,6 +193,8 @@ const Web3AuthProvider = vue.defineComponent({
169
193
  isInitializing,
170
194
  initError,
171
195
  isMFAEnabled,
196
+ chainId,
197
+ chainNamespace,
172
198
  getPlugin,
173
199
  setIsMFAEnabled,
174
200
  isAuthorized
@@ -1,23 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var vue = require('vue');
4
3
  var useWeb3AuthInner = require('./useWeb3AuthInner.js');
5
4
 
6
5
  const useChain = () => {
7
6
  const context = useWeb3AuthInner.useWeb3AuthInner();
8
- const chainId = vue.computed(() => {
9
- var _context$web3Auth$val;
10
- if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
11
- return context.web3Auth.value.currentChain.chainId;
12
- });
13
- const chainNamespace = vue.computed(() => {
14
- var _context$web3Auth$val2;
15
- if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
16
- return context.web3Auth.value.currentChain.chainNamespace;
17
- });
18
7
  return {
19
- chainId,
20
- chainNamespace
8
+ chainId: context.chainId,
9
+ chainNamespace: context.chainNamespace
21
10
  };
22
11
  };
23
12
 
@@ -12,7 +12,9 @@ const useWeb3Auth = () => {
12
12
  provider,
13
13
  status,
14
14
  web3Auth,
15
- getPlugin
15
+ getPlugin,
16
+ chainId,
17
+ chainNamespace
16
18
  } = useWeb3AuthInner.useWeb3AuthInner();
17
19
  return {
18
20
  initError,
@@ -23,6 +25,8 @@ const useWeb3Auth = () => {
23
25
  provider,
24
26
  status,
25
27
  web3Auth,
28
+ chainId,
29
+ chainNamespace,
26
30
  getPlugin
27
31
  };
28
32
  };
@@ -146,7 +146,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
146
146
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
147
147
  };
148
148
  };
149
- const sdkVersion = "10.13.2";
149
+ const sdkVersion = "10.14.0";
150
150
  const getErrorAnalyticsProperties = error => {
151
151
  try {
152
152
  const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -20,6 +20,8 @@ const Web3AuthProvider = defineComponent({
20
20
  const provider = ref(null);
21
21
  const isMFAEnabled = ref(false);
22
22
  const status = ref(null);
23
+ const chainId = ref(null);
24
+ const chainNamespace = ref(null);
23
25
  const isInitializing = ref(false);
24
26
  const initError = ref(null);
25
27
  const isInitialized = ref(false);
@@ -39,6 +41,8 @@ const Web3AuthProvider = defineComponent({
39
41
  isConnected.value = false;
40
42
  isAuthorized.value = false;
41
43
  status.value = null;
44
+ chainId.value = null;
45
+ chainNamespace.value = null;
42
46
  };
43
47
  onInvalidate(() => {
44
48
  if (web3Auth.value) {
@@ -93,9 +97,12 @@ const Web3AuthProvider = defineComponent({
93
97
  status.value = web3Auth.value.status;
94
98
  // we do this because of rehydration issues. status connected is fired first but web3auth sdk is not ready yet.
95
99
  if (web3Auth.value.status === CONNECTOR_STATUS.CONNECTED) {
100
+ var _currentChain$chainNa, _currentChain;
96
101
  if (!isInitialized.value) isInitialized.value = true;
97
102
  isConnected.value = true;
98
103
  provider.value = newWeb3Auth.provider;
104
+ chainId.value = web3Auth.value.currentChainId;
105
+ chainNamespace.value = (_currentChain$chainNa = (_currentChain = web3Auth.value.currentChain) === null || _currentChain === void 0 ? void 0 : _currentChain.chainNamespace) !== null && _currentChain$chainNa !== void 0 ? _currentChain$chainNa : null;
99
106
  }
100
107
  };
101
108
  const authorizedListener = () => {
@@ -150,6 +157,25 @@ const Web3AuthProvider = defineComponent({
150
157
  }, {
151
158
  immediate: true
152
159
  });
160
+
161
+ // Listen for chain changes on the provider
162
+ watch(provider, (newProvider, prevProvider) => {
163
+ const handleChainChange = newChainId => {
164
+ var _web3Auth$value$curre, _web3Auth$value;
165
+ chainId.value = newChainId;
166
+ chainNamespace.value = (_web3Auth$value$curre = (_web3Auth$value = web3Auth.value) === null || _web3Auth$value === void 0 || (_web3Auth$value = _web3Auth$value.currentChain) === null || _web3Auth$value === void 0 ? void 0 : _web3Auth$value.chainNamespace) !== null && _web3Auth$value$curre !== void 0 ? _web3Auth$value$curre : null;
167
+ };
168
+
169
+ // unregister previous listener
170
+ if (prevProvider && newProvider !== prevProvider) {
171
+ prevProvider.removeListener("chainChanged", handleChainChange);
172
+ }
173
+ if (newProvider && newProvider !== prevProvider) {
174
+ newProvider.on("chainChanged", handleChainChange);
175
+ }
176
+ }, {
177
+ immediate: true
178
+ });
153
179
  provide(Web3AuthContextKey, {
154
180
  web3Auth,
155
181
  isConnected,
@@ -159,6 +185,8 @@ const Web3AuthProvider = defineComponent({
159
185
  isInitializing,
160
186
  initError,
161
187
  isMFAEnabled,
188
+ chainId,
189
+ chainNamespace,
162
190
  getPlugin,
163
191
  setIsMFAEnabled,
164
192
  isAuthorized
@@ -1,21 +1,10 @@
1
- import { computed } from 'vue';
2
1
  import { useWeb3AuthInner } from './useWeb3AuthInner.js';
3
2
 
4
3
  const useChain = () => {
5
4
  const context = useWeb3AuthInner();
6
- const chainId = computed(() => {
7
- var _context$web3Auth$val;
8
- if (!((_context$web3Auth$val = context.web3Auth.value) !== null && _context$web3Auth$val !== void 0 && _context$web3Auth$val.currentChain)) return null;
9
- return context.web3Auth.value.currentChain.chainId;
10
- });
11
- const chainNamespace = computed(() => {
12
- var _context$web3Auth$val2;
13
- if (!((_context$web3Auth$val2 = context.web3Auth.value) !== null && _context$web3Auth$val2 !== void 0 && _context$web3Auth$val2.currentChain)) return null;
14
- return context.web3Auth.value.currentChain.chainNamespace;
15
- });
16
5
  return {
17
- chainId,
18
- chainNamespace
6
+ chainId: context.chainId,
7
+ chainNamespace: context.chainNamespace
19
8
  };
20
9
  };
21
10
 
@@ -10,7 +10,9 @@ const useWeb3Auth = () => {
10
10
  provider,
11
11
  status,
12
12
  web3Auth,
13
- getPlugin
13
+ getPlugin,
14
+ chainId,
15
+ chainNamespace
14
16
  } = useWeb3AuthInner();
15
17
  return {
16
18
  initError,
@@ -21,6 +23,8 @@ const useWeb3Auth = () => {
21
23
  provider,
22
24
  status,
23
25
  web3Auth,
26
+ chainId,
27
+ chainNamespace,
24
28
  getPlugin
25
29
  };
26
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web3auth/no-modal",
3
- "version": "10.13.2",
3
+ "version": "10.14.0",
4
4
  "description": "Multi chain wallet aggregator for web3Auth",
5
5
  "keywords": [
6
6
  "web3Auth/no-modal",
@@ -203,5 +203,5 @@
203
203
  "node": ">=20.x",
204
204
  "npm": ">=9.x"
205
205
  },
206
- "gitHead": "baf197386d786fd4b7b3e1de549fbff5ec74e7dc"
206
+ "gitHead": "07760538ad7ad9feadae4f59f6d93ba65e57e560"
207
207
  }