@dynamic-labs/sdk-react-core 0.17.100-viem.2 → 0.17.100-viem.3

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/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
1
 
2
+ ### [0.17.100-viem.3](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.100-viem.2...v0.17.100-viem.3) (2023-07-01)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * log out if there's any session sync issue ([#2547](https://github.com/dynamic-labs/DynamicAuth/issues/2547)) ([62d41a9](https://github.com/dynamic-labs/DynamicAuth/commit/62d41a93f878694f2fdd80214a6fe55843c974f5))
8
+ * **TransactionView:** convert viem transaction hash value to bigint ([#2540](https://github.com/dynamic-labs/DynamicAuth/issues/2540)) ([6b95443](https://github.com/dynamic-labs/DynamicAuth/commit/6b9544303070aecf148cf73957a914e8c466319c))
9
+ * **wcv2:** don't force required chain to eth in case is not enabled ([#2539](https://github.com/dynamic-labs/DynamicAuth/issues/2539)) ([3f35fa2](https://github.com/dynamic-labs/DynamicAuth/commit/3f35fa2122123aedf174f03f10833b88d364a662))
10
+
2
11
  ### [0.17.100-viem.2](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.100-viem.1...v0.17.100-viem.2) (2023-06-29)
3
12
 
4
13
 
package/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "0.17.100-viem.2";
5
+ var version = "0.17.100-viem.3";
6
6
  var dependencies = {
7
7
  "react-focus-lock": "2.9.2",
8
8
  "@dynamic-labs/iconic": "0.1.23",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.17.100-viem.2";
1
+ var version = "0.17.100-viem.3";
2
2
  var dependencies = {
3
3
  "react-focus-lock": "2.9.2",
4
4
  "@dynamic-labs/iconic": "0.1.23",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "0.17.100-viem.2",
3
+ "version": "0.17.100-viem.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -15,13 +15,13 @@
15
15
  "yup": "0.32.11",
16
16
  "formik": "2.2.9",
17
17
  "qrcode": "1.5.1",
18
- "@dynamic-labs/logger": "0.17.100-viem.2",
19
- "@dynamic-labs/multi-wallet": "0.17.100-viem.2",
20
- "@dynamic-labs/rpc-providers": "0.17.100-viem.2",
21
- "@dynamic-labs/types": "0.17.100-viem.2",
22
- "@dynamic-labs/utils": "0.17.100-viem.2",
23
- "@dynamic-labs/wallet-book": "0.17.100-viem.2",
24
- "@dynamic-labs/wallet-connector-core": "0.17.100-viem.2"
18
+ "@dynamic-labs/logger": "0.17.100-viem.3",
19
+ "@dynamic-labs/multi-wallet": "0.17.100-viem.3",
20
+ "@dynamic-labs/rpc-providers": "0.17.100-viem.3",
21
+ "@dynamic-labs/types": "0.17.100-viem.3",
22
+ "@dynamic-labs/utils": "0.17.100-viem.3",
23
+ "@dynamic-labs/wallet-book": "0.17.100-viem.3",
24
+ "@dynamic-labs/wallet-connector-core": "0.17.100-viem.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "semver": "7.3.8"
package/src/index.cjs CHANGED
@@ -21,6 +21,7 @@ var getFromLS = require('./lib/shared/utils/functions/storage/getFromLS.cjs');
21
21
  var getDynamicLSKey = require('./lib/shared/utils/functions/storage/getDynamicLSKey.cjs');
22
22
  var removeFromLS = require('./lib/shared/utils/functions/storage/removeFromLS.cjs');
23
23
  var setToLS = require('./lib/shared/utils/functions/storage/setToLS.cjs');
24
+ var getLSKeys = require('./lib/shared/utils/functions/storage/getLSKeys.cjs');
24
25
  var validateType = require('./lib/shared/utils/functions/validateType/validateType.cjs');
25
26
  var getChainIcon = require('./lib/shared/utils/functions/chain/getChainIcon.cjs');
26
27
  var getChainDisplayName = require('./lib/shared/utils/functions/chain/getChainDisplayName.cjs');
@@ -143,6 +144,7 @@ exports.getFromLS = getFromLS.getFromLS;
143
144
  exports.getDynamicLSKey = getDynamicLSKey.getDynamicLSKey;
144
145
  exports.removeFromLS = removeFromLS.removeFromLS;
145
146
  exports.setToLS = setToLS.setToLS;
147
+ exports.getLSKeys = getLSKeys.getLSKeys;
146
148
  exports.validateType = validateType.validateType;
147
149
  exports.getChainIcon = getChainIcon.getChainIcon;
148
150
  exports.getChainDisplayName = getChainDisplayName.getChainDisplayName;
package/src/index.js CHANGED
@@ -17,6 +17,7 @@ export { getFromLS } from './lib/shared/utils/functions/storage/getFromLS.js';
17
17
  export { getDynamicLSKey } from './lib/shared/utils/functions/storage/getDynamicLSKey.js';
18
18
  export { removeFromLS } from './lib/shared/utils/functions/storage/removeFromLS.js';
19
19
  export { setToLS } from './lib/shared/utils/functions/storage/setToLS.js';
20
+ export { getLSKeys } from './lib/shared/utils/functions/storage/getLSKeys.js';
20
21
  export { validateType } from './lib/shared/utils/functions/validateType/validateType.js';
21
22
  export { getChainIcon } from './lib/shared/utils/functions/chain/getChainIcon.js';
22
23
  export { getChainDisplayName } from './lib/shared/utils/functions/chain/getChainDisplayName.js';
@@ -76,6 +76,7 @@ var FundingWidget = require('../../widgets/FundingWidget/FundingWidget.cjs');
76
76
  var DynamicBridgeWidgetContext = require('../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.cjs');
77
77
  require('../../widgets/DynamicBridgeWidget/components/DynamicBridgeWidgetViews/DynamicBridgeWidgetViews.cjs');
78
78
  var SendBalanceContext = require('../SendBalanceContext/SendBalanceContext.cjs');
79
+ var useValidateSession = require('../../utils/hooks/useValidateSession/useValidateSession.cjs');
79
80
  var helpers = require('./helpers.cjs');
80
81
  var validators = require('./validators.cjs');
81
82
  var useCustomerCallbacks = require('./useCustomerCallbacks/useCustomerCallbacks.cjs');
@@ -88,17 +89,12 @@ var useSetShowAuthFlowWithInit = require('./hooks/useSetShowAuthFlowWithInit/use
88
89
  const EMPTY_INITIAL_USER = undefined;
89
90
  const DynamicContext = React.createContext(undefined);
90
91
  const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, appLogoUrl = 'https://demo.dynamic.xyz/assets/dynamic-logo.svg', appName = 'Dynamic Example', cssOverrides, defaultNumberOfWalletsToShow = values.DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displayTermsOfService = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', multiWallet: deprecatedMultiWallet, notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectV1Bridge, walletConnectors: walletConnectorsProp, }, children, theme, }) => {
91
- var _a, _b, _c, _d, _e;
92
+ var _a, _b, _c, _d, _e, _f, _g;
92
93
  logger.logger.setLogLevel(logLevel);
93
94
  walletConnectorCore.logger.setLogLevel(logLevel);
94
95
  ApiEndpoint.setBaseUrl((_a = process.env.DYNAMIC_API_BASE_URL) !== null && _a !== void 0 ? _a : apiBaseUrl);
95
96
  LSSuffix.setSuffix(localStorageSuffix);
96
97
  const isAuthenticated = Boolean(getAuthToken.getAuthToken());
97
- // HOTFIX - NEED TO BE REVISITED
98
- // if there's user but not auth_token, remove user
99
- if (!isAuthenticated) {
100
- removeFromLS.removeFromLS(localStorage$1.AUTH_USER);
101
- }
102
98
  const [onboardingOnlyJwt, setOnboardingOnlyJwt] = React.useState(undefined);
103
99
  const [showAuthFlow, setShowAuthFlow] = React.useState(false);
104
100
  // Allows clients to control widget flow without need to click on AccountControl
@@ -170,8 +166,10 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
170
166
  setShowAuthFlow,
171
167
  wallets,
172
168
  });
169
+ // until user completes onboarding, jwt is only stored in onboardingOnlyJwt
170
+ const authToken = (_d = getAuthToken.getAuthToken()) !== null && _d !== void 0 ? _d : onboardingOnlyJwt;
173
171
  const { getNameService, removeConnectedNameService } = useNameService.useNameService({
174
- authToken: (_d = getAuthToken.getAuthToken()) !== null && _d !== void 0 ? _d : onboardingOnlyJwt,
172
+ authToken,
175
173
  currentWallet: primaryWallet !== null && primaryWallet !== void 0 ? primaryWallet : connectedWallet,
176
174
  });
177
175
  const walletForUserFacingContext = authMode === 'connect-and-sign' || user ? primaryWallet : connectedWallet;
@@ -182,7 +180,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
182
180
  clearOphanedWalletConnectSessions,
183
181
  ]);
184
182
  const handleLogOut = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
185
- var _f, _g;
183
+ var _h, _j;
186
184
  clearAllWalletConnectSessions();
187
185
  localStorage.removeItem(localStorage$1.WALLET_PICKER_SEARCH_KEY);
188
186
  const jwt = getAuthToken.getAuthToken();
@@ -193,7 +191,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
193
191
  for (const connector of walletConnectors) {
194
192
  yield connector.endSession();
195
193
  }
196
- (_f = connectedWallet === null || connectedWallet === void 0 ? void 0 : connectedWallet.connector) === null || _f === void 0 ? void 0 : _f.endSession();
194
+ (_h = connectedWallet === null || connectedWallet === void 0 ? void 0 : connectedWallet.connector) === null || _h === void 0 ? void 0 : _h.endSession();
197
195
  setShowAuthFlow(false);
198
196
  setMultiWalletWidgetState('idle');
199
197
  removeAuthTokenAndUser();
@@ -203,7 +201,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
203
201
  removeConnectedInfo();
204
202
  clearPrimaryWalletId();
205
203
  removeConnectedNameService();
206
- (_g = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _g === void 0 ? void 0 : _g.call(eventsCallbacks, user);
204
+ (_j = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _j === void 0 ? void 0 : _j.call(eventsCallbacks, user);
207
205
  }), [
208
206
  clearAllWalletConnectSessions,
209
207
  user,
@@ -219,6 +217,21 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
219
217
  environmentId,
220
218
  walletConnectors,
221
219
  ]);
220
+ let wcVersion;
221
+ if (projectSettings) {
222
+ wcVersion =
223
+ ((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.walletConnect) === null || _f === void 0 ? void 0 : _f.v2Enabled) && !walletConnectV1Bridge
224
+ ? 2
225
+ : 1;
226
+ }
227
+ useValidateSession.useValidateSession({
228
+ authToken,
229
+ handleLogOut,
230
+ user,
231
+ walletConnectV1Bridge,
232
+ walletConnectors,
233
+ wcVersion,
234
+ });
222
235
  useSyncPrimaryWallet.useSyncPrimaryWallet({
223
236
  canSync: didConnectedStateLoad,
224
237
  computeConnectedStateForWallets,
@@ -519,7 +532,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
519
532
  setShowDynamicUserProfile(true);
520
533
  }
521
534
  }, [multiWallet, multiWalletWidgetState, showDynamicUserProfile, user]);
522
- return (jsxRuntime.jsx(DynamicContext.Provider, { value: value, children: jsxRuntime.jsx(ThemeContext.ThemeContextProvider, { customerTheme: parseTheme.parseTheme(theme, ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsxRuntime.jsx(LoadingContext.LoadingContextProvider, { children: jsxRuntime.jsx(ViewContext.ViewContextProvider, { initialView: loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list', children: jsxRuntime.jsx(QrCodeContext.QrCodeContextProvider, { children: jsxRuntime.jsx(EmailVerificationContext.EmailVerificationContextProvider, { children: jsxRuntime.jsx(ErrorContext.ErrorContextProvider, { children: jsxRuntime.jsx(DynamicWidgetContext.DynamicWidgetContextProvider, { children: jsxRuntime.jsx(DynamicBridgeWidgetContext.DynamicBridgeWidgetContextProvider, { children: jsxRuntime.jsx(CaptchaContext.CaptchaContextProvider, { children: jsxRuntime.jsx(FundingContext.FundingContextProvider, { children: jsxRuntime.jsx(AccessDeniedContext.AccessDeniedContextProvider, { children: jsxRuntime.jsxs(SendBalanceContext.SendBalanceContextProvider, { children: [jsxRuntime.jsx(app.DynamicAuthFlow, {}), jsxRuntime.jsx(Toolkit.Toolkit, {}), jsxRuntime.jsx(FundingWidget.FundingWidget, {}), confirmationModal, children] }) }) }) }) }) }) }) }) }) }) }) }) }));
535
+ return (jsxRuntime.jsx(DynamicContext.Provider, { value: value, children: jsxRuntime.jsx(ThemeContext.ThemeContextProvider, { customerTheme: parseTheme.parseTheme(theme, ((_g = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _g === void 0 ? void 0 : _g.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsxRuntime.jsx(LoadingContext.LoadingContextProvider, { children: jsxRuntime.jsx(ViewContext.ViewContextProvider, { initialView: loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list', children: jsxRuntime.jsx(QrCodeContext.QrCodeContextProvider, { children: jsxRuntime.jsx(EmailVerificationContext.EmailVerificationContextProvider, { children: jsxRuntime.jsx(ErrorContext.ErrorContextProvider, { children: jsxRuntime.jsx(DynamicWidgetContext.DynamicWidgetContextProvider, { children: jsxRuntime.jsx(DynamicBridgeWidgetContext.DynamicBridgeWidgetContextProvider, { children: jsxRuntime.jsx(CaptchaContext.CaptchaContextProvider, { children: jsxRuntime.jsx(FundingContext.FundingContextProvider, { children: jsxRuntime.jsx(AccessDeniedContext.AccessDeniedContextProvider, { children: jsxRuntime.jsxs(SendBalanceContext.SendBalanceContextProvider, { children: [jsxRuntime.jsx(app.DynamicAuthFlow, {}), jsxRuntime.jsx(Toolkit.Toolkit, {}), jsxRuntime.jsx(FundingWidget.FundingWidget, {}), confirmationModal, children] }) }) }) }) }) }) }) }) }) }) }) }) }));
523
536
  };
524
537
 
525
538
  exports.DynamicContext = DynamicContext;
@@ -3,7 +3,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { createContext, useState, useCallback, useEffect, useMemo } from 'react';
4
4
  import { logger as logger$1 } from '@dynamic-labs/wallet-connector-core';
5
5
  import { ICONIC_SPRITE_URL } from '@dynamic-labs/iconic';
6
- import { AUTH_USER, AUTH_TOKEN, AUTH_MODE, WALLET_PICKER_SEARCH_KEY } from '../../utils/constants/localStorage.js';
6
+ import { AUTH_TOKEN, AUTH_USER, AUTH_MODE, WALLET_PICKER_SEARCH_KEY } from '../../utils/constants/localStorage.js';
7
7
  import '../../utils/constants/colors.js';
8
8
  import { DEFAULT_NUMBER_OF_WALLETS_TO_SHOW } from '../../utils/constants/values.js';
9
9
  import { decodeJwt } from '../../shared/utils/functions/decodeJwt/decodeJwt.js';
@@ -72,6 +72,7 @@ import { FundingWidget } from '../../widgets/FundingWidget/FundingWidget.js';
72
72
  import { DynamicBridgeWidgetContextProvider } from '../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.js';
73
73
  import '../../widgets/DynamicBridgeWidget/components/DynamicBridgeWidgetViews/DynamicBridgeWidgetViews.js';
74
74
  import { SendBalanceContextProvider } from '../SendBalanceContext/SendBalanceContext.js';
75
+ import { useValidateSession } from '../../utils/hooks/useValidateSession/useValidateSession.js';
75
76
  import { initExpirationTime } from './helpers.js';
76
77
  import { validateAuthUser } from './validators.js';
77
78
  import { useCustomerCallbacks } from './useCustomerCallbacks/useCustomerCallbacks.js';
@@ -84,17 +85,12 @@ import { useSetShowAuthFlowWithInit } from './hooks/useSetShowAuthFlowWithInit/u
84
85
  const EMPTY_INITIAL_USER = undefined;
85
86
  const DynamicContext = createContext(undefined);
86
87
  const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, accessDeniedMessageSecondary, accessDeniedButton, apiBaseUrl, appLogoUrl = 'https://demo.dynamic.xyz/assets/dynamic-logo.svg', appName = 'Dynamic Example', cssOverrides, defaultNumberOfWalletsToShow = DEFAULT_NUMBER_OF_WALLETS_TO_SHOW, flowNetwork, initialAuthenticationMode = 'connect-and-sign', debugError = false, displayTermsOfService = true, newToWeb3WalletChainMap, enableVisitTrackingOnConnectOnly = true, environmentId, localStorageSuffix, eventsCallbacks, evmNetworks, walletsFilter, logLevel = 'WARN', multiWallet: deprecatedMultiWallet, notInTheListImageUrl, onboardingImageUrl, policiesConsentInnerComponent, privacyPolicyUrl, signWithEmailWalletName, socialMediaLinkText, socialMediaIconUrl, socialMediaUrl, termsOfServiceUrl, toolkitEnabled, siweStatement, shadowDOMEnabled = true, walletConnectV1Bridge, walletConnectors: walletConnectorsProp, }, children, theme, }) => {
87
- var _a, _b, _c, _d, _e;
88
+ var _a, _b, _c, _d, _e, _f, _g;
88
89
  logger.setLogLevel(logLevel);
89
90
  logger$1.setLogLevel(logLevel);
90
91
  ApiEndpoint.setBaseUrl((_a = process.env.DYNAMIC_API_BASE_URL) !== null && _a !== void 0 ? _a : apiBaseUrl);
91
92
  LSSuffix.setSuffix(localStorageSuffix);
92
93
  const isAuthenticated = Boolean(getAuthToken());
93
- // HOTFIX - NEED TO BE REVISITED
94
- // if there's user but not auth_token, remove user
95
- if (!isAuthenticated) {
96
- removeFromLS(AUTH_USER);
97
- }
98
94
  const [onboardingOnlyJwt, setOnboardingOnlyJwt] = useState(undefined);
99
95
  const [showAuthFlow, setShowAuthFlow] = useState(false);
100
96
  // Allows clients to control widget flow without need to click on AccountControl
@@ -166,8 +162,10 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
166
162
  setShowAuthFlow,
167
163
  wallets,
168
164
  });
165
+ // until user completes onboarding, jwt is only stored in onboardingOnlyJwt
166
+ const authToken = (_d = getAuthToken()) !== null && _d !== void 0 ? _d : onboardingOnlyJwt;
169
167
  const { getNameService, removeConnectedNameService } = useNameService({
170
- authToken: (_d = getAuthToken()) !== null && _d !== void 0 ? _d : onboardingOnlyJwt,
168
+ authToken,
171
169
  currentWallet: primaryWallet !== null && primaryWallet !== void 0 ? primaryWallet : connectedWallet,
172
170
  });
173
171
  const walletForUserFacingContext = authMode === 'connect-and-sign' || user ? primaryWallet : connectedWallet;
@@ -178,7 +176,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
178
176
  clearOphanedWalletConnectSessions,
179
177
  ]);
180
178
  const handleLogOut = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
181
- var _f, _g;
179
+ var _h, _j;
182
180
  clearAllWalletConnectSessions();
183
181
  localStorage.removeItem(WALLET_PICKER_SEARCH_KEY);
184
182
  const jwt = getAuthToken();
@@ -189,7 +187,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
189
187
  for (const connector of walletConnectors) {
190
188
  yield connector.endSession();
191
189
  }
192
- (_f = connectedWallet === null || connectedWallet === void 0 ? void 0 : connectedWallet.connector) === null || _f === void 0 ? void 0 : _f.endSession();
190
+ (_h = connectedWallet === null || connectedWallet === void 0 ? void 0 : connectedWallet.connector) === null || _h === void 0 ? void 0 : _h.endSession();
193
191
  setShowAuthFlow(false);
194
192
  setMultiWalletWidgetState('idle');
195
193
  removeAuthTokenAndUser();
@@ -199,7 +197,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
199
197
  removeConnectedInfo();
200
198
  clearPrimaryWalletId();
201
199
  removeConnectedNameService();
202
- (_g = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _g === void 0 ? void 0 : _g.call(eventsCallbacks, user);
200
+ (_j = eventsCallbacks === null || eventsCallbacks === void 0 ? void 0 : eventsCallbacks.onLogout) === null || _j === void 0 ? void 0 : _j.call(eventsCallbacks, user);
203
201
  }), [
204
202
  clearAllWalletConnectSessions,
205
203
  user,
@@ -215,6 +213,21 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
215
213
  environmentId,
216
214
  walletConnectors,
217
215
  ]);
216
+ let wcVersion;
217
+ if (projectSettings) {
218
+ wcVersion =
219
+ ((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.walletConnect) === null || _f === void 0 ? void 0 : _f.v2Enabled) && !walletConnectV1Bridge
220
+ ? 2
221
+ : 1;
222
+ }
223
+ useValidateSession({
224
+ authToken,
225
+ handleLogOut,
226
+ user,
227
+ walletConnectV1Bridge,
228
+ walletConnectors,
229
+ wcVersion,
230
+ });
218
231
  useSyncPrimaryWallet({
219
232
  canSync: didConnectedStateLoad,
220
233
  computeConnectedStateForWallets,
@@ -515,7 +528,7 @@ const DynamicContextProvider = ({ settings: { accessDeniedMessagePrimary, access
515
528
  setShowDynamicUserProfile(true);
516
529
  }
517
530
  }, [multiWallet, multiWalletWidgetState, showDynamicUserProfile, user]);
518
- return (jsx(DynamicContext.Provider, { value: value, children: jsx(ThemeContextProvider, { customerTheme: parseTheme(theme, ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsx(LoadingContextProvider, { children: jsx(ViewContextProvider, { initialView: loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list', children: jsx(QrCodeContextProvider, { children: jsx(EmailVerificationContextProvider, { children: jsx(ErrorContextProvider, { children: jsx(DynamicWidgetContextProvider, { children: jsx(DynamicBridgeWidgetContextProvider, { children: jsx(CaptchaContextProvider, { children: jsx(FundingContextProvider, { children: jsx(AccessDeniedContextProvider, { children: jsxs(SendBalanceContextProvider, { children: [jsx(DynamicAuthFlow, {}), jsx(Toolkit, {}), jsx(FundingWidget, {}), confirmationModal, children] }) }) }) }) }) }) }) }) }) }) }) }) }));
531
+ return (jsx(DynamicContext.Provider, { value: value, children: jsx(ThemeContextProvider, { customerTheme: parseTheme(theme, ((_g = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _g === void 0 ? void 0 : _g.modal) || undefined), designSettings: projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design, children: jsx(LoadingContextProvider, { children: jsx(ViewContextProvider, { initialView: loginWithEmail ? 'login-with-email-or-wallet' : 'wallet-list', children: jsx(QrCodeContextProvider, { children: jsx(EmailVerificationContextProvider, { children: jsx(ErrorContextProvider, { children: jsx(DynamicWidgetContextProvider, { children: jsx(DynamicBridgeWidgetContextProvider, { children: jsx(CaptchaContextProvider, { children: jsx(FundingContextProvider, { children: jsx(AccessDeniedContextProvider, { children: jsxs(SendBalanceContextProvider, { children: [jsx(DynamicAuthFlow, {}), jsx(Toolkit, {}), jsx(FundingWidget, {}), confirmationModal, children] }) }) }) }) }) }) }) }) }) }) }) }) }));
519
532
  };
520
533
 
521
534
  export { DynamicContext, DynamicContextProvider };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const getLSKeys = () => {
6
+ if (typeof window === 'undefined') {
7
+ return [];
8
+ }
9
+ return Object.keys(window.localStorage);
10
+ };
11
+
12
+ exports.getLSKeys = getLSKeys;
@@ -0,0 +1 @@
1
+ export declare const getLSKeys: () => string[];
@@ -0,0 +1,8 @@
1
+ const getLSKeys = () => {
2
+ if (typeof window === 'undefined') {
3
+ return [];
4
+ }
5
+ return Object.keys(window.localStorage);
6
+ };
7
+
8
+ export { getLSKeys };
@@ -2,3 +2,4 @@ export { getFromLS } from './getFromLS';
2
2
  export { getDynamicLSKey } from './getDynamicLSKey';
3
3
  export { removeFromLS } from './removeFromLS';
4
4
  export { setToLS } from './setToLS';
5
+ export { getLSKeys } from './getLSKeys';
@@ -4,6 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
+ require('@dynamic-labs/sdk-api');
8
+ require('../../../shared/logger.cjs');
9
+ require('../../../config/LSSuffix.cjs');
10
+ var getLSKeys = require('../../../shared/utils/functions/storage/getLSKeys.cjs');
11
+ require('@dynamic-labs/iconic');
12
+ require('react/jsx-runtime');
13
+ require('../../../context/ViewContext/ViewContext.cjs');
14
+ require('@dynamic-labs/utils');
15
+ require('../../constants/colors.cjs');
16
+ require('viem');
17
+ require('../../../shared/consts/index.cjs');
7
18
 
8
19
  const useClearWalletConnectSessions = ({ connectors }) => {
9
20
  const clearOphanedWalletConnectSessions = React.useCallback(() => {
@@ -12,7 +23,7 @@ const useClearWalletConnectSessions = ({ connectors }) => {
12
23
  if (connectors.length === 0)
13
24
  return;
14
25
  const names = new Set(connectors.map((connector) => walletConnectorCore.normalizeWalletName(connector.name)));
15
- for (const key of Object.keys(localStorage)) {
26
+ for (const key of getLSKeys.getLSKeys()) {
16
27
  if (key.startsWith('walletconnect') &&
17
28
  !names.has(key.replace('walletconnect-', ''))) {
18
29
  localStorage.removeItem(key);
@@ -22,8 +33,10 @@ const useClearWalletConnectSessions = ({ connectors }) => {
22
33
  const clearAllWalletConnectSessions = () => {
23
34
  if (typeof window === 'undefined')
24
35
  return;
25
- for (const key of Object.keys(localStorage)) {
26
- if (key.startsWith('walletconnect')) {
36
+ for (const key of getLSKeys.getLSKeys()) {
37
+ if (key.startsWith('walletconnect') ||
38
+ key.startsWith('walletlink') ||
39
+ key.startsWith('wc@2')) {
27
40
  localStorage.removeItem(key);
28
41
  }
29
42
  }
@@ -1,5 +1,16 @@
1
1
  import { useCallback } from 'react';
2
2
  import { normalizeWalletName } from '@dynamic-labs/wallet-connector-core';
3
+ import '@dynamic-labs/sdk-api';
4
+ import '../../../shared/logger.js';
5
+ import '../../../config/LSSuffix.js';
6
+ import { getLSKeys } from '../../../shared/utils/functions/storage/getLSKeys.js';
7
+ import '@dynamic-labs/iconic';
8
+ import 'react/jsx-runtime';
9
+ import '../../../context/ViewContext/ViewContext.js';
10
+ import '@dynamic-labs/utils';
11
+ import '../../constants/colors.js';
12
+ import 'viem';
13
+ import '../../../shared/consts/index.js';
3
14
 
4
15
  const useClearWalletConnectSessions = ({ connectors }) => {
5
16
  const clearOphanedWalletConnectSessions = useCallback(() => {
@@ -8,7 +19,7 @@ const useClearWalletConnectSessions = ({ connectors }) => {
8
19
  if (connectors.length === 0)
9
20
  return;
10
21
  const names = new Set(connectors.map((connector) => normalizeWalletName(connector.name)));
11
- for (const key of Object.keys(localStorage)) {
22
+ for (const key of getLSKeys()) {
12
23
  if (key.startsWith('walletconnect') &&
13
24
  !names.has(key.replace('walletconnect-', ''))) {
14
25
  localStorage.removeItem(key);
@@ -18,8 +29,10 @@ const useClearWalletConnectSessions = ({ connectors }) => {
18
29
  const clearAllWalletConnectSessions = () => {
19
30
  if (typeof window === 'undefined')
20
31
  return;
21
- for (const key of Object.keys(localStorage)) {
22
- if (key.startsWith('walletconnect')) {
32
+ for (const key of getLSKeys()) {
33
+ if (key.startsWith('walletconnect') ||
34
+ key.startsWith('walletlink') ||
35
+ key.startsWith('wc@2')) {
23
36
  localStorage.removeItem(key);
24
37
  }
25
38
  }
@@ -30,9 +30,9 @@ const useCreateUserProfileByJWTCallback = () => {
30
30
  goToInitialView();
31
31
  return;
32
32
  }
33
+ index.storeAuthToken(jwt);
33
34
  const userProfile = createUserProfile.createUserProfile(decodedJWT);
34
35
  setUser(userProfile);
35
- index.storeAuthToken(jwt);
36
36
  // eslint-disable-next-line react-hooks/exhaustive-deps
37
37
  }, []);
38
38
  return { createUserProfileByJWT };
@@ -26,9 +26,9 @@ const useCreateUserProfileByJWTCallback = () => {
26
26
  goToInitialView();
27
27
  return;
28
28
  }
29
+ storeAuthToken(jwt);
29
30
  const userProfile = createUserProfile(decodedJWT);
30
31
  setUser(userProfile);
31
- storeAuthToken(jwt);
32
32
  // eslint-disable-next-line react-hooks/exhaustive-deps
33
33
  }, []);
34
34
  return { createUserProfileByJWT };
@@ -0,0 +1 @@
1
+ export { useValidateSession } from './useValidateSession';
@@ -0,0 +1,79 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
6
+ var React = require('react');
7
+ require('@dynamic-labs/sdk-api');
8
+ var logger = require('../../../shared/logger.cjs');
9
+ require('../../../config/LSSuffix.cjs');
10
+ var getLSKeys = require('../../../shared/utils/functions/storage/getLSKeys.cjs');
11
+ require('@dynamic-labs/iconic');
12
+ require('@dynamic-labs/wallet-connector-core');
13
+ require('react/jsx-runtime');
14
+ require('../../../context/ViewContext/ViewContext.cjs');
15
+ require('@dynamic-labs/utils');
16
+ require('../../constants/colors.cjs');
17
+ require('viem');
18
+ require('../../../shared/consts/index.cjs');
19
+
20
+ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }) => {
21
+ const [hasLoggedOut, setHasLoggedOut] = React.useState(false);
22
+ if (hasLoggedOut) {
23
+ return;
24
+ }
25
+ const logout = (reason, params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
26
+ setHasLoggedOut(true);
27
+ logger.logger.debug(`Logging out - Reason: ${reason}`, Object.assign({}, params));
28
+ yield handleLogOut();
29
+ });
30
+ const handleUserDataOutOfSync = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
31
+ if (authToken || !user) {
32
+ return;
33
+ }
34
+ yield logout('user data out of sync', {
35
+ authToken,
36
+ user,
37
+ });
38
+ });
39
+ const handleConnectorBridgeOutOfSync = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
40
+ let currentWalletConnectV1Bridge;
41
+ if (walletConnectors) {
42
+ for (const connector of walletConnectors) {
43
+ const session = yield connector.getSession();
44
+ const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
45
+ if (bridge) {
46
+ currentWalletConnectV1Bridge = bridge;
47
+ break;
48
+ }
49
+ }
50
+ }
51
+ if (!walletConnectV1Bridge ||
52
+ !currentWalletConnectV1Bridge ||
53
+ walletConnectV1Bridge === currentWalletConnectV1Bridge) {
54
+ return;
55
+ }
56
+ yield logout('connector bridge out of sync', {
57
+ newBridge: walletConnectV1Bridge,
58
+ oldBridge: currentWalletConnectV1Bridge,
59
+ });
60
+ });
61
+ const hasWCV1Data = getLSKeys.getLSKeys().some((key) => key.startsWith('walletconnect') || key.startsWith('walletlink'));
62
+ const hasWCV2Data = getLSKeys.getLSKeys().some((key) => key.startsWith('wc@2'));
63
+ const handleConnectorVersionOutOfSync = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
64
+ if (!wcVersion ||
65
+ (wcVersion === 2 && !hasWCV1Data) ||
66
+ (wcVersion === 1 && !hasWCV2Data)) {
67
+ return;
68
+ }
69
+ yield logout('connector version out of sync', {
70
+ newVersion: wcVersion,
71
+ oldVersion: hasWCV1Data ? 1 : 2,
72
+ });
73
+ });
74
+ handleUserDataOutOfSync();
75
+ handleConnectorBridgeOutOfSync();
76
+ handleConnectorVersionOutOfSync();
77
+ };
78
+
79
+ exports.useValidateSession = useValidateSession;
@@ -0,0 +1,12 @@
1
+ import { UserProfile } from '../../../shared';
2
+ import { WalletConnector } from '../../../..';
3
+ type Props = {
4
+ handleLogOut: () => Promise<void>;
5
+ user: UserProfile | undefined;
6
+ authToken: string | undefined;
7
+ walletConnectV1Bridge: string | undefined;
8
+ walletConnectors: WalletConnector[] | undefined;
9
+ wcVersion: number | undefined;
10
+ };
11
+ export declare const useValidateSession: ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }: Props) => void;
12
+ export {};
@@ -0,0 +1,75 @@
1
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
+ import { useState } from 'react';
3
+ import '@dynamic-labs/sdk-api';
4
+ import { logger } from '../../../shared/logger.js';
5
+ import '../../../config/LSSuffix.js';
6
+ import { getLSKeys } from '../../../shared/utils/functions/storage/getLSKeys.js';
7
+ import '@dynamic-labs/iconic';
8
+ import '@dynamic-labs/wallet-connector-core';
9
+ import 'react/jsx-runtime';
10
+ import '../../../context/ViewContext/ViewContext.js';
11
+ import '@dynamic-labs/utils';
12
+ import '../../constants/colors.js';
13
+ import 'viem';
14
+ import '../../../shared/consts/index.js';
15
+
16
+ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Bridge, walletConnectors, wcVersion, }) => {
17
+ const [hasLoggedOut, setHasLoggedOut] = useState(false);
18
+ if (hasLoggedOut) {
19
+ return;
20
+ }
21
+ const logout = (reason, params) => __awaiter(void 0, void 0, void 0, function* () {
22
+ setHasLoggedOut(true);
23
+ logger.debug(`Logging out - Reason: ${reason}`, Object.assign({}, params));
24
+ yield handleLogOut();
25
+ });
26
+ const handleUserDataOutOfSync = () => __awaiter(void 0, void 0, void 0, function* () {
27
+ if (authToken || !user) {
28
+ return;
29
+ }
30
+ yield logout('user data out of sync', {
31
+ authToken,
32
+ user,
33
+ });
34
+ });
35
+ const handleConnectorBridgeOutOfSync = () => __awaiter(void 0, void 0, void 0, function* () {
36
+ let currentWalletConnectV1Bridge;
37
+ if (walletConnectors) {
38
+ for (const connector of walletConnectors) {
39
+ const session = yield connector.getSession();
40
+ const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
41
+ if (bridge) {
42
+ currentWalletConnectV1Bridge = bridge;
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ if (!walletConnectV1Bridge ||
48
+ !currentWalletConnectV1Bridge ||
49
+ walletConnectV1Bridge === currentWalletConnectV1Bridge) {
50
+ return;
51
+ }
52
+ yield logout('connector bridge out of sync', {
53
+ newBridge: walletConnectV1Bridge,
54
+ oldBridge: currentWalletConnectV1Bridge,
55
+ });
56
+ });
57
+ const hasWCV1Data = getLSKeys().some((key) => key.startsWith('walletconnect') || key.startsWith('walletlink'));
58
+ const hasWCV2Data = getLSKeys().some((key) => key.startsWith('wc@2'));
59
+ const handleConnectorVersionOutOfSync = () => __awaiter(void 0, void 0, void 0, function* () {
60
+ if (!wcVersion ||
61
+ (wcVersion === 2 && !hasWCV1Data) ||
62
+ (wcVersion === 1 && !hasWCV2Data)) {
63
+ return;
64
+ }
65
+ yield logout('connector version out of sync', {
66
+ newVersion: wcVersion,
67
+ oldVersion: hasWCV1Data ? 1 : 2,
68
+ });
69
+ });
70
+ handleUserDataOutOfSync();
71
+ handleConnectorBridgeOutOfSync();
72
+ handleConnectorVersionOutOfSync();
73
+ };
74
+
75
+ export { useValidateSession };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../../../../../_virtual/_tslib.cjs');
6
6
  var React = require('react');
7
+ var viem = require('viem');
7
8
  require('@dynamic-labs/utils');
8
9
  require('@dynamic-labs/sdk-api');
9
10
  require('../../../../config/ApiEndpoint.cjs');
@@ -14,7 +15,6 @@ require('@dynamic-labs/wallet-connector-core');
14
15
  require('react/jsx-runtime');
15
16
  require('../../../../context/ViewContext/ViewContext.cjs');
16
17
  require('../../../../utils/constants/colors.cjs');
17
- require('viem');
18
18
  require('../../../../shared/consts/index.cjs');
19
19
  require('@dynamic-labs/multi-wallet');
20
20
  require('@dynamic-labs/rpc-providers');
@@ -42,7 +42,15 @@ require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs')
42
42
 
43
43
  const useTransactionData = ({ transaction, }) => {
44
44
  const { primaryWallet } = useInternalDynamicContext.useInternalDynamicContext();
45
- const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () { return transaction.value; }));
45
+ const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise.usePromise(() => {
46
+ const { value } = transaction;
47
+ if (value === undefined)
48
+ return undefined;
49
+ if (viem.isHex(value)) {
50
+ return viem.fromHex(value, 'bigint');
51
+ }
52
+ return value;
53
+ });
46
54
  const { data: estimatedGas, isLoading: isEstimatedGasLoading } = usePromise.usePromise(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
47
55
  const publicClient = yield (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.getRpcProvider());
48
56
  if (!publicClient)
@@ -1,5 +1,6 @@
1
1
  import { __awaiter, __rest } from '../../../../../../_virtual/_tslib.js';
2
2
  import { useMemo } from 'react';
3
+ import { isHex, fromHex } from 'viem';
3
4
  import '@dynamic-labs/utils';
4
5
  import '@dynamic-labs/sdk-api';
5
6
  import '../../../../config/ApiEndpoint.js';
@@ -10,7 +11,6 @@ import '@dynamic-labs/wallet-connector-core';
10
11
  import 'react/jsx-runtime';
11
12
  import '../../../../context/ViewContext/ViewContext.js';
12
13
  import '../../../../utils/constants/colors.js';
13
- import 'viem';
14
14
  import '../../../../shared/consts/index.js';
15
15
  import '@dynamic-labs/multi-wallet';
16
16
  import '@dynamic-labs/rpc-providers';
@@ -38,7 +38,15 @@ import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
38
38
 
39
39
  const useTransactionData = ({ transaction, }) => {
40
40
  const { primaryWallet } = useInternalDynamicContext();
41
- const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () { return transaction.value; }));
41
+ const { data: transactionValue, isLoading: isEffectiveValueLoading } = usePromise(() => {
42
+ const { value } = transaction;
43
+ if (value === undefined)
44
+ return undefined;
45
+ if (isHex(value)) {
46
+ return fromHex(value, 'bigint');
47
+ }
48
+ return value;
49
+ });
42
50
  const { data: estimatedGas, isLoading: isEstimatedGasLoading } = usePromise(() => __awaiter(void 0, void 0, void 0, function* () {
43
51
  const publicClient = yield (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.getRpcProvider());
44
52
  if (!publicClient)