@dynamic-labs/sdk-react-core 2.3.1 → 2.3.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
+ ### [2.3.3](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.2...v2.3.3) (2024-07-18)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * add project setting prefetch ([#6368](https://github.com/dynamic-labs/DynamicAuth/issues/6368)) ([4f3009e](https://github.com/dynamic-labs/DynamicAuth/commit/4f3009ec1fbe110be73bd7b775cfb040592a8b2a))
8
+
9
+ ### [2.3.2](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.1...v2.3.2) (2024-07-16)
10
+
2
11
  ### [2.3.1](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.1-alpha.0...v2.3.1) (2024-07-13)
3
12
 
4
13
  ### [2.3.1-alpha.0](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.0...v2.3.1-alpha.0) (2024-07-12)
package/package.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "2.3.1";
6
+ var version = "2.3.3";
7
7
  var dependencies = {
8
8
  "@dynamic-labs/sdk-api-core": "0.0.460",
9
9
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client'
2
- var version = "2.3.1";
2
+ var version = "2.3.3";
3
3
  var dependencies = {
4
4
  "@dynamic-labs/sdk-api-core": "0.0.460",
5
5
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -17,18 +17,18 @@
17
17
  "react-i18next": "13.5.0",
18
18
  "yup": "0.32.11",
19
19
  "react-international-phone": "4.2.5",
20
- "@dynamic-labs/iconic": "2.3.1",
21
- "@dynamic-labs/logger": "2.3.1",
22
- "@dynamic-labs/multi-wallet": "2.3.1",
23
- "@dynamic-labs/rpc-provider-ethereum": "2.3.1",
24
- "@dynamic-labs/rpc-provider-solana": "2.3.1",
25
- "@dynamic-labs/rpc-providers": "2.3.1",
26
- "@dynamic-labs/store": "2.3.1",
27
- "@dynamic-labs/types": "2.3.1",
28
- "@dynamic-labs/utils": "2.3.1",
29
- "@dynamic-labs/viem-utils": "2.3.1",
30
- "@dynamic-labs/wallet-book": "2.3.1",
31
- "@dynamic-labs/wallet-connector-core": "2.3.1",
20
+ "@dynamic-labs/iconic": "2.3.3",
21
+ "@dynamic-labs/logger": "2.3.3",
22
+ "@dynamic-labs/multi-wallet": "2.3.3",
23
+ "@dynamic-labs/rpc-provider-ethereum": "2.3.3",
24
+ "@dynamic-labs/rpc-provider-solana": "2.3.3",
25
+ "@dynamic-labs/rpc-providers": "2.3.3",
26
+ "@dynamic-labs/store": "2.3.3",
27
+ "@dynamic-labs/types": "2.3.3",
28
+ "@dynamic-labs/utils": "2.3.3",
29
+ "@dynamic-labs/viem-utils": "2.3.3",
30
+ "@dynamic-labs/wallet-book": "2.3.3",
31
+ "@dynamic-labs/wallet-connector-core": "2.3.3",
32
32
  "eventemitter3": "5.0.1"
33
33
  },
34
34
  "devDependencies": {
@@ -25,6 +25,7 @@ var values = require('../../utils/constants/values.cjs');
25
25
  var localStorage = require('../../shared/utils/classes/storage/localStorage.cjs');
26
26
  var useGlobalLoading = require('../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.cjs');
27
27
  var useLocalStorage = require('../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
28
+ var usePrefetch = require('../../shared/utils/hooks/usePrefetch/usePrefetch.cjs');
28
29
  require('../../shared/consts/index.cjs');
29
30
  var CaptchaContext = require('../CaptchaContext/CaptchaContext.cjs');
30
31
  var ErrorContext = require('../ErrorContext/ErrorContext.cjs');
@@ -34,6 +35,7 @@ var getMinAuthToken = require('../../utils/functions/getMinAuthToken/getMinAuthT
34
35
  require('react-international-phone');
35
36
  require('viem');
36
37
  require('viem/chains');
38
+ var version = require('../../../version.cjs');
37
39
  var ApiEndpoint = require('../../config/ApiEndpoint.cjs');
38
40
  var userActions = require('../../store/actions/userActions/userActions.cjs');
39
41
  var settings = require('../../data/api/settings/settings.cjs');
@@ -164,8 +166,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
164
166
  if (!environmentId) {
165
167
  throw new utils.MissingEnvironmentIdError();
166
168
  }
167
- logger$1.logger.setLogLevel(logLevel);
168
- walletConnectorCore.logger.setLogLevel(logLevel);
169
+ try {
170
+ logger$1.logger.setLogLevel(logLevel);
171
+ walletConnectorCore.logger.setLogLevel(logLevel);
172
+ }
173
+ catch (_j) {
174
+ // logger could be messing up with SSR so we are catching the errors
175
+ /* empty */
176
+ }
169
177
  if (environmentId === PUBLIC_PROJECT_LIVE_ENVIRONMENT_ID) {
170
178
  logger$1.logger.warn(`WARNING: DYNAMIC is using a test environment ID ${environmentId}. Please sign up on https://app.dynamic.xyz/ to get your production environment ID.`);
171
179
  }
@@ -185,11 +193,17 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
185
193
  const [isSingleWalletAccount, setIsSingleWalletAccount] = React.useState(false);
186
194
  const { user, unauthenticatedUser } = useUser.useUser();
187
195
  const isAuthenticated = useIsAuthenticated.useIsAuthenticated(user);
188
- if (user) {
189
- logger$1.logger.setMetaData('user', user);
196
+ try {
197
+ if (user) {
198
+ logger$1.logger.setMetaData('user', user);
199
+ }
200
+ else {
201
+ logger$1.logger.setMetaData('user', undefined);
202
+ }
190
203
  }
191
- else {
192
- logger$1.logger.setMetaData('user', undefined);
204
+ catch (e) {
205
+ // It was messing up with SSR so we are catching the errors
206
+ /* empty */
193
207
  }
194
208
  const { consumeNonce } = useFetchNonce.useFetchNonce(environmentId);
195
209
  const [qrcodeUri, setQrcodeUri] = React.useState('');
@@ -662,31 +676,24 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
662
676
  walletUiUtils,
663
677
  walletsFilter,
664
678
  ]);
665
- React.useEffect(() => {
666
- const addPrefetch = (attr) => {
667
- if (!document.head.querySelector(`#${attr.id}`)) {
668
- const element = document.createElement('link');
669
- element.setAttribute('id', attr.id);
670
- element.setAttribute('rel', 'prefetch');
671
- element.setAttribute('href', attr.href);
672
- element.setAttribute('as', attr.as);
673
- element.setAttribute('type', attr.type);
674
- document.head.insertAdjacentElement('beforeend', element);
675
- }
676
- };
677
- addPrefetch({
678
- as: 'image',
679
- href: iconic.getIconicSpriteUrl(),
680
- id: 'sprite',
681
- type: 'image/svg+xml',
682
- });
683
- addPrefetch({
684
- as: 'fetch',
685
- href: walletBook.getWalletBookCdnUrl(),
686
- id: 'wallet-book',
687
- type: 'application/json',
688
- });
689
- }, []);
679
+ usePrefetch.usePrefetch({
680
+ as: 'image',
681
+ href: iconic.getIconicSpriteUrl(),
682
+ id: 'sprite',
683
+ type: 'image/svg+xml',
684
+ });
685
+ usePrefetch.usePrefetch({
686
+ as: 'fetch',
687
+ href: walletBook.getWalletBookCdnUrl(),
688
+ id: 'wallet-book',
689
+ type: 'application/json',
690
+ });
691
+ usePrefetch.usePrefetch({
692
+ as: 'fetch',
693
+ href: `${ApiEndpoint.getBaseUrl()}/sdk/${environmentId}/settings?sdkVersion=${encodeURIComponent(`WalletKit/${version.VERSION}`)}`,
694
+ id: `project-settings-${environmentId}`,
695
+ type: 'application/json',
696
+ });
690
697
  // DYN-1140 - Opens Widget when multiWalletWidgetState changes
691
698
  React.useEffect(() => {
692
699
  // If statement to secure SingleWallet widget
@@ -709,8 +716,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
709
716
  };
710
717
  /** The context provider you need to have access too all of Dynamic's hooks */
711
718
  const DynamicContextProvider = (props) => {
712
- logger.Logger.setEnvironmentId(props.settings.environmentId);
713
- logger.Logger.setEmitErrors(props.emitErrors);
719
+ try {
720
+ logger.Logger.setEnvironmentId(props.settings.environmentId);
721
+ logger.Logger.setEmitErrors(props.emitErrors);
722
+ }
723
+ catch (e) {
724
+ // Sometimes in SSR Logger is not available
725
+ /* empty */
726
+ }
714
727
  useParentDynamicContextGuard.useParentDynamicContextGuard();
715
728
  return (jsxRuntime.jsx(ErrorBoundary.ErrorBoundary, { children: jsxRuntime.jsx(ErrorContext.ErrorContextProvider, { children: jsxRuntime.jsx(UserWalletsContext.UserWalletsProvider, { children: jsxRuntime.jsx(FieldsStateContext.FieldsStateProvider, { children: jsxRuntime.jsx(IpConfigurationContext.IpConfigurationContextProvider, { children: jsxRuntime.jsx(MfaSettingsContext.MfaSettingsContextProvider, { children: jsxRuntime.jsx(WidgetRegistryContextProvider.WidgetRegistryContextProvider, { children: jsxRuntime.jsx(InnerDynamicContextProvider, Object.assign({}, props)) }) }) }) }) }) }) }));
716
729
  };
@@ -21,6 +21,7 @@ import { DEFAULT_NUMBER_OF_WALLETS_TO_SHOW } from '../../utils/constants/values.
21
21
  import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js';
22
22
  import { useGlobalLoading } from '../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.js';
23
23
  import { useLocalStorage } from '../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
24
+ import { usePrefetch } from '../../shared/utils/hooks/usePrefetch/usePrefetch.js';
24
25
  import '../../shared/consts/index.js';
25
26
  import { CaptchaContextProvider } from '../CaptchaContext/CaptchaContext.js';
26
27
  import { ErrorContextProvider } from '../ErrorContext/ErrorContext.js';
@@ -30,6 +31,7 @@ import { getMinAuthToken } from '../../utils/functions/getMinAuthToken/getMinAut
30
31
  import 'react-international-phone';
31
32
  import 'viem';
32
33
  import 'viem/chains';
34
+ import { VERSION } from '../../../version.js';
33
35
  import ApiEndpoint from '../../config/ApiEndpoint.js';
34
36
  import { setUser } from '../../store/actions/userActions/userActions.js';
35
37
  import { sendDynamicProps } from '../../data/api/settings/settings.js';
@@ -160,8 +162,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
160
162
  if (!environmentId) {
161
163
  throw new MissingEnvironmentIdError();
162
164
  }
163
- logger.setLogLevel(logLevel);
164
- logger$1.setLogLevel(logLevel);
165
+ try {
166
+ logger.setLogLevel(logLevel);
167
+ logger$1.setLogLevel(logLevel);
168
+ }
169
+ catch (_j) {
170
+ // logger could be messing up with SSR so we are catching the errors
171
+ /* empty */
172
+ }
165
173
  if (environmentId === PUBLIC_PROJECT_LIVE_ENVIRONMENT_ID) {
166
174
  logger.warn(`WARNING: DYNAMIC is using a test environment ID ${environmentId}. Please sign up on https://app.dynamic.xyz/ to get your production environment ID.`);
167
175
  }
@@ -181,11 +189,17 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
181
189
  const [isSingleWalletAccount, setIsSingleWalletAccount] = useState(false);
182
190
  const { user, unauthenticatedUser } = useUser();
183
191
  const isAuthenticated = useIsAuthenticated(user);
184
- if (user) {
185
- logger.setMetaData('user', user);
192
+ try {
193
+ if (user) {
194
+ logger.setMetaData('user', user);
195
+ }
196
+ else {
197
+ logger.setMetaData('user', undefined);
198
+ }
186
199
  }
187
- else {
188
- logger.setMetaData('user', undefined);
200
+ catch (e) {
201
+ // It was messing up with SSR so we are catching the errors
202
+ /* empty */
189
203
  }
190
204
  const { consumeNonce } = useFetchNonce(environmentId);
191
205
  const [qrcodeUri, setQrcodeUri] = useState('');
@@ -658,31 +672,24 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
658
672
  walletUiUtils,
659
673
  walletsFilter,
660
674
  ]);
661
- useEffect(() => {
662
- const addPrefetch = (attr) => {
663
- if (!document.head.querySelector(`#${attr.id}`)) {
664
- const element = document.createElement('link');
665
- element.setAttribute('id', attr.id);
666
- element.setAttribute('rel', 'prefetch');
667
- element.setAttribute('href', attr.href);
668
- element.setAttribute('as', attr.as);
669
- element.setAttribute('type', attr.type);
670
- document.head.insertAdjacentElement('beforeend', element);
671
- }
672
- };
673
- addPrefetch({
674
- as: 'image',
675
- href: getIconicSpriteUrl(),
676
- id: 'sprite',
677
- type: 'image/svg+xml',
678
- });
679
- addPrefetch({
680
- as: 'fetch',
681
- href: getWalletBookCdnUrl(),
682
- id: 'wallet-book',
683
- type: 'application/json',
684
- });
685
- }, []);
675
+ usePrefetch({
676
+ as: 'image',
677
+ href: getIconicSpriteUrl(),
678
+ id: 'sprite',
679
+ type: 'image/svg+xml',
680
+ });
681
+ usePrefetch({
682
+ as: 'fetch',
683
+ href: getWalletBookCdnUrl(),
684
+ id: 'wallet-book',
685
+ type: 'application/json',
686
+ });
687
+ usePrefetch({
688
+ as: 'fetch',
689
+ href: `${ApiEndpoint.getBaseUrl()}/sdk/${environmentId}/settings?sdkVersion=${encodeURIComponent(`WalletKit/${VERSION}`)}`,
690
+ id: `project-settings-${environmentId}`,
691
+ type: 'application/json',
692
+ });
686
693
  // DYN-1140 - Opens Widget when multiWalletWidgetState changes
687
694
  useEffect(() => {
688
695
  // If statement to secure SingleWallet widget
@@ -705,8 +712,14 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
705
712
  };
706
713
  /** The context provider you need to have access too all of Dynamic's hooks */
707
714
  const DynamicContextProvider = (props) => {
708
- Logger.setEnvironmentId(props.settings.environmentId);
709
- Logger.setEmitErrors(props.emitErrors);
715
+ try {
716
+ Logger.setEnvironmentId(props.settings.environmentId);
717
+ Logger.setEmitErrors(props.emitErrors);
718
+ }
719
+ catch (e) {
720
+ // Sometimes in SSR Logger is not available
721
+ /* empty */
722
+ }
710
723
  useParentDynamicContextGuard();
711
724
  return (jsx(ErrorBoundary, { children: jsx(ErrorContextProvider, { children: jsx(UserWalletsProvider, { children: jsx(FieldsStateProvider, { children: jsx(IpConfigurationContextProvider, { children: jsx(MfaSettingsContextProvider, { children: jsx(WidgetRegistryContextProvider, { children: jsx(InnerDynamicContextProvider, Object.assign({}, props)) }) }) }) }) }) }) }));
712
725
  };
@@ -5,4 +5,5 @@ export { useLocalStorage } from './useLocalStorage';
5
5
  export { useMediaQuery } from './useMediaQuery';
6
6
  export { useOnClickOutside } from './useOnClickOutside';
7
7
  export { usePreventPageScroll } from './usePreventPageScroll';
8
- export * from './useThrottle';
8
+ export { useThrottle } from './useThrottle';
9
+ export { usePrefetch } from './usePrefetch';
@@ -0,0 +1 @@
1
+ export { usePrefetch } from './usePrefetch';
@@ -0,0 +1,51 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ require('@dynamic-labs/sdk-api-core');
7
+ require('../../../logger.cjs');
8
+ require('@dynamic-labs/iconic');
9
+ require('@dynamic-labs/wallet-connector-core');
10
+ require('react/jsx-runtime');
11
+ require('../../../../context/ViewContext/ViewContext.cjs');
12
+ require('react');
13
+ require('@dynamic-labs/wallet-book');
14
+ var isSSR = require('../../functions/isSSR/isSSR.cjs');
15
+ require('../../../../utils/constants/colors.cjs');
16
+ require('../../../../utils/constants/values.cjs');
17
+ require('../../classes/storage/localStorage.cjs');
18
+
19
+ /**
20
+ * Prefetches a resource
21
+ * Adds a link element to the head of the document with the provided attributes
22
+ * when the element is not already present
23
+ * @param {PrefetchProps} prefetchProps
24
+ * @returns {void}
25
+ *
26
+ * @example
27
+ * usePrefetch({
28
+ * href: 'https://example.com/image.jpg',
29
+ * as: 'image',
30
+ * type: 'image/jpeg',
31
+ * id: 'image-prefetch',
32
+ * });
33
+ */
34
+ const usePrefetch = ({ as, href, id, type }) => {
35
+ // Do not run on server side
36
+ if (isSSR.isSSR())
37
+ return;
38
+ const predefinedElement = document.head.querySelector(`#${id}`);
39
+ // Do not add the element if it already exists
40
+ if (predefinedElement)
41
+ return;
42
+ const element = document.createElement('link');
43
+ element.setAttribute('id', id);
44
+ element.setAttribute('rel', 'prefetch');
45
+ element.setAttribute('href', href);
46
+ element.setAttribute('as', as);
47
+ element.setAttribute('type', type);
48
+ document.head.insertAdjacentElement('beforeend', element);
49
+ };
50
+
51
+ exports.usePrefetch = usePrefetch;
@@ -0,0 +1,23 @@
1
+ type PrefetchProps = {
2
+ href: string;
3
+ as: string;
4
+ type: string;
5
+ id: string;
6
+ };
7
+ /**
8
+ * Prefetches a resource
9
+ * Adds a link element to the head of the document with the provided attributes
10
+ * when the element is not already present
11
+ * @param {PrefetchProps} prefetchProps
12
+ * @returns {void}
13
+ *
14
+ * @example
15
+ * usePrefetch({
16
+ * href: 'https://example.com/image.jpg',
17
+ * as: 'image',
18
+ * type: 'image/jpeg',
19
+ * id: 'image-prefetch',
20
+ * });
21
+ */
22
+ export declare const usePrefetch: ({ as, href, id, type }: PrefetchProps) => void;
23
+ export {};
@@ -0,0 +1,47 @@
1
+ 'use client'
2
+ import '@dynamic-labs/sdk-api-core';
3
+ import '../../../logger.js';
4
+ import '@dynamic-labs/iconic';
5
+ import '@dynamic-labs/wallet-connector-core';
6
+ import 'react/jsx-runtime';
7
+ import '../../../../context/ViewContext/ViewContext.js';
8
+ import 'react';
9
+ import '@dynamic-labs/wallet-book';
10
+ import { isSSR } from '../../functions/isSSR/isSSR.js';
11
+ import '../../../../utils/constants/colors.js';
12
+ import '../../../../utils/constants/values.js';
13
+ import '../../classes/storage/localStorage.js';
14
+
15
+ /**
16
+ * Prefetches a resource
17
+ * Adds a link element to the head of the document with the provided attributes
18
+ * when the element is not already present
19
+ * @param {PrefetchProps} prefetchProps
20
+ * @returns {void}
21
+ *
22
+ * @example
23
+ * usePrefetch({
24
+ * href: 'https://example.com/image.jpg',
25
+ * as: 'image',
26
+ * type: 'image/jpeg',
27
+ * id: 'image-prefetch',
28
+ * });
29
+ */
30
+ const usePrefetch = ({ as, href, id, type }) => {
31
+ // Do not run on server side
32
+ if (isSSR())
33
+ return;
34
+ const predefinedElement = document.head.querySelector(`#${id}`);
35
+ // Do not add the element if it already exists
36
+ if (predefinedElement)
37
+ return;
38
+ const element = document.createElement('link');
39
+ element.setAttribute('id', id);
40
+ element.setAttribute('rel', 'prefetch');
41
+ element.setAttribute('href', href);
42
+ element.setAttribute('as', as);
43
+ element.setAttribute('type', type);
44
+ document.head.insertAdjacentElement('beforeend', element);
45
+ };
46
+
47
+ export { usePrefetch };