@dynamic-labs/sdk-react-core 0.18.16 → 0.18.18

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +9 -9
  5. package/src/index.cjs +1 -2
  6. package/src/index.d.ts +1 -1
  7. package/src/index.js +1 -1
  8. package/src/lib/components/SignMessagePreview/SignMessagePreview.cjs +27 -0
  9. package/src/lib/components/SignMessagePreview/SignMessagePreview.d.ts +6 -0
  10. package/src/lib/components/SignMessagePreview/SignMessagePreview.js +23 -0
  11. package/src/lib/components/SignMessagePreview/SignMessagePreview.types.d.ts +8 -0
  12. package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.cjs +44 -0
  13. package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.d.ts +8 -0
  14. package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/SignTypedDataPreview.js +40 -0
  15. package/src/lib/components/SignMessagePreview/components/SignTypedDataPreview/index.d.ts +1 -0
  16. package/src/lib/components/SignMessagePreview/components/index.d.ts +1 -0
  17. package/src/lib/components/SignMessagePreview/index.d.ts +1 -0
  18. package/src/lib/components/SignMessagePreview/utils/index.d.ts +1 -0
  19. package/src/lib/components/SignMessagePreview/utils/isSignTypedData/index.d.ts +1 -0
  20. package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.cjs +17 -0
  21. package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.d.ts +2 -0
  22. package/src/lib/components/SignMessagePreview/utils/isSignTypedData/isSignTypedData.js +13 -0
  23. package/src/lib/components/index.d.ts +1 -0
  24. package/src/lib/data/api.cjs +2 -1
  25. package/src/lib/data/api.d.ts +2 -1
  26. package/src/lib/data/api.js +2 -1
  27. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +2 -1
  28. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +2 -1
  29. package/src/lib/styles/index.shadow.cjs +1 -1
  30. package/src/lib/styles/index.shadow.js +1 -1
  31. package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs +10 -1
  32. package/src/lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js +10 -1
  33. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +4 -1
  34. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +4 -1
  35. package/src/lib/utils/hooks/useWallets/useWallets.cjs +15 -26
  36. package/src/lib/utils/hooks/useWallets/useWallets.js +16 -27
  37. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +1 -1
  38. package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +1 -1
  39. package/src/lib/views/WalletList/data.cjs +3 -15
  40. package/src/lib/views/WalletList/data.d.ts +4 -2
  41. package/src/lib/views/WalletList/data.js +3 -14
  42. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +7 -10
  43. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.d.ts +1 -0
  44. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +8 -11
  45. package/src/lib/widgets/DynamicWidget/hooks/index.d.ts +1 -0
  46. package/src/lib/widgets/DynamicWidget/hooks/useViewController/index.d.ts +1 -0
  47. package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.cjs +17 -0
  48. package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.d.ts +6 -0
  49. package/src/lib/widgets/DynamicWidget/hooks/useViewController/useViewController.js +13 -0
  50. package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.cjs +2 -3
  51. package/src/lib/widgets/DynamicWidget/views/SendBalanceWidgetView/SendBalanceWidgetView.js +2 -3
@@ -22,7 +22,7 @@ const getEnabledChains = (chains) => chains
22
22
  .filter(({ enabled }) => enabled)
23
23
  .map(({ name }) => { var _a; return (_a = walletConnectorCore.getChainInfo(name)) === null || _a === void 0 ? void 0 : _a.symbol; })
24
24
  .filter((chain) => Boolean(chain));
25
- const createWallets = (props) => {
25
+ const getWallets = (props) => {
26
26
  var _a, _b, _c, _d;
27
27
  return multiWallet.getEnabledWallets({
28
28
  enabledChains: getEnabledChains(props.settings.chains),
@@ -31,20 +31,8 @@ const createWallets = (props) => {
31
31
  ((_b = props.settings.sdk.walletConnect) === null || _b === void 0 ? void 0 : _b.projectId)
32
32
  ? (_c = props.settings.sdk.walletConnect) === null || _c === void 0 ? void 0 : _c.v2Enabled
33
33
  : false, walletConnectProjectId: (_d = props.settings.sdk.walletConnect) === null || _d === void 0 ? void 0 : _d.projectId }),
34
- installed: props.installed,
35
34
  }).map((wallet) => createWallet.createWallet(props.getSupportedWalletOpts.walletBook, wallet));
36
- };
37
- const getInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
38
- getSupportedWalletOpts,
39
- installed: true,
40
- settings,
41
- });
42
- const getNotInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
43
- getSupportedWalletOpts,
44
- installed: false,
45
- settings,
46
- });
35
+ };
47
36
 
48
37
  exports.getEnabledChains = getEnabledChains;
49
- exports.getInstalledWallets = getInstalledWallets;
50
- exports.getNotInstalledWallets = getNotInstalledWallets;
38
+ exports.getWallets = getWallets;
@@ -6,6 +6,8 @@ interface IChain {
6
6
  }
7
7
  export declare const getEnabledChains: (chains: IChain[]) => ("ETH" | "FLOW" | "SOL" | "EVM" | "ALGO" | "STARK" | "ATOM" | "COSMOS")[];
8
8
  type BaseGetSupportedWalletOpts = Omit<GetSupportedWalletsOpts, 'isWalletConnectV2Enabled' | 'walletConnectProjectId' | 'chainRpcProviders'>;
9
- export declare const getInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) => import("../../shared").WalletOption[];
10
- export declare const getNotInstalledWallets: (settings: ProjectSettings, getSupportedWalletOpts: BaseGetSupportedWalletOpts) => import("../../shared").WalletOption[];
9
+ export declare const getWallets: (props: {
10
+ getSupportedWalletOpts: BaseGetSupportedWalletOpts;
11
+ settings: ProjectSettings;
12
+ }) => import("../../shared").WalletOption[];
11
13
  export {};
@@ -18,7 +18,7 @@ const getEnabledChains = (chains) => chains
18
18
  .filter(({ enabled }) => enabled)
19
19
  .map(({ name }) => { var _a; return (_a = getChainInfo(name)) === null || _a === void 0 ? void 0 : _a.symbol; })
20
20
  .filter((chain) => Boolean(chain));
21
- const createWallets = (props) => {
21
+ const getWallets = (props) => {
22
22
  var _a, _b, _c, _d;
23
23
  return getEnabledWallets({
24
24
  enabledChains: getEnabledChains(props.settings.chains),
@@ -27,18 +27,7 @@ const createWallets = (props) => {
27
27
  ((_b = props.settings.sdk.walletConnect) === null || _b === void 0 ? void 0 : _b.projectId)
28
28
  ? (_c = props.settings.sdk.walletConnect) === null || _c === void 0 ? void 0 : _c.v2Enabled
29
29
  : false, walletConnectProjectId: (_d = props.settings.sdk.walletConnect) === null || _d === void 0 ? void 0 : _d.projectId }),
30
- installed: props.installed,
31
30
  }).map((wallet) => createWallet(props.getSupportedWalletOpts.walletBook, wallet));
32
- };
33
- const getInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
34
- getSupportedWalletOpts,
35
- installed: true,
36
- settings,
37
- });
38
- const getNotInstalledWallets = (settings, getSupportedWalletOpts) => createWallets({
39
- getSupportedWalletOpts,
40
- installed: false,
41
- settings,
42
- });
31
+ };
43
32
 
44
- export { getEnabledChains, getInstalledWallets, getNotInstalledWallets };
33
+ export { getEnabledChains, getWallets };
@@ -38,6 +38,7 @@ require('formik');
38
38
  require('yup');
39
39
  require('../../../components/InlineWidget/InlineWidget.cjs');
40
40
  require('../../../components/MenuList/Dropdown/Dropdown.cjs');
41
+ var useViewController = require('../hooks/useViewController/useViewController.cjs');
41
42
  var useKYCFlag = require('../../../utils/hooks/useKYCFlag/useKYCFlag.cjs');
42
43
  var useMultiWalletFlag = require('../../../utils/hooks/useMultiWalletFlag/useMultiWalletFlag.cjs');
43
44
  require('../../../context/MockContext/MockContext.cjs');
@@ -52,8 +53,7 @@ const DynamicWidgetContextProvider = ({ children, }) => {
52
53
  const { setShowDynamicUserProfile, showDynamicUserProfile } = useInternalDynamicContext.useInternalDynamicContext();
53
54
  const isKYCEnabled = useKYCFlag.useKYCFlag();
54
55
  const isMultiWalletEnabled = useMultiWalletFlag.useMultiWalletFlag();
55
- const initialView = React.useMemo(() => (isKYCEnabled && !isMultiWalletEnabled ? 'profile' : 'wallets'), [isKYCEnabled, isMultiWalletEnabled]);
56
- const [dynamicWidgetView, setDynamicWidgetView] = React.useState(initialView);
56
+ const { view: dynamicWidgetView, setView: setDynamicWidgetView, goToInitialView: goToInitialDynamicWidgetView, } = useViewController.useViewController(isKYCEnabled && !isMultiWalletEnabled ? 'profile' : 'wallets');
57
57
  const goToProfileView = React.useCallback(() => {
58
58
  if (isKYCEnabled)
59
59
  return setDynamicWidgetView('profile');
@@ -64,18 +64,14 @@ const DynamicWidgetContextProvider = ({ children, }) => {
64
64
  if (!showDynamicUserProfile) {
65
65
  // wait for exit animation to finish
66
66
  setTimeout(() => {
67
- setDynamicWidgetView(initialView);
67
+ goToInitialDynamicWidgetView();
68
68
  }, 200);
69
69
  }
70
- }, [initialView, showDynamicUserProfile]);
71
- // set correct initial view once isKYCEnabled and isMultiWalletEnabled values are correctly set
72
- // *isKYCEnabled is always false when the context initializes, so the initial view is set to index
73
- React.useEffect(() => {
74
- setDynamicWidgetView(initialView);
75
- }, [initialView, isKYCEnabled, isMultiWalletEnabled]);
70
+ }, [goToInitialDynamicWidgetView, showDynamicUserProfile]);
76
71
  const value = React.useMemo(() => ({
77
72
  availableWalletsContainerRef,
78
73
  dynamicWidgetView,
74
+ goToInitialDynamicWidgetView,
79
75
  goToProfileView,
80
76
  inlineControlsRef,
81
77
  isOpen: showDynamicUserProfile,
@@ -84,8 +80,9 @@ const DynamicWidgetContextProvider = ({ children, }) => {
84
80
  widgetRef,
85
81
  }), [
86
82
  dynamicWidgetView,
87
- goToProfileView,
88
83
  setShowDynamicUserProfile,
84
+ goToInitialDynamicWidgetView,
85
+ goToProfileView,
89
86
  showDynamicUserProfile,
90
87
  ]);
91
88
  return (jsxRuntime.jsx(DynamicWidgetContext.Provider, Object.assign({ value: value }, { children: children })));
@@ -3,6 +3,7 @@ export interface WidgetContextProps {
3
3
  availableWalletsContainerRef: RefObject<HTMLDivElement>;
4
4
  dynamicWidgetView: DynamicWidgetViews;
5
5
  goToProfileView: () => void;
6
+ goToInitialDynamicWidgetView: () => void;
6
7
  inlineControlsRef: RefObject<HTMLDivElement>;
7
8
  isOpen: boolean;
8
9
  setDynamicWidgetView: Dispatch<SetStateAction<DynamicWidgetViews>>;
@@ -1,5 +1,5 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { createContext, useRef, useMemo, useState, useCallback, useEffect, useContext } from 'react';
2
+ import { createContext, useRef, useCallback, useEffect, useMemo, useContext } from 'react';
3
3
  import '@dynamic-labs/utils';
4
4
  import '@dynamic-labs/sdk-api';
5
5
  import '../../../config/ApiEndpoint.js';
@@ -34,6 +34,7 @@ import 'formik';
34
34
  import 'yup';
35
35
  import '../../../components/InlineWidget/InlineWidget.js';
36
36
  import '../../../components/MenuList/Dropdown/Dropdown.js';
37
+ import { useViewController } from '../hooks/useViewController/useViewController.js';
37
38
  import { useKYCFlag } from '../../../utils/hooks/useKYCFlag/useKYCFlag.js';
38
39
  import { useMultiWalletFlag } from '../../../utils/hooks/useMultiWalletFlag/useMultiWalletFlag.js';
39
40
  import '../../../context/MockContext/MockContext.js';
@@ -48,8 +49,7 @@ const DynamicWidgetContextProvider = ({ children, }) => {
48
49
  const { setShowDynamicUserProfile, showDynamicUserProfile } = useInternalDynamicContext();
49
50
  const isKYCEnabled = useKYCFlag();
50
51
  const isMultiWalletEnabled = useMultiWalletFlag();
51
- const initialView = useMemo(() => (isKYCEnabled && !isMultiWalletEnabled ? 'profile' : 'wallets'), [isKYCEnabled, isMultiWalletEnabled]);
52
- const [dynamicWidgetView, setDynamicWidgetView] = useState(initialView);
52
+ const { view: dynamicWidgetView, setView: setDynamicWidgetView, goToInitialView: goToInitialDynamicWidgetView, } = useViewController(isKYCEnabled && !isMultiWalletEnabled ? 'profile' : 'wallets');
53
53
  const goToProfileView = useCallback(() => {
54
54
  if (isKYCEnabled)
55
55
  return setDynamicWidgetView('profile');
@@ -60,18 +60,14 @@ const DynamicWidgetContextProvider = ({ children, }) => {
60
60
  if (!showDynamicUserProfile) {
61
61
  // wait for exit animation to finish
62
62
  setTimeout(() => {
63
- setDynamicWidgetView(initialView);
63
+ goToInitialDynamicWidgetView();
64
64
  }, 200);
65
65
  }
66
- }, [initialView, showDynamicUserProfile]);
67
- // set correct initial view once isKYCEnabled and isMultiWalletEnabled values are correctly set
68
- // *isKYCEnabled is always false when the context initializes, so the initial view is set to index
69
- useEffect(() => {
70
- setDynamicWidgetView(initialView);
71
- }, [initialView, isKYCEnabled, isMultiWalletEnabled]);
66
+ }, [goToInitialDynamicWidgetView, showDynamicUserProfile]);
72
67
  const value = useMemo(() => ({
73
68
  availableWalletsContainerRef,
74
69
  dynamicWidgetView,
70
+ goToInitialDynamicWidgetView,
75
71
  goToProfileView,
76
72
  inlineControlsRef,
77
73
  isOpen: showDynamicUserProfile,
@@ -80,8 +76,9 @@ const DynamicWidgetContextProvider = ({ children, }) => {
80
76
  widgetRef,
81
77
  }), [
82
78
  dynamicWidgetView,
83
- goToProfileView,
84
79
  setShowDynamicUserProfile,
80
+ goToInitialDynamicWidgetView,
81
+ goToProfileView,
85
82
  showDynamicUserProfile,
86
83
  ]);
87
84
  return (jsx(DynamicWidgetContext.Provider, Object.assign({ value: value }, { children: children })));
@@ -2,3 +2,4 @@ export { useContent } from './useContent';
2
2
  export { useFetchBalance } from './useFetchBalance';
3
3
  export { useFetchChain } from './useFetchChain';
4
4
  export { useFetchCurrency } from './useFetchCurrency';
5
+ export { useViewController } from './useViewController';
@@ -0,0 +1 @@
1
+ export { useViewController } from './useViewController';
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ const useViewController = (initialView) => {
8
+ const [_view, setView] = React.useState(null);
9
+ const goToInitialView = () => setView(null);
10
+ return {
11
+ goToInitialView,
12
+ setView: setView,
13
+ view: _view || initialView,
14
+ };
15
+ };
16
+
17
+ exports.useViewController = useViewController;
@@ -0,0 +1,6 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ export declare const useViewController: <VIEW extends string>(initialView: VIEW) => {
3
+ goToInitialView: () => void;
4
+ setView: Dispatch<SetStateAction<VIEW>>;
5
+ view: VIEW;
6
+ };
@@ -0,0 +1,13 @@
1
+ import { useState } from 'react';
2
+
3
+ const useViewController = (initialView) => {
4
+ const [_view, setView] = useState(null);
5
+ const goToInitialView = () => setView(null);
6
+ return {
7
+ goToInitialView,
8
+ setView: setView,
9
+ view: _view || initialView,
10
+ };
11
+ };
12
+
13
+ export { useViewController };
@@ -7,9 +7,8 @@ var DynamicWidgetContext = require('../../context/DynamicWidgetContext.cjs');
7
7
  var SendBalanceView = require('../../../../views/SendBalanceView/SendBalanceView.cjs');
8
8
 
9
9
  const SendBalanceWidgetView = () => {
10
- const { setDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
11
- const goToIndex = () => setDynamicWidgetView('wallets');
12
- return (jsxRuntime.jsx("div", Object.assign({ className: 'send-balance-widget-view' }, { children: jsxRuntime.jsx(SendBalanceView.SendBalanceView, { onClickBack: goToIndex, onDone: goToIndex }) })));
10
+ const { goToInitialDynamicWidgetView } = DynamicWidgetContext.useWidgetContext();
11
+ return (jsxRuntime.jsx("div", Object.assign({ className: 'send-balance-widget-view' }, { children: jsxRuntime.jsx(SendBalanceView.SendBalanceView, { onClickBack: goToInitialDynamicWidgetView, onDone: goToInitialDynamicWidgetView }) })));
13
12
  };
14
13
 
15
14
  exports.SendBalanceWidgetView = SendBalanceWidgetView;
@@ -3,9 +3,8 @@ import { useWidgetContext } from '../../context/DynamicWidgetContext.js';
3
3
  import { SendBalanceView } from '../../../../views/SendBalanceView/SendBalanceView.js';
4
4
 
5
5
  const SendBalanceWidgetView = () => {
6
- const { setDynamicWidgetView } = useWidgetContext();
7
- const goToIndex = () => setDynamicWidgetView('wallets');
8
- return (jsx("div", Object.assign({ className: 'send-balance-widget-view' }, { children: jsx(SendBalanceView, { onClickBack: goToIndex, onDone: goToIndex }) })));
6
+ const { goToInitialDynamicWidgetView } = useWidgetContext();
7
+ return (jsx("div", Object.assign({ className: 'send-balance-widget-view' }, { children: jsx(SendBalanceView, { onClickBack: goToInitialDynamicWidgetView, onDone: goToInitialDynamicWidgetView }) })));
9
8
  };
10
9
 
11
10
  export { SendBalanceWidgetView };