@dynamic-labs/sdk-react-core 0.17.0-RC.4 → 0.17.0-RC.5

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,12 @@
1
1
 
2
+ ## [0.17.0-RC.5](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.4...v0.17.0-RC.5) (2023-04-24)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * **Cypress:** add polyfills ([#1945](https://github.com/dynamic-labs/DynamicAuth/issues/1945)) ([4902ecf](https://github.com/dynamic-labs/DynamicAuth/commit/4902ecf74306cc052c2df52796e1b254fb1829e5))
8
+ * **DYN-2261:** hide authorization flow after network switch ([#1942](https://github.com/dynamic-labs/DynamicAuth/issues/1942)) ([cc3ca53](https://github.com/dynamic-labs/DynamicAuth/commit/cc3ca5398191f18046958cc950cec25d6043fab3))
9
+
2
10
  ## [0.17.0-RC.4](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.0-RC.3...v0.17.0-RC.4) (2023-04-22)
3
11
 
4
12
 
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.0-RC.4";
5
+ var version = "0.17.0-RC.5";
6
6
  var dependencies = {
7
7
  "react-focus-lock": "^2.9.2",
8
8
  "@dynamic-labs/sdk-api": "0.0.178",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.17.0-RC.4";
1
+ var version = "0.17.0-RC.5";
2
2
  var dependencies = {
3
3
  "react-focus-lock": "^2.9.2",
4
4
  "@dynamic-labs/sdk-api": "0.0.178",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "0.17.0-RC.4",
3
+ "version": "0.17.0-RC.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -17,9 +17,9 @@
17
17
  "formik": "^2.2.9",
18
18
  "qrcode": "1.5.1",
19
19
  "ethers": "^5.7.2",
20
- "@dynamic-labs/logger": "0.17.0-RC.4",
21
- "@dynamic-labs/multi-wallet": "0.17.0-RC.4",
22
- "@dynamic-labs/wallet-connector-core": "0.17.0-RC.4"
20
+ "@dynamic-labs/logger": "0.17.0-RC.5",
21
+ "@dynamic-labs/multi-wallet": "0.17.0-RC.5",
22
+ "@dynamic-labs/wallet-connector-core": "0.17.0-RC.5"
23
23
  },
24
24
  "devDependencies": {
25
25
  "semver": "^7.3.8"
@@ -6,6 +6,13 @@ var React = require('react');
6
6
  var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
7
7
  var useCreateUserProfileByJWTCallback = require('../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.cjs');
8
8
 
9
+ /**
10
+ * A custom React hook that returns a function to update the user profile using a JSON Web Token (JWT).
11
+ * This hook internally uses the 'useCreateUserProfileByJWTCallback' hook to create the user profile by JWT
12
+ * and the 'useInternalDynamicContext' hook to set the callback for when the user profile is updated.
13
+ * The returned function uses 'useCallback' to memoize the function and optimize performance.
14
+ * @returns An object with the 'updateUserProfileByJWT' function.
15
+ */
9
16
  const useUpdateUserProfileByJWTCallback = () => {
10
17
  const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback.useCreateUserProfileByJWTCallback();
11
18
  const { setCallback } = useInternalDynamicContext.useInternalDynamicContext();
@@ -1,3 +1,10 @@
1
+ /**
2
+ * A custom React hook that returns a function to update the user profile using a JSON Web Token (JWT).
3
+ * This hook internally uses the 'useCreateUserProfileByJWTCallback' hook to create the user profile by JWT
4
+ * and the 'useInternalDynamicContext' hook to set the callback for when the user profile is updated.
5
+ * The returned function uses 'useCallback' to memoize the function and optimize performance.
6
+ * @returns An object with the 'updateUserProfileByJWT' function.
7
+ */
1
8
  export declare const useUpdateUserProfileByJWTCallback: () => {
2
9
  updateUserProfileByJWT: (jwt: string) => void;
3
10
  };
@@ -2,6 +2,13 @@ import { useCallback } from 'react';
2
2
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
3
3
  import { useCreateUserProfileByJWTCallback } from '../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.js';
4
4
 
5
+ /**
6
+ * A custom React hook that returns a function to update the user profile using a JSON Web Token (JWT).
7
+ * This hook internally uses the 'useCreateUserProfileByJWTCallback' hook to create the user profile by JWT
8
+ * and the 'useInternalDynamicContext' hook to set the callback for when the user profile is updated.
9
+ * The returned function uses 'useCallback' to memoize the function and optimize performance.
10
+ * @returns An object with the 'updateUserProfileByJWT' function.
11
+ */
5
12
  const useUpdateUserProfileByJWTCallback = () => {
6
13
  const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback();
7
14
  const { setCallback } = useInternalDynamicContext();
@@ -40,16 +40,22 @@ var useUpdateUserProfileByJWTCallback = require('../../utils/hooks/useUpdateUser
40
40
 
41
41
  const NetworkNotSupported = () => {
42
42
  var _a, _b;
43
- const { handleLogOut, onboardingOnlyJwt, network, onboardingImageUrl, selectedWalletConnector: walletConnector, decodedOnboardingOnlyToken, } = useInternalDynamicContext.useInternalDynamicContext();
43
+ const { handleLogOut, onboardingOnlyJwt, network, onboardingImageUrl, selectedWalletConnector: walletConnector, decodedOnboardingOnlyToken, setShowAuthFlow, } = useInternalDynamicContext.useInternalDynamicContext();
44
44
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
45
45
  const [isNetworkPickerOpen, setIsNetworkPickerOpen] = React.useState(false);
46
46
  if (!decodedOnboardingOnlyToken || !walletConnector) {
47
47
  return null;
48
48
  }
49
+ const onSubmit = () => {
50
+ if (!onboardingOnlyJwt)
51
+ return;
52
+ updateUserProfileByJWT(onboardingOnlyJwt);
53
+ setShowAuthFlow(false);
54
+ };
49
55
  const userProfile = createUserProfile.createUserProfile(decodedOnboardingOnlyToken);
50
56
  const evmNetworks = walletConnector.evmNetworks || [];
51
57
  const _isSupportedNetwork = isSupportedNetwork.isSupportedNetwork({ network, walletConnector });
52
- return (jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported', "data-testid": 'network-not-supported' }, { children: [onboardingImageUrl && (jsxRuntime.jsx("img", { className: 'network-not-supported__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, Object.assign({ withIcon: false, className: 'network-not-supported__error--not-supported' }, { children: "This network is not available, please update." }))), jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported__content-container' }, { children: [jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__img-container' }, { children: ((_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _a === void 0 ? void 0 : _a.avatar) ? (jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx("img", { src: (_b = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _b === void 0 ? void 0 : _b.avatar, alt: 'user ens avatar', className: 'network-not-supported__img' }) }))) : (jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx(walletBook.WalletIcon, { walletName: walletConnector.name, style: { height: pixelToRem.pixelToRem(64), width: pixelToRem.pixelToRem(64) } }) }))) })), jsxRuntime.jsx(UserAddress.UserAddress, { userProfile: userProfile }), jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx(NetworkPicker.NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, showNetworkName: true, buttonClassName: 'network-not-supported__network-picker-button', mainClassName: 'network-not-supported__network-picker' }) })), jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported__welcome-container' }, { children: [jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'title', color: 'primary', className: 'network-not-supported__welcome-title' }, { children: "Update Network" })), jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'body_normal', weight: 'regular', color: 'secondary' }, { children: "Your wallet is not connected to a supported network. Please update before continuing." })), jsxRuntime.jsx(Button.Button, Object.assign({ type: 'submit', buttonVariant: 'primary', expanded: true, buttonRounded: 'default', buttonPadding: 'large', disabled: !_isSupportedNetwork, onClick: () => onboardingOnlyJwt && updateUserProfileByJWT(onboardingOnlyJwt), buttonClassName: 'network-not-supported__continue' }, { children: "Continue" })), jsxRuntime.jsx(TextButton.TextButton, Object.assign({ className: 'network-not-supported__log-out', onClick: () => handleLogOut() }, { children: "Log out" }))] }))] }))] })));
58
+ return (jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported', "data-testid": 'network-not-supported' }, { children: [onboardingImageUrl && (jsxRuntime.jsx("img", { className: 'network-not-supported__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, Object.assign({ withIcon: false, className: 'network-not-supported__error--not-supported' }, { children: "This network is not available, please update." }))), jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported__content-container' }, { children: [jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__img-container' }, { children: ((_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _a === void 0 ? void 0 : _a.avatar) ? (jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx("img", { src: (_b = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _b === void 0 ? void 0 : _b.avatar, alt: 'user ens avatar', className: 'network-not-supported__img' }) }))) : (jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx(walletBook.WalletIcon, { walletName: walletConnector.name, style: { height: pixelToRem.pixelToRem(64), width: pixelToRem.pixelToRem(64) } }) }))) })), jsxRuntime.jsx(UserAddress.UserAddress, { userProfile: userProfile }), jsxRuntime.jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsxRuntime.jsx(NetworkPicker.NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, showNetworkName: true, buttonClassName: 'network-not-supported__network-picker-button', mainClassName: 'network-not-supported__network-picker' }) })), jsxRuntime.jsxs("div", Object.assign({ className: 'network-not-supported__welcome-container' }, { children: [jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'title', color: 'primary', className: 'network-not-supported__welcome-title' }, { children: "Update Network" })), jsxRuntime.jsx(Typography.Typography, Object.assign({ variant: 'body_normal', weight: 'regular', color: 'secondary' }, { children: "Your wallet is not connected to a supported network. Please update before continuing." })), jsxRuntime.jsx(Button.Button, Object.assign({ type: 'submit', buttonVariant: 'primary', expanded: true, buttonRounded: 'default', buttonPadding: 'large', disabled: !_isSupportedNetwork, onClick: onSubmit, buttonClassName: 'network-not-supported__continue' }, { children: "Continue" })), jsxRuntime.jsx(TextButton.TextButton, Object.assign({ className: 'network-not-supported__log-out', onClick: () => handleLogOut() }, { children: "Log out" }))] }))] }))] })));
53
59
  };
54
60
 
55
61
  exports.NetworkNotSupported = NetworkNotSupported;
@@ -36,16 +36,22 @@ import { useUpdateUserProfileByJWTCallback } from '../../utils/hooks/useUpdateUs
36
36
 
37
37
  const NetworkNotSupported = () => {
38
38
  var _a, _b;
39
- const { handleLogOut, onboardingOnlyJwt, network, onboardingImageUrl, selectedWalletConnector: walletConnector, decodedOnboardingOnlyToken, } = useInternalDynamicContext();
39
+ const { handleLogOut, onboardingOnlyJwt, network, onboardingImageUrl, selectedWalletConnector: walletConnector, decodedOnboardingOnlyToken, setShowAuthFlow, } = useInternalDynamicContext();
40
40
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
41
41
  const [isNetworkPickerOpen, setIsNetworkPickerOpen] = useState(false);
42
42
  if (!decodedOnboardingOnlyToken || !walletConnector) {
43
43
  return null;
44
44
  }
45
+ const onSubmit = () => {
46
+ if (!onboardingOnlyJwt)
47
+ return;
48
+ updateUserProfileByJWT(onboardingOnlyJwt);
49
+ setShowAuthFlow(false);
50
+ };
45
51
  const userProfile = createUserProfile(decodedOnboardingOnlyToken);
46
52
  const evmNetworks = walletConnector.evmNetworks || [];
47
53
  const _isSupportedNetwork = isSupportedNetwork({ network, walletConnector });
48
- return (jsxs("div", Object.assign({ className: 'network-not-supported', "data-testid": 'network-not-supported' }, { children: [onboardingImageUrl && (jsx("img", { className: 'network-not-supported__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsx(ErrorContainer, Object.assign({ withIcon: false, className: 'network-not-supported__error--not-supported' }, { children: "This network is not available, please update." }))), jsxs("div", Object.assign({ className: 'network-not-supported__content-container' }, { children: [jsx("div", Object.assign({ className: 'network-not-supported__img-container' }, { children: ((_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _a === void 0 ? void 0 : _a.avatar) ? (jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx("img", { src: (_b = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _b === void 0 ? void 0 : _b.avatar, alt: 'user ens avatar', className: 'network-not-supported__img' }) }))) : (jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx(WalletIcon, { walletName: walletConnector.name, style: { height: pixelToRem(64), width: pixelToRem(64) } }) }))) })), jsx(UserAddress, { userProfile: userProfile }), jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx(NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, showNetworkName: true, buttonClassName: 'network-not-supported__network-picker-button', mainClassName: 'network-not-supported__network-picker' }) })), jsxs("div", Object.assign({ className: 'network-not-supported__welcome-container' }, { children: [jsx(Typography, Object.assign({ variant: 'title', color: 'primary', className: 'network-not-supported__welcome-title' }, { children: "Update Network" })), jsx(Typography, Object.assign({ variant: 'body_normal', weight: 'regular', color: 'secondary' }, { children: "Your wallet is not connected to a supported network. Please update before continuing." })), jsx(Button, Object.assign({ type: 'submit', buttonVariant: 'primary', expanded: true, buttonRounded: 'default', buttonPadding: 'large', disabled: !_isSupportedNetwork, onClick: () => onboardingOnlyJwt && updateUserProfileByJWT(onboardingOnlyJwt), buttonClassName: 'network-not-supported__continue' }, { children: "Continue" })), jsx(TextButton, Object.assign({ className: 'network-not-supported__log-out', onClick: () => handleLogOut() }, { children: "Log out" }))] }))] }))] })));
54
+ return (jsxs("div", Object.assign({ className: 'network-not-supported', "data-testid": 'network-not-supported' }, { children: [onboardingImageUrl && (jsx("img", { className: 'network-not-supported__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsx(ErrorContainer, Object.assign({ withIcon: false, className: 'network-not-supported__error--not-supported' }, { children: "This network is not available, please update." }))), jsxs("div", Object.assign({ className: 'network-not-supported__content-container' }, { children: [jsx("div", Object.assign({ className: 'network-not-supported__img-container' }, { children: ((_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _a === void 0 ? void 0 : _a.avatar) ? (jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx("img", { src: (_b = userProfile === null || userProfile === void 0 ? void 0 : userProfile.ens) === null || _b === void 0 ? void 0 : _b.avatar, alt: 'user ens avatar', className: 'network-not-supported__img' }) }))) : (jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx(WalletIcon, { walletName: walletConnector.name, style: { height: pixelToRem(64), width: pixelToRem(64) } }) }))) })), jsx(UserAddress, { userProfile: userProfile }), jsx("div", Object.assign({ className: 'network-not-supported__network-container' }, { children: jsx(NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, showNetworkName: true, buttonClassName: 'network-not-supported__network-picker-button', mainClassName: 'network-not-supported__network-picker' }) })), jsxs("div", Object.assign({ className: 'network-not-supported__welcome-container' }, { children: [jsx(Typography, Object.assign({ variant: 'title', color: 'primary', className: 'network-not-supported__welcome-title' }, { children: "Update Network" })), jsx(Typography, Object.assign({ variant: 'body_normal', weight: 'regular', color: 'secondary' }, { children: "Your wallet is not connected to a supported network. Please update before continuing." })), jsx(Button, Object.assign({ type: 'submit', buttonVariant: 'primary', expanded: true, buttonRounded: 'default', buttonPadding: 'large', disabled: !_isSupportedNetwork, onClick: onSubmit, buttonClassName: 'network-not-supported__continue' }, { children: "Continue" })), jsx(TextButton, Object.assign({ className: 'network-not-supported__log-out', onClick: () => handleLogOut() }, { children: "Log out" }))] }))] }))] })));
49
55
  };
50
56
 
51
57
  export { NetworkNotSupported };
@@ -37,7 +37,7 @@ var useUpdateUserProfileByJWTCallback = require('../../utils/hooks/useUpdateUser
37
37
  // as the wallet does not support programmatic network change.
38
38
  const NetworkNotSupportedSwitchManual = () => {
39
39
  var _a, _b;
40
- const { user, network, onboardingOnlyJwt, selectedWalletConnector: walletConnector, } = useInternalDynamicContext.useInternalDynamicContext();
40
+ const { user, network, onboardingOnlyJwt, selectedWalletConnector: walletConnector, setShowAuthFlow, } = useInternalDynamicContext.useInternalDynamicContext();
41
41
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
42
42
  // Listen for network changes
43
43
  React.useEffect(() => {
@@ -52,6 +52,7 @@ const NetworkNotSupportedSwitchManual = () => {
52
52
  // The user had an incorrect network at the time of authorization. We finish the user's authorization.
53
53
  if (onboardingOnlyJwt) {
54
54
  updateUserProfileByJWT(onboardingOnlyJwt);
55
+ setShowAuthFlow(false);
55
56
  }
56
57
  }
57
58
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -33,7 +33,7 @@ import { useUpdateUserProfileByJWTCallback } from '../../utils/hooks/useUpdateUs
33
33
  // as the wallet does not support programmatic network change.
34
34
  const NetworkNotSupportedSwitchManual = () => {
35
35
  var _a, _b;
36
- const { user, network, onboardingOnlyJwt, selectedWalletConnector: walletConnector, } = useInternalDynamicContext();
36
+ const { user, network, onboardingOnlyJwt, selectedWalletConnector: walletConnector, setShowAuthFlow, } = useInternalDynamicContext();
37
37
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
38
38
  // Listen for network changes
39
39
  useEffect(() => {
@@ -48,6 +48,7 @@ const NetworkNotSupportedSwitchManual = () => {
48
48
  // The user had an incorrect network at the time of authorization. We finish the user's authorization.
49
49
  if (onboardingOnlyJwt) {
50
50
  updateUserProfileByJWT(onboardingOnlyJwt);
51
+ setShowAuthFlow(false);
51
52
  }
52
53
  }
53
54
  // eslint-disable-next-line react-hooks/exhaustive-deps