@dynamic-labs/sdk-react-core 2.3.2 → 2.3.4

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,18 @@
1
1
 
2
+ ### [2.3.4](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.3...v2.3.4) (2024-07-19)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * not able to switch to secondary wallet ([#6373](https://github.com/dynamic-labs/DynamicAuth/issues/6373)) ([#6378](https://github.com/dynamic-labs/DynamicAuth/issues/6378)) ([7c4f220](https://github.com/dynamic-labs/DynamicAuth/commit/7c4f2200cc66da1889b5de03a6823a96043825da))
8
+
9
+ ### [2.3.3](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.2...v2.3.3) (2024-07-18)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * add project setting prefetch ([#6368](https://github.com/dynamic-labs/DynamicAuth/issues/6368)) ([4f3009e](https://github.com/dynamic-labs/DynamicAuth/commit/4f3009ec1fbe110be73bd7b775cfb040592a8b2a))
15
+
2
16
  ### [2.3.2](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.1...v2.3.2) (2024-07-16)
3
17
 
4
18
  ### [2.3.1](https://github.com/dynamic-labs/DynamicAuth/compare/v2.3.1-alpha.0...v2.3.1) (2024-07-13)
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.2";
6
+ var version = "2.3.4";
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.2";
2
+ var version = "2.3.4";
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.2",
3
+ "version": "2.3.4",
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.2",
21
- "@dynamic-labs/logger": "2.3.2",
22
- "@dynamic-labs/multi-wallet": "2.3.2",
23
- "@dynamic-labs/rpc-provider-ethereum": "2.3.2",
24
- "@dynamic-labs/rpc-provider-solana": "2.3.2",
25
- "@dynamic-labs/rpc-providers": "2.3.2",
26
- "@dynamic-labs/store": "2.3.2",
27
- "@dynamic-labs/types": "2.3.2",
28
- "@dynamic-labs/utils": "2.3.2",
29
- "@dynamic-labs/viem-utils": "2.3.2",
30
- "@dynamic-labs/wallet-book": "2.3.2",
31
- "@dynamic-labs/wallet-connector-core": "2.3.2",
20
+ "@dynamic-labs/iconic": "2.3.4",
21
+ "@dynamic-labs/logger": "2.3.4",
22
+ "@dynamic-labs/multi-wallet": "2.3.4",
23
+ "@dynamic-labs/rpc-provider-ethereum": "2.3.4",
24
+ "@dynamic-labs/rpc-provider-solana": "2.3.4",
25
+ "@dynamic-labs/rpc-providers": "2.3.4",
26
+ "@dynamic-labs/store": "2.3.4",
27
+ "@dynamic-labs/types": "2.3.4",
28
+ "@dynamic-labs/utils": "2.3.4",
29
+ "@dynamic-labs/viem-utils": "2.3.4",
30
+ "@dynamic-labs/wallet-book": "2.3.4",
31
+ "@dynamic-labs/wallet-connector-core": "2.3.4",
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');
@@ -674,31 +676,24 @@ const InnerDynamicContextProvider = ({ children, theme, settings: settings$1, lo
674
676
  walletUiUtils,
675
677
  walletsFilter,
676
678
  ]);
677
- React.useEffect(() => {
678
- const addPrefetch = (attr) => {
679
- if (!document.head.querySelector(`#${attr.id}`)) {
680
- const element = document.createElement('link');
681
- element.setAttribute('id', attr.id);
682
- element.setAttribute('rel', 'prefetch');
683
- element.setAttribute('href', attr.href);
684
- element.setAttribute('as', attr.as);
685
- element.setAttribute('type', attr.type);
686
- document.head.insertAdjacentElement('beforeend', element);
687
- }
688
- };
689
- addPrefetch({
690
- as: 'image',
691
- href: iconic.getIconicSpriteUrl(),
692
- id: 'sprite',
693
- type: 'image/svg+xml',
694
- });
695
- addPrefetch({
696
- as: 'fetch',
697
- href: walletBook.getWalletBookCdnUrl(),
698
- id: 'wallet-book',
699
- type: 'application/json',
700
- });
701
- }, []);
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
+ });
702
697
  // DYN-1140 - Opens Widget when multiWalletWidgetState changes
703
698
  React.useEffect(() => {
704
699
  // If statement to secure SingleWallet widget
@@ -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';
@@ -670,31 +672,24 @@ const InnerDynamicContextProvider = ({ children, theme, settings, locale, enable
670
672
  walletUiUtils,
671
673
  walletsFilter,
672
674
  ]);
673
- useEffect(() => {
674
- const addPrefetch = (attr) => {
675
- if (!document.head.querySelector(`#${attr.id}`)) {
676
- const element = document.createElement('link');
677
- element.setAttribute('id', attr.id);
678
- element.setAttribute('rel', 'prefetch');
679
- element.setAttribute('href', attr.href);
680
- element.setAttribute('as', attr.as);
681
- element.setAttribute('type', attr.type);
682
- document.head.insertAdjacentElement('beforeend', element);
683
- }
684
- };
685
- addPrefetch({
686
- as: 'image',
687
- href: getIconicSpriteUrl(),
688
- id: 'sprite',
689
- type: 'image/svg+xml',
690
- });
691
- addPrefetch({
692
- as: 'fetch',
693
- href: getWalletBookCdnUrl(),
694
- id: 'wallet-book',
695
- type: 'application/json',
696
- });
697
- }, []);
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
+ });
698
693
  // DYN-1140 - Opens Widget when multiWalletWidgetState changes
699
694
  useEffect(() => {
700
695
  // If statement to secure SingleWallet widget
@@ -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 };
@@ -82,7 +82,7 @@ require('../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/Passke
82
82
  var useInternalDynamicContext = require('../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
83
83
 
84
84
  const useSyncPrimaryWallet = (canSync = true) => {
85
- const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, setMultiWalletWidgetState, showLockedWalletView, secondaryWallets, setPrimaryWallet, setSelectedWalletWithAction, multiWallet, } = useInternalDynamicContext.useInternalDynamicContext();
85
+ const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, setMultiWalletWidgetState, showLockedWalletView, secondaryWallets, setPrimaryWallet, setSelectedWalletWithAction, multiWallet, selectedWalletWithAction, } = useInternalDynamicContext.useInternalDynamicContext();
86
86
  const { setView } = ViewContext.useViewContext();
87
87
  const handlePrimaryWalletNotActive = React.useCallback((connectedAddress) => {
88
88
  logVerboseTroubleshootingMessage.logVerboseTroubleshootingMessage('[useSyncPrimaryWallet] handlePrimaryWalletNotActive', {
@@ -104,7 +104,11 @@ const useSyncPrimaryWallet = (canSync = true) => {
104
104
  connectedWalletWithSameProvider,
105
105
  multiWallet,
106
106
  });
107
- if (multiWallet && connectedWalletWithSameProvider) {
107
+ // If user was explicitly trying to switch to this new wallet, let it be
108
+ const wasExplicitWalletChange = (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) === primaryWallet.address;
109
+ if (multiWallet &&
110
+ connectedWalletWithSameProvider &&
111
+ !wasExplicitWalletChange) {
108
112
  setPrimaryWallet(connectedWalletWithSameProvider.id);
109
113
  return;
110
114
  }
@@ -119,6 +123,7 @@ const useSyncPrimaryWallet = (canSync = true) => {
119
123
  primaryWallet,
120
124
  secondaryWallets,
121
125
  multiWallet,
126
+ selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address,
122
127
  setSelectedWalletWithAction,
123
128
  setMultiWalletWidgetState,
124
129
  connectWallet,
@@ -78,7 +78,7 @@ import '../../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/Passkey
78
78
  import { useInternalDynamicContext } from '../../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
79
79
 
80
80
  const useSyncPrimaryWallet = (canSync = true) => {
81
- const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, setMultiWalletWidgetState, showLockedWalletView, secondaryWallets, setPrimaryWallet, setSelectedWalletWithAction, multiWallet, } = useInternalDynamicContext();
81
+ const { setShowAuthFlow, isAuthenticated, authMode, connectWallet, handleLogOut, multiWalletWidgetState, primaryWallet, setMultiWalletWidgetState, showLockedWalletView, secondaryWallets, setPrimaryWallet, setSelectedWalletWithAction, multiWallet, selectedWalletWithAction, } = useInternalDynamicContext();
82
82
  const { setView } = useViewContext();
83
83
  const handlePrimaryWalletNotActive = useCallback((connectedAddress) => {
84
84
  logVerboseTroubleshootingMessage('[useSyncPrimaryWallet] handlePrimaryWalletNotActive', {
@@ -100,7 +100,11 @@ const useSyncPrimaryWallet = (canSync = true) => {
100
100
  connectedWalletWithSameProvider,
101
101
  multiWallet,
102
102
  });
103
- if (multiWallet && connectedWalletWithSameProvider) {
103
+ // If user was explicitly trying to switch to this new wallet, let it be
104
+ const wasExplicitWalletChange = (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) === primaryWallet.address;
105
+ if (multiWallet &&
106
+ connectedWalletWithSameProvider &&
107
+ !wasExplicitWalletChange) {
104
108
  setPrimaryWallet(connectedWalletWithSameProvider.id);
105
109
  return;
106
110
  }
@@ -115,6 +119,7 @@ const useSyncPrimaryWallet = (canSync = true) => {
115
119
  primaryWallet,
116
120
  secondaryWallets,
117
121
  multiWallet,
122
+ selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address,
118
123
  setSelectedWalletWithAction,
119
124
  setMultiWalletWidgetState,
120
125
  connectWallet,
@@ -0,0 +1,3 @@
1
+ export { DynamicWidget } from './DynamicWidget';
2
+ export { ShadowedDynamicNav as DynamicNav } from './components/DynamicNav/DynamicNav';
3
+ export { ShadowedDynamicUserProfile as DynamicUserProfile } from './components/DynamicUserProfile';