@dynamic-labs/sdk-react-core 1.1.0-alpha.4 → 1.1.0-alpha.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +10 -10
  5. package/src/index.cjs +14 -0
  6. package/src/index.d.ts +1 -1
  7. package/src/index.js +7 -0
  8. package/src/lib/components/index.d.ts +1 -0
  9. package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
  10. package/src/lib/data/api.cjs +15 -0
  11. package/src/lib/data/api.d.ts +7 -1
  12. package/src/lib/data/api.js +15 -1
  13. package/src/lib/events/dynamicEvents.d.ts +2 -0
  14. package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.cjs +1 -0
  15. package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.js +2 -1
  16. package/src/lib/locale/en/translation.cjs +71 -1
  17. package/src/lib/locale/en/translation.d.ts +70 -0
  18. package/src/lib/locale/en/translation.js +71 -1
  19. package/src/lib/shared/assets/alt-embedded-wallet.cjs +54 -0
  20. package/src/lib/shared/assets/alt-embedded-wallet.js +30 -0
  21. package/src/lib/shared/assets/export-embedded-hero.cjs +90 -0
  22. package/src/lib/shared/assets/export-embedded-hero.js +66 -0
  23. package/src/lib/shared/assets/eye-off-icon.cjs +53 -0
  24. package/src/lib/shared/assets/eye-off-icon.js +29 -0
  25. package/src/lib/shared/assets/face-id.cjs +53 -0
  26. package/src/lib/shared/assets/face-id.js +29 -0
  27. package/src/lib/shared/assets/index.d.ts +6 -0
  28. package/src/lib/shared/assets/lock.cjs +54 -0
  29. package/src/lib/shared/assets/lock.js +30 -0
  30. package/src/lib/shared/assets/wallet-v2.cjs +53 -0
  31. package/src/lib/shared/assets/wallet-v2.js +29 -0
  32. package/src/lib/styles/index.shadow.cjs +1 -1
  33. package/src/lib/styles/index.shadow.js +1 -1
  34. package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.cjs +28 -1
  35. package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.js +28 -1
  36. package/src/lib/utils/hooks/index.d.ts +1 -0
  37. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
  38. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
  39. package/src/lib/utils/hooks/useEmbeddedReveal/index.d.ts +1 -0
  40. package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.cjs +60 -0
  41. package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.d.ts +4 -0
  42. package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.js +56 -0
  43. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +3 -0
  44. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +3 -0
  45. package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.cjs +2 -27
  46. package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.js +2 -27
  47. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +20 -14
  48. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +20 -14
  49. package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs +26 -4
  50. package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js +26 -4
  51. package/src/lib/views/EmailVerification/EmailVerification.cjs +34 -23
  52. package/src/lib/views/EmailVerification/EmailVerification.js +34 -23
  53. package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +158 -0
  54. package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.d.ts +2 -0
  55. package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +154 -0
  56. package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/index.d.ts +1 -0
  57. package/src/lib/views/EmbeddedReveal/constants.cjs +9 -0
  58. package/src/lib/views/EmbeddedReveal/constants.d.ts +2 -0
  59. package/src/lib/views/EmbeddedReveal/constants.js +4 -0
  60. package/src/lib/views/EmbeddedReveal/index.d.ts +1 -0
  61. package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/index.d.ts +1 -0
  62. package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs +114 -0
  63. package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.d.ts +15 -0
  64. package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +108 -0
  65. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +2 -2
  66. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +2 -2
  67. package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.cjs +2 -2
  68. package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.d.ts +2 -2
  69. package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +2 -2
  70. package/src/lib/views/viewToComponentMap.cjs +2 -0
  71. package/src/lib/views/viewToComponentMap.js +2 -0
  72. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +2 -2
  73. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +2 -2
  74. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.cjs +2 -0
  75. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.js +2 -0
  76. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.cjs +2 -0
  77. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.d.ts +3 -1
  78. package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.js +2 -1
  79. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.cjs +4 -4
  80. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.js +4 -4
  81. package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.cjs +93 -0
  82. package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.d.ts +2 -0
  83. package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.js +89 -0
  84. package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/index.d.ts +1 -0
  85. package/src/lib/widgets/DynamicWidget/views/index.d.ts +1 -0
@@ -0,0 +1 @@
1
+ export { useEmbeddedReveal } from './useEmbeddedReveal';
@@ -0,0 +1,60 @@
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
+ var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
8
+ var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
9
+ require('@dynamic-labs/sdk-api');
10
+ require('../../../shared/logger.cjs');
11
+ require('@dynamic-labs/iconic');
12
+ require('@dynamic-labs/wallet-connector-core');
13
+ require('react/jsx-runtime');
14
+ require('@dynamic-labs/wallet-book');
15
+ require('../../constants/colors.cjs');
16
+ require('../../../shared/utils/classes/storage/localStorage.cjs');
17
+ require('viem');
18
+ require('@dynamic-labs/utils');
19
+ require('../../../shared/consts/index.cjs');
20
+ require('@dynamic-labs/multi-wallet');
21
+ var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
22
+ var isTurnkeyEnabled = require('../../functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
23
+ var useEmbeddedWallet = require('../useEmbeddedWallet/useEmbeddedWallet.cjs');
24
+ var dynamicEvents = require('../../../events/dynamicEvents.cjs');
25
+
26
+ // Hook exposed to customers and used internally to trigger embedded reveal
27
+ const useEmbeddedReveal = () => {
28
+ const { projectSettings, internalSetShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
29
+ const { userHasEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
30
+ const { setView } = ViewContext.useViewContext();
31
+ const initExportProcess = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
32
+ const jwt = getAuthToken.getAuthToken();
33
+ if (!jwt) {
34
+ throw new Error('User is not logged in');
35
+ }
36
+ if (!isTurnkeyEnabled.isTurnkeyEnabled(projectSettings)) {
37
+ throw new Error('Passkey embedded wallet is not enabled. Go to the dashboard and make sure to have both Turnkey/Passkey Embedded wallets and at least one EVM network enabled. Also, check if EthereumWalletConnectors is in the DynamicContextProvider > settings > walletConnectors.');
38
+ }
39
+ if (!userHasEmbeddedWallet()) {
40
+ throw new Error('Passkey embedded wallet not found');
41
+ }
42
+ internalSetShowAuthFlow(true);
43
+ setView('embedded-reveal-view');
44
+ return new Promise((resolve, reject) => {
45
+ dynamicEvents.dynamicEvents.once('embeddedWalletRevealCompleted', (wallet) => resolve(wallet));
46
+ dynamicEvents.dynamicEvents.once('embeddedWalletRevealFailed', (error) => reject(error));
47
+ });
48
+ }), [
49
+ dynamicEvents.dynamicEvents,
50
+ internalSetShowAuthFlow,
51
+ projectSettings,
52
+ setView,
53
+ userHasEmbeddedWallet,
54
+ ]);
55
+ return {
56
+ initExportProcess,
57
+ };
58
+ };
59
+
60
+ exports.useEmbeddedReveal = useEmbeddedReveal;
@@ -0,0 +1,4 @@
1
+ import { Wallet } from '../../../shared';
2
+ export declare const useEmbeddedReveal: () => {
3
+ readonly initExportProcess: () => Promise<Wallet>;
4
+ };
@@ -0,0 +1,56 @@
1
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
2
+ import { useCallback } from 'react';
3
+ import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
4
+ import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
5
+ import '@dynamic-labs/sdk-api';
6
+ import '../../../shared/logger.js';
7
+ import '@dynamic-labs/iconic';
8
+ import '@dynamic-labs/wallet-connector-core';
9
+ import 'react/jsx-runtime';
10
+ import '@dynamic-labs/wallet-book';
11
+ import '../../constants/colors.js';
12
+ import '../../../shared/utils/classes/storage/localStorage.js';
13
+ import 'viem';
14
+ import '@dynamic-labs/utils';
15
+ import '../../../shared/consts/index.js';
16
+ import '@dynamic-labs/multi-wallet';
17
+ import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
18
+ import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
19
+ import { useEmbeddedWallet } from '../useEmbeddedWallet/useEmbeddedWallet.js';
20
+ import { dynamicEvents } from '../../../events/dynamicEvents.js';
21
+
22
+ // Hook exposed to customers and used internally to trigger embedded reveal
23
+ const useEmbeddedReveal = () => {
24
+ const { projectSettings, internalSetShowAuthFlow } = useInternalDynamicContext();
25
+ const { userHasEmbeddedWallet } = useEmbeddedWallet();
26
+ const { setView } = useViewContext();
27
+ const initExportProcess = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
28
+ const jwt = getAuthToken();
29
+ if (!jwt) {
30
+ throw new Error('User is not logged in');
31
+ }
32
+ if (!isTurnkeyEnabled(projectSettings)) {
33
+ throw new Error('Passkey embedded wallet is not enabled. Go to the dashboard and make sure to have both Turnkey/Passkey Embedded wallets and at least one EVM network enabled. Also, check if EthereumWalletConnectors is in the DynamicContextProvider > settings > walletConnectors.');
34
+ }
35
+ if (!userHasEmbeddedWallet()) {
36
+ throw new Error('Passkey embedded wallet not found');
37
+ }
38
+ internalSetShowAuthFlow(true);
39
+ setView('embedded-reveal-view');
40
+ return new Promise((resolve, reject) => {
41
+ dynamicEvents.once('embeddedWalletRevealCompleted', (wallet) => resolve(wallet));
42
+ dynamicEvents.once('embeddedWalletRevealFailed', (error) => reject(error));
43
+ });
44
+ }), [
45
+ dynamicEvents,
46
+ internalSetShowAuthFlow,
47
+ projectSettings,
48
+ setView,
49
+ userHasEmbeddedWallet,
50
+ ]);
51
+ return {
52
+ initExportProcess,
53
+ };
54
+ };
55
+
56
+ export { useEmbeddedReveal };
@@ -28,12 +28,14 @@ var isTurnkeyEnabled = require('../../functions/isTurnkeyEnabled/isTurnkeyEnable
28
28
  var smartWallet = require('../useWalletConnectors/utils/smartWallet/smartWallet.cjs');
29
29
  var useCreateDynamicEmbeddedWalletMutation = require('../useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs');
30
30
  var dynamicEvents = require('../../../events/dynamicEvents.cjs');
31
+ var useCreateUserProfileByJWTCallback = require('../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.cjs');
31
32
 
32
33
  // Hook exposed to customers and used internally to trigger embedded wallet creation
33
34
  const useEmbeddedWallet = () => {
34
35
  const { projectSettings, onboardingOnlyJwt, setPrimaryWalletId, walletConnectorOptions, internalSetShowAuthFlow, primaryWallet, environmentId, } = useInternalDynamicContext.useInternalDynamicContext();
35
36
  const { setView } = ViewContext.useViewContext();
36
37
  const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation.useCreateDynamicEmbeddedWalletMutation();
38
+ const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback.useCreateUserProfileByJWTCallback();
37
39
  const userHasEmbeddedWallet = () => {
38
40
  var _a;
39
41
  const jwt = (_a = getAuthToken.getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
@@ -85,6 +87,7 @@ const useEmbeddedWallet = () => {
85
87
  // if user already has embedded wallet, set it as primary wallet
86
88
  if (decodedJwt) {
87
89
  (_a = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector) === null || _a === void 0 ? void 0 : _a.setVerifiedCredentials(decodedJwt.verifiedCredentials);
90
+ yield createUserProfileByJWT(jwt);
88
91
  const smartWallet$1 = smartWallet.findSmartWallet(embeddedWalletVerifiedCredential, decodedJwt.verifiedCredentials);
89
92
  if (smartWallet$1) {
90
93
  yield smartWallet.initializeSmartWallet({
@@ -24,12 +24,14 @@ import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnab
24
24
  import { findSmartWallet, initializeSmartWallet } from '../useWalletConnectors/utils/smartWallet/smartWallet.js';
25
25
  import { useCreateDynamicEmbeddedWalletMutation } from '../useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js';
26
26
  import { dynamicEvents } from '../../../events/dynamicEvents.js';
27
+ import { useCreateUserProfileByJWTCallback } from '../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.js';
27
28
 
28
29
  // Hook exposed to customers and used internally to trigger embedded wallet creation
29
30
  const useEmbeddedWallet = () => {
30
31
  const { projectSettings, onboardingOnlyJwt, setPrimaryWalletId, walletConnectorOptions, internalSetShowAuthFlow, primaryWallet, environmentId, } = useInternalDynamicContext();
31
32
  const { setView } = useViewContext();
32
33
  const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation();
34
+ const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback();
33
35
  const userHasEmbeddedWallet = () => {
34
36
  var _a;
35
37
  const jwt = (_a = getAuthToken()) !== null && _a !== void 0 ? _a : onboardingOnlyJwt;
@@ -81,6 +83,7 @@ const useEmbeddedWallet = () => {
81
83
  // if user already has embedded wallet, set it as primary wallet
82
84
  if (decodedJwt) {
83
85
  (_a = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector) === null || _a === void 0 ? void 0 : _a.setVerifiedCredentials(decodedJwt.verifiedCredentials);
86
+ yield createUserProfileByJWT(jwt);
84
87
  const smartWallet = findSmartWallet(embeddedWalletVerifiedCredential, decodedJwt.verifiedCredentials);
85
88
  if (smartWallet) {
86
89
  yield initializeSmartWallet({
@@ -3,37 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
6
- require('@dynamic-labs/sdk-api');
7
- require('../../../shared/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
- require('../../constants/colors.cjs');
15
- require('../../../shared/utils/classes/storage/localStorage.cjs');
16
- require('viem');
17
- require('@dynamic-labs/utils');
18
- require('../../../shared/consts/index.cjs');
19
- require('@dynamic-labs/multi-wallet');
20
- var isTurnkeyEnabled = require('../../functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
21
6
 
22
7
  const useIsLoggedIn = () => {
23
- const { user, primaryWallet, authMode, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
24
- const isTurnkeyProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
8
+ const { user, primaryWallet, authMode } = useInternalDynamicContext.useInternalDynamicContext();
25
9
  // a user is set even when on connect-only mode if signing in with social,
26
10
  // but it won't have a primaryWallet in this case
27
- const isLoggedIn = Boolean(user) || (authMode === 'connect-only' && Boolean(primaryWallet));
28
- // if turnkey is enabled we need to check if the user that is logged/connected
29
- // has a primaryWallet to not show the widget without secure
30
- if (isTurnkeyProviderEnabled &&
31
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.automaticEmbeddedWalletCreation) &&
32
- ((projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWalletSecurityMethods) || []).length === 0) {
33
- return Boolean(primaryWallet && isLoggedIn);
34
- }
35
- // return isLoggedIn;
36
- return isLoggedIn;
11
+ return (Boolean(user) || (authMode === 'connect-only' && Boolean(primaryWallet)));
37
12
  };
38
13
 
39
14
  exports.useIsLoggedIn = useIsLoggedIn;
@@ -1,35 +1,10 @@
1
1
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
2
- import '@dynamic-labs/sdk-api';
3
- import '../../../shared/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 '../../constants/colors.js';
11
- import '../../../shared/utils/classes/storage/localStorage.js';
12
- import 'viem';
13
- import '@dynamic-labs/utils';
14
- import '../../../shared/consts/index.js';
15
- import '@dynamic-labs/multi-wallet';
16
- import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
17
2
 
18
3
  const useIsLoggedIn = () => {
19
- const { user, primaryWallet, authMode, projectSettings } = useInternalDynamicContext();
20
- const isTurnkeyProviderEnabled = isTurnkeyEnabled(projectSettings);
4
+ const { user, primaryWallet, authMode } = useInternalDynamicContext();
21
5
  // a user is set even when on connect-only mode if signing in with social,
22
6
  // but it won't have a primaryWallet in this case
23
- const isLoggedIn = Boolean(user) || (authMode === 'connect-only' && Boolean(primaryWallet));
24
- // if turnkey is enabled we need to check if the user that is logged/connected
25
- // has a primaryWallet to not show the widget without secure
26
- if (isTurnkeyProviderEnabled &&
27
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.automaticEmbeddedWalletCreation) &&
28
- ((projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWalletSecurityMethods) || []).length === 0) {
29
- return Boolean(primaryWallet && isLoggedIn);
30
- }
31
- // return isLoggedIn;
32
- return isLoggedIn;
7
+ return (Boolean(user) || (authMode === 'connect-only' && Boolean(primaryWallet)));
33
8
  };
34
9
 
35
10
  export { useIsLoggedIn };
@@ -27,7 +27,9 @@ require('@dynamic-labs/multi-wallet');
27
27
  var getAuthToken = require('../../functions/getAuthToken/getAuthToken.cjs');
28
28
  var getOauthLoginUrl = require('../../functions/getOauthLoginUrl/getOauthLoginUrl.cjs');
29
29
  var getProviderByType = require('../../functions/getProviderByType/getProviderByType.cjs');
30
+ var isTurnkeyEnabled = require('../../functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
30
31
  var randomString = require('../../functions/randomString/randomString.cjs');
32
+ var index = require('../../functions/storeAuthToken/index.cjs');
31
33
  var stringifyURIQuery = require('../../functions/stringifyURIQuery/stringifyURIQuery.cjs');
32
34
  var useCreateUserProfileByJWTCallback = require('../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.cjs');
33
35
  var ErrorContext = require('../../../context/ErrorContext/ErrorContext.cjs');
@@ -58,6 +60,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
58
60
  const { createEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
59
61
  const [isProcessing, setIsProcessing] = React.useState(false);
60
62
  const [error, setError] = React.useState();
63
+ const isTurnkeyProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
61
64
  const providersWaitingOauthMessage = React.useRef({});
62
65
  const authWindowInterval = React.useRef();
63
66
  const shouldPool = React.useRef(false);
@@ -147,22 +150,25 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
147
150
  return;
148
151
  }
149
152
  setCallback('authSuccess');
150
- yield createUserProfileByJWT(jwt);
151
- if (!((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation)) {
152
- setShowAuthFlow(false);
153
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
153
+ if (isTurnkeyProviderEnabled &&
154
+ ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation)) {
155
+ try {
156
+ index.storeAuthToken(jwt);
157
+ // this function will check turnkey wallet enabled and create wallet if needed
158
+ // if not enabled, it will throw an error.
159
+ yield createEmbeddedWallet();
160
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
161
+ }
162
+ catch (e) {
163
+ yield createUserProfileByJWT(jwt);
164
+ setShowAuthFlow(false);
165
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
166
+ }
154
167
  return;
155
168
  }
156
- try {
157
- // this function will check turnkey wallet enabled and create wallet if needed
158
- // if not enabled, it will throw an error.
159
- yield createEmbeddedWallet();
160
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
161
- }
162
- catch (e) {
163
- setShowAuthFlow(false);
164
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
165
- }
169
+ yield createUserProfileByJWT(jwt);
170
+ setShowAuthFlow(false);
171
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
166
172
  }
167
173
  catch (error) {
168
174
  if (error instanceof utils.NoAccessError) {
@@ -23,7 +23,9 @@ import '@dynamic-labs/multi-wallet';
23
23
  import { getAuthToken } from '../../functions/getAuthToken/getAuthToken.js';
24
24
  import { getOauthLoginUrl } from '../../functions/getOauthLoginUrl/getOauthLoginUrl.js';
25
25
  import { getProviderByType } from '../../functions/getProviderByType/getProviderByType.js';
26
+ import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
26
27
  import { randomString } from '../../functions/randomString/randomString.js';
28
+ import { storeAuthToken } from '../../functions/storeAuthToken/index.js';
27
29
  import { stringifyURIQuery } from '../../functions/stringifyURIQuery/stringifyURIQuery.js';
28
30
  import { useCreateUserProfileByJWTCallback } from '../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.js';
29
31
  import { useErrorContext } from '../../../context/ErrorContext/ErrorContext.js';
@@ -54,6 +56,7 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
54
56
  const { createEmbeddedWallet } = useEmbeddedWallet();
55
57
  const [isProcessing, setIsProcessing] = useState(false);
56
58
  const [error, setError] = useState();
59
+ const isTurnkeyProviderEnabled = isTurnkeyEnabled(projectSettings);
57
60
  const providersWaitingOauthMessage = useRef({});
58
61
  const authWindowInterval = useRef();
59
62
  const shouldPool = useRef(false);
@@ -143,22 +146,25 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
143
146
  return;
144
147
  }
145
148
  setCallback('authSuccess');
146
- yield createUserProfileByJWT(jwt);
147
- if (!((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation)) {
148
- setShowAuthFlow(false);
149
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
149
+ if (isTurnkeyProviderEnabled &&
150
+ ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation)) {
151
+ try {
152
+ storeAuthToken(jwt);
153
+ // this function will check turnkey wallet enabled and create wallet if needed
154
+ // if not enabled, it will throw an error.
155
+ yield createEmbeddedWallet();
156
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
157
+ }
158
+ catch (e) {
159
+ yield createUserProfileByJWT(jwt);
160
+ setShowAuthFlow(false);
161
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
162
+ }
150
163
  return;
151
164
  }
152
- try {
153
- // this function will check turnkey wallet enabled and create wallet if needed
154
- // if not enabled, it will throw an error.
155
- yield createEmbeddedWallet();
156
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
157
- }
158
- catch (e) {
159
- setShowAuthFlow(false);
160
- onSettled === null || onSettled === void 0 ? void 0 : onSettled();
161
- }
165
+ yield createUserProfileByJWT(jwt);
166
+ setShowAuthFlow(false);
167
+ onSettled === null || onSettled === void 0 ? void 0 : onSettled();
162
168
  }
163
169
  catch (error) {
164
170
  if (error instanceof NoAccessError) {
@@ -25,6 +25,8 @@ require('../../../../context/CaptchaContext/CaptchaContext.cjs');
25
25
  require('../../../../context/ErrorContext/ErrorContext.cjs');
26
26
  require('@dynamic-labs/multi-wallet');
27
27
  require('@dynamic-labs/sdk-api');
28
+ var isTurnkeyEnabled = require('../../../functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
29
+ var index = require('../../../functions/storeAuthToken/index.cjs');
28
30
  require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
29
31
  require('../../../../context/AccountExistsContext/AccountExistsContext.cjs');
30
32
  var useEmailVerificationRequest = require('../../authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.cjs');
@@ -54,13 +56,14 @@ const userFieldsSchema = yup.object().shape({
54
56
  username: yup.string(),
55
57
  });
56
58
  const useUpdateUser = (validationSchemaStripUnknown) => {
57
- const { authToken, onboardingOnlyJwt, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
59
+ const { authToken, onboardingOnlyJwt, environmentId, projectSettings, primaryWallet, } = useInternalDynamicContext.useInternalDynamicContext();
60
+ const isTurnkeyProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
58
61
  const jwtToken = onboardingOnlyJwt || authToken;
59
62
  const { setVerificationUUID, setEmail } = EmailVerificationContext.useEmailVerificationContext();
60
63
  const { verifyEmail } = useEmailVerificationRequest.useEmailVerificationRequest();
61
64
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback.useUpdateUserProfileByJWTCallback();
62
65
  return React.useCallback((userFields, userEnvironmentId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
63
- var _a, _b, _c;
66
+ var _a, _b, _c, _d;
64
67
  // `stripUnknown: true` will automatically strip out any values in the metadata object
65
68
  // so we need to pull out the metadata object here and then re-add it after stripping unknown fields
66
69
  const { metadata } = userFields;
@@ -72,6 +75,25 @@ const useUpdateUser = (validationSchemaStripUnknown) => {
72
75
  const decodedJwt = decodeJwt.decodeJwt(updateUserProfileResponse.jwt);
73
76
  const missingFields = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.missingFields) !== null && _a !== void 0 ? _a : [];
74
77
  const _isEmailVerificationRequired = isEmailVerificationRequired.isEmailVerificationRequired(updateUserProfileResponse);
78
+ // This is to handle properly the embedded wallet creation.
79
+ // In that case we shouldn't create a user. Only store the JWT in the localstorage
80
+ // The user will be created after generating the wallet.
81
+ // This should be called only when:
82
+ // Turnkey is enabled
83
+ // automaticEmbeddedWalletCreation is set to true
84
+ // there is no emailVerificationRequired -> it's already verified
85
+ // there is no primaryWallet -> it means that the user is already logged in
86
+ if (isTurnkeyProviderEnabled &&
87
+ ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation) &&
88
+ !_isEmailVerificationRequired &&
89
+ !primaryWallet) {
90
+ index.storeAuthToken(updateUserProfileResponse.jwt);
91
+ return {
92
+ isEmailVerificationRequired: false,
93
+ missingFields,
94
+ updateUserProfileResponse,
95
+ };
96
+ }
75
97
  if (!_isEmailVerificationRequired) {
76
98
  // If email verification is not needed then we can update the user profile immediately.
77
99
  yield updateUserProfileByJWT(updateUserProfileResponse.jwt);
@@ -82,8 +104,8 @@ const useUpdateUser = (validationSchemaStripUnknown) => {
82
104
  };
83
105
  }
84
106
  // We update EmailContext to use this information in the Email Verification view
85
- setEmail((_b = updateUserProfileResponse.emailVerification) === null || _b === void 0 ? void 0 : _b.email);
86
- setVerificationUUID((_c = updateUserProfileResponse.emailVerification) === null || _c === void 0 ? void 0 : _c.verificationUUID);
107
+ setEmail((_c = updateUserProfileResponse.emailVerification) === null || _c === void 0 ? void 0 : _c.email);
108
+ setVerificationUUID((_d = updateUserProfileResponse.emailVerification) === null || _d === void 0 ? void 0 : _d.verificationUUID);
87
109
  // DYN-2046 - Customers have the opportunity to programmatically use our email verification and profile editing.
88
110
  // VerifyEmailFN was scoped to bypass the problem with memoization of the state at the beginning of Promise.
89
111
  // setEmail and setVerificationUUID in the above lines will are not visible in this promise.
@@ -21,6 +21,8 @@ import '../../../../context/CaptchaContext/CaptchaContext.js';
21
21
  import '../../../../context/ErrorContext/ErrorContext.js';
22
22
  import '@dynamic-labs/multi-wallet';
23
23
  import '@dynamic-labs/sdk-api';
24
+ import { isTurnkeyEnabled } from '../../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
25
+ import { storeAuthToken } from '../../../functions/storeAuthToken/index.js';
24
26
  import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
25
27
  import '../../../../context/AccountExistsContext/AccountExistsContext.js';
26
28
  import { useEmailVerificationRequest } from '../../authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.js';
@@ -50,13 +52,14 @@ const userFieldsSchema = object().shape({
50
52
  username: string(),
51
53
  });
52
54
  const useUpdateUser = (validationSchemaStripUnknown) => {
53
- const { authToken, onboardingOnlyJwt, environmentId } = useInternalDynamicContext();
55
+ const { authToken, onboardingOnlyJwt, environmentId, projectSettings, primaryWallet, } = useInternalDynamicContext();
56
+ const isTurnkeyProviderEnabled = isTurnkeyEnabled(projectSettings);
54
57
  const jwtToken = onboardingOnlyJwt || authToken;
55
58
  const { setVerificationUUID, setEmail } = useEmailVerificationContext();
56
59
  const { verifyEmail } = useEmailVerificationRequest();
57
60
  const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
58
61
  return useCallback((userFields, userEnvironmentId) => __awaiter(void 0, void 0, void 0, function* () {
59
- var _a, _b, _c;
62
+ var _a, _b, _c, _d;
60
63
  // `stripUnknown: true` will automatically strip out any values in the metadata object
61
64
  // so we need to pull out the metadata object here and then re-add it after stripping unknown fields
62
65
  const { metadata } = userFields;
@@ -68,6 +71,25 @@ const useUpdateUser = (validationSchemaStripUnknown) => {
68
71
  const decodedJwt = decodeJwt(updateUserProfileResponse.jwt);
69
72
  const missingFields = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.missingFields) !== null && _a !== void 0 ? _a : [];
70
73
  const _isEmailVerificationRequired = isEmailVerificationRequired(updateUserProfileResponse);
74
+ // This is to handle properly the embedded wallet creation.
75
+ // In that case we shouldn't create a user. Only store the JWT in the localstorage
76
+ // The user will be created after generating the wallet.
77
+ // This should be called only when:
78
+ // Turnkey is enabled
79
+ // automaticEmbeddedWalletCreation is set to true
80
+ // there is no emailVerificationRequired -> it's already verified
81
+ // there is no primaryWallet -> it means that the user is already logged in
82
+ if (isTurnkeyProviderEnabled &&
83
+ ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation) &&
84
+ !_isEmailVerificationRequired &&
85
+ !primaryWallet) {
86
+ storeAuthToken(updateUserProfileResponse.jwt);
87
+ return {
88
+ isEmailVerificationRequired: false,
89
+ missingFields,
90
+ updateUserProfileResponse,
91
+ };
92
+ }
71
93
  if (!_isEmailVerificationRequired) {
72
94
  // If email verification is not needed then we can update the user profile immediately.
73
95
  yield updateUserProfileByJWT(updateUserProfileResponse.jwt);
@@ -78,8 +100,8 @@ const useUpdateUser = (validationSchemaStripUnknown) => {
78
100
  };
79
101
  }
80
102
  // We update EmailContext to use this information in the Email Verification view
81
- setEmail((_b = updateUserProfileResponse.emailVerification) === null || _b === void 0 ? void 0 : _b.email);
82
- setVerificationUUID((_c = updateUserProfileResponse.emailVerification) === null || _c === void 0 ? void 0 : _c.verificationUUID);
103
+ setEmail((_c = updateUserProfileResponse.emailVerification) === null || _c === void 0 ? void 0 : _c.email);
104
+ setVerificationUUID((_d = updateUserProfileResponse.emailVerification) === null || _d === void 0 ? void 0 : _d.verificationUUID);
83
105
  // DYN-2046 - Customers have the opportunity to programmatically use our email verification and profile editing.
84
106
  // VerifyEmailFN was scoped to bypass the problem with memoization of the state at the beginning of Promise.
85
107
  // setEmail and setVerificationUUID in the above lines will are not visible in this promise.
@@ -28,6 +28,8 @@ var useEffectOnce = require('../../shared/utils/hooks/useEffectOnce/useEffectOnc
28
28
  require('../../shared/consts/index.cjs');
29
29
  require('@dynamic-labs/multi-wallet');
30
30
  require('@dynamic-labs/sdk-api');
31
+ var isTurnkeyEnabled = require('../../utils/functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
32
+ var index = require('../../utils/functions/storeAuthToken/index.cjs');
31
33
  require('../../context/AccessDeniedContext/AccessDeniedContext.cjs');
32
34
  var AccountExistsContext = require('../../context/AccountExistsContext/AccountExistsContext.cjs');
33
35
  var api = require('../../data/api.cjs');
@@ -101,6 +103,7 @@ const EmailVerification = () => {
101
103
  const { loading, setLoading } = LoadingContext.useLoadingContext();
102
104
  const { t } = reactI18next.useTranslation();
103
105
  const { createEmbeddedWallet } = useEmbeddedWallet.useEmbeddedWallet();
106
+ const isTurnkeyProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
104
107
  const { remainingSeconds, startCountdown } = useCountdown.useCountdown({
105
108
  callback: () => setRetried(false),
106
109
  seconds: SECONDS_TO_RETRY,
@@ -130,7 +133,7 @@ const EmailVerification = () => {
130
133
  return;
131
134
  }
132
135
  try {
133
- const { nextView } = yield verifyEmail(verificationToken, verificationUUID);
136
+ const { nextView, jwt } = yield verifyEmail(verificationToken, verificationUUID);
134
137
  if (onboardingOnlyJwt) {
135
138
  setOnboardingOnlyJwt(undefined);
136
139
  setCallback('authSuccess');
@@ -139,18 +142,20 @@ const EmailVerification = () => {
139
142
  if (nextView === 'verified-and-transferred') {
140
143
  setShowTransferMessage(true);
141
144
  }
142
- if (!((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation)) {
143
- setShowAuthFlow(false);
145
+ if (isTurnkeyProviderEnabled &&
146
+ ((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation)) {
147
+ try {
148
+ index.storeAuthToken(jwt);
149
+ // this function will check turnkey wallet enabled and create wallet if needed
150
+ // if not enabled, it will throw an error.
151
+ yield createEmbeddedWallet();
152
+ }
153
+ catch (e) {
154
+ setShowAuthFlow(false);
155
+ }
144
156
  return;
145
157
  }
146
- try {
147
- // this function will check turnkey wallet enabled and create wallet if needed
148
- // if not enabled, it will throw an error.
149
- yield createEmbeddedWallet();
150
- }
151
- catch (e) {
152
- setShowAuthFlow(false);
153
- }
158
+ setShowAuthFlow(false);
154
159
  }
155
160
  catch (error) {
156
161
  logger.logger.debug(error);
@@ -178,8 +183,8 @@ const EmailVerification = () => {
178
183
  (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.automaticEmbeddedWalletCreation,
179
184
  createEmbeddedWallet,
180
185
  setShowAuthFlow,
181
- setErrorMessage,
182
186
  setView,
187
+ isTurnkeyProviderEnabled,
183
188
  ]);
184
189
  const handleEmailLogin = React.useCallback((verificationToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
185
190
  var _d;
@@ -212,19 +217,24 @@ const EmailVerification = () => {
212
217
  setCallback('authSuccess');
213
218
  // this timeout is set to make sure that the user will see success message
214
219
  yield sleepToShowSuccessMessage();
215
- yield createUserProfileByJWT(jwt);
216
- if (!((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.automaticEmbeddedWalletCreation)) {
217
- setShowAuthFlow(false);
220
+ if (isTurnkeyProviderEnabled &&
221
+ ((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.automaticEmbeddedWalletCreation)) {
222
+ try {
223
+ // Store the auth token in local storage so it can be used during embedded wallet creation
224
+ index.storeAuthToken(jwt);
225
+ // this function will check turnkey wallet enabled and create wallet if needed
226
+ // if not enabled, it will throw an error.
227
+ yield createEmbeddedWallet();
228
+ }
229
+ catch (e) {
230
+ yield createUserProfileByJWT(jwt);
231
+ setShowAuthFlow(false);
232
+ }
218
233
  return;
219
234
  }
220
- try {
221
- // this function will check turnkey wallet enabled and create wallet if needed
222
- // if not enabled, it will throw an error.
223
- yield createEmbeddedWallet();
224
- }
225
- catch (e) {
226
- setShowAuthFlow(false);
227
- }
235
+ // If not creating embedded wallet automatically, create user profile
236
+ yield createUserProfileByJWT(jwt);
237
+ setShowAuthFlow(false);
228
238
  }
229
239
  catch (error) {
230
240
  if (error instanceof utils.NoAccessError) {
@@ -256,6 +266,7 @@ const EmailVerification = () => {
256
266
  setShowAuthFlow,
257
267
  setErrorMessage,
258
268
  setExistentAccountData,
269
+ isTurnkeyProviderEnabled,
259
270
  ]);
260
271
  const handleRetry = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
261
272
  try {