@dynamic-labs/sdk-react-core 1.1.0-alpha.3 → 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.
- package/CHANGELOG.md +17 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/index.cjs +16 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +8 -0
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/data/api.cjs +15 -0
- package/src/lib/data/api.d.ts +7 -1
- package/src/lib/data/api.js +16 -2
- package/src/lib/events/dynamicEvents.d.ts +2 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.cjs +1 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.js +2 -1
- package/src/lib/locale/en/translation.cjs +71 -1
- package/src/lib/locale/en/translation.d.ts +70 -0
- package/src/lib/locale/en/translation.js +71 -1
- package/src/lib/shared/assets/alt-embedded-wallet.cjs +54 -0
- package/src/lib/shared/assets/alt-embedded-wallet.js +30 -0
- package/src/lib/shared/assets/export-embedded-hero.cjs +90 -0
- package/src/lib/shared/assets/export-embedded-hero.js +66 -0
- package/src/lib/shared/assets/eye-off-icon.cjs +53 -0
- package/src/lib/shared/assets/eye-off-icon.js +29 -0
- package/src/lib/shared/assets/face-id.cjs +53 -0
- package/src/lib/shared/assets/face-id.js +29 -0
- package/src/lib/shared/assets/index.d.ts +6 -0
- package/src/lib/shared/assets/lock.cjs +54 -0
- package/src/lib/shared/assets/lock.js +30 -0
- package/src/lib/shared/assets/wallet-v2.cjs +53 -0
- package/src/lib/shared/assets/wallet-v2.js +29 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/index.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/index.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.cjs +8 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.js +4 -0
- package/src/lib/utils/functions/isProviderEnabled/isProviderEnabled.cjs +9 -1
- package/src/lib/utils/functions/isProviderEnabled/isProviderEnabled.js +9 -1
- package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.cjs +28 -1
- package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.js +28 -1
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +4 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +4 -1
- package/src/lib/utils/hooks/useConnectWithEmailOtp/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.cjs +150 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.d.ts +32 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.js +146 -0
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.cjs +3 -3
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.js +3 -3
- package/src/lib/utils/hooks/useEmbeddedReveal/index.d.ts +1 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.cjs +60 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.d.ts +4 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.js +56 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +3 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +3 -0
- package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.cjs +2 -27
- package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.js +2 -27
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +20 -14
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +20 -14
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs +26 -4
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js +26 -4
- package/src/lib/views/EmailVerification/EmailVerification.cjs +34 -23
- package/src/lib/views/EmailVerification/EmailVerification.js +34 -23
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +158 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.d.ts +2 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +154 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/constants.cjs +9 -0
- package/src/lib/views/EmbeddedReveal/constants.d.ts +2 -0
- package/src/lib/views/EmbeddedReveal/constants.js +4 -0
- package/src/lib/views/EmbeddedReveal/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs +114 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.d.ts +15 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +108 -0
- package/src/lib/views/LoginView/sections/EmailSignInSection/LoginEmailForm.cjs +2 -3
- package/src/lib/views/LoginView/sections/EmailSignInSection/LoginEmailForm.d.ts +0 -1
- package/src/lib/views/LoginView/sections/EmailSignInSection/LoginEmailForm.js +3 -3
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +2 -2
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.cjs +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.d.ts +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +2 -2
- package/src/lib/views/WalletList/WalletList.cjs +5 -8
- package/src/lib/views/WalletList/WalletList.js +5 -8
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +2 -2
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.cjs +2 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.js +2 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.cjs +2 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.d.ts +3 -1
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.js +2 -1
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.cjs +4 -4
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.js +4 -4
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.cjs +93 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.js +89 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/index.d.ts +1 -0
|
@@ -4,14 +4,31 @@ import { useInternalDynamicContext } from '../../../../context/DynamicContext/us
|
|
|
4
4
|
import { verifyEmail } from '../../../../data/api.js';
|
|
5
5
|
import { useUpdateUserProfileByJWTCallback } from '../../useUpdateUserProfileByJWTCallback/useUpdateUserProfileByJWTCallback.js';
|
|
6
6
|
import { useEmailVerificationContext } from '../../../../context/EmailVerificationContext/EmailVerificationContext.js';
|
|
7
|
+
import '@dynamic-labs/sdk-api';
|
|
8
|
+
import '../../../../shared/logger.js';
|
|
9
|
+
import '@dynamic-labs/iconic';
|
|
10
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
11
|
+
import 'react/jsx-runtime';
|
|
12
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
13
|
+
import '@dynamic-labs/wallet-book';
|
|
14
|
+
import '../../../constants/colors.js';
|
|
15
|
+
import '../../../../shared/utils/classes/storage/localStorage.js';
|
|
16
|
+
import 'viem';
|
|
17
|
+
import '@dynamic-labs/utils';
|
|
18
|
+
import '../../../../shared/consts/index.js';
|
|
19
|
+
import '@dynamic-labs/multi-wallet';
|
|
20
|
+
import { isTurnkeyEnabled } from '../../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
|
|
7
21
|
|
|
8
22
|
// Hook exposed to the public as a scoped function in useUserUpdateRequest result
|
|
9
23
|
const useEmailVerificationRequest = () => {
|
|
10
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
const { onboardingOnlyJwt, authToken, environmentId, projectSettings, primaryWallet, } = useInternalDynamicContext();
|
|
11
26
|
const jwtToken = onboardingOnlyJwt || authToken;
|
|
27
|
+
const isTurnkeyProviderEnabled = isTurnkeyEnabled(projectSettings);
|
|
12
28
|
const { updateUserProfileByJWT } = useUpdateUserProfileByJWTCallback();
|
|
13
29
|
const { verificationUUID: emailVerificationContextVerificationUUID } = useEmailVerificationContext();
|
|
14
30
|
const verifyEmail$1 = useCallback((verificationToken, verificationUUID) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
var _b;
|
|
15
32
|
if (!jwtToken)
|
|
16
33
|
throw new Error('No JWT token provided');
|
|
17
34
|
// VerificationUUID is saved in the context in case the view changes
|
|
@@ -23,12 +40,22 @@ const useEmailVerificationRequest = () => {
|
|
|
23
40
|
verificationToken,
|
|
24
41
|
verificationUUID: String(verificationUUID || emailVerificationContextVerificationUUID),
|
|
25
42
|
}, jwtToken);
|
|
43
|
+
if (isTurnkeyProviderEnabled &&
|
|
44
|
+
((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _b === void 0 ? void 0 : _b.automaticEmbeddedWalletCreation) &&
|
|
45
|
+
!primaryWallet) {
|
|
46
|
+
// Don't create the user right now
|
|
47
|
+
// It will be done after the wallet creation
|
|
48
|
+
return verifyEmailResponse;
|
|
49
|
+
}
|
|
26
50
|
yield updateUserProfileByJWT(verifyEmailResponse.jwt);
|
|
27
51
|
return verifyEmailResponse;
|
|
28
52
|
}), [
|
|
29
53
|
emailVerificationContextVerificationUUID,
|
|
30
54
|
environmentId,
|
|
55
|
+
isTurnkeyProviderEnabled,
|
|
31
56
|
jwtToken,
|
|
57
|
+
primaryWallet,
|
|
58
|
+
(_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.automaticEmbeddedWalletCreation,
|
|
32
59
|
updateUserProfileByJWT,
|
|
33
60
|
]);
|
|
34
61
|
return { verifyEmail: verifyEmail$1 };
|
|
@@ -41,3 +41,4 @@ export { useWalletConnectorOptions } from './useWalletConnectorOptions';
|
|
|
41
41
|
export { useWalletConnectors } from './useWalletConnectors';
|
|
42
42
|
export { useWalletItemActions } from './useWalletItemActions';
|
|
43
43
|
export { useWalletUiUtils } from './useWalletUiUtils';
|
|
44
|
+
export { useEmbeddedReveal } from './useEmbeddedReveal';
|
|
@@ -48,7 +48,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
48
48
|
view !== 'social-redirect-view' &&
|
|
49
49
|
view !== 'update-email' &&
|
|
50
50
|
view !== 'collect-user-data-login-with-email' &&
|
|
51
|
-
view !== 'passkey-recovery-start'
|
|
51
|
+
view !== 'passkey-recovery-start' &&
|
|
52
|
+
view !== 'embedded-reveal-view';
|
|
52
53
|
const showConnectedWalletProgress = isBridgeFlow &&
|
|
53
54
|
(view === 'wallet-list' ||
|
|
54
55
|
view === 'qr-code' ||
|
|
@@ -94,12 +95,14 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
94
95
|
view === 'passkey-intro' ||
|
|
95
96
|
(view === 'merge-user-accounts' && !user);
|
|
96
97
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
98
|
+
const showDefaultFooter = !showDynamicFooter && !showToSFooter;
|
|
97
99
|
return {
|
|
98
100
|
displayBorderBelowHeader,
|
|
99
101
|
isWalletListTypeView,
|
|
100
102
|
showBackButton,
|
|
101
103
|
showCloseButton,
|
|
102
104
|
showConnectedWalletProgress,
|
|
105
|
+
showDefaultFooter,
|
|
103
106
|
showDynamicFooter,
|
|
104
107
|
showHeader,
|
|
105
108
|
showHelpContent,
|
|
@@ -5,6 +5,7 @@ export declare const useAuthLayoutChecks: (walletConnector?: WalletConnector | n
|
|
|
5
5
|
showBackButton: boolean;
|
|
6
6
|
showCloseButton: boolean;
|
|
7
7
|
showConnectedWalletProgress: boolean;
|
|
8
|
+
showDefaultFooter: boolean;
|
|
8
9
|
showDynamicFooter: boolean;
|
|
9
10
|
showHeader: boolean;
|
|
10
11
|
showHelpContent: boolean;
|
|
@@ -44,7 +44,8 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
44
44
|
view !== 'social-redirect-view' &&
|
|
45
45
|
view !== 'update-email' &&
|
|
46
46
|
view !== 'collect-user-data-login-with-email' &&
|
|
47
|
-
view !== 'passkey-recovery-start'
|
|
47
|
+
view !== 'passkey-recovery-start' &&
|
|
48
|
+
view !== 'embedded-reveal-view';
|
|
48
49
|
const showConnectedWalletProgress = isBridgeFlow &&
|
|
49
50
|
(view === 'wallet-list' ||
|
|
50
51
|
view === 'qr-code' ||
|
|
@@ -90,12 +91,14 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
90
91
|
view === 'passkey-intro' ||
|
|
91
92
|
(view === 'merge-user-accounts' && !user);
|
|
92
93
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
94
|
+
const showDefaultFooter = !showDynamicFooter && !showToSFooter;
|
|
93
95
|
return {
|
|
94
96
|
displayBorderBelowHeader,
|
|
95
97
|
isWalletListTypeView,
|
|
96
98
|
showBackButton,
|
|
97
99
|
showCloseButton,
|
|
98
100
|
showConnectedWalletProgress,
|
|
101
|
+
showDefaultFooter,
|
|
99
102
|
showDynamicFooter,
|
|
100
103
|
showHeader,
|
|
101
104
|
showHelpContent,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useConnectWithEmailOtp } from './useConnectWithEmailOtp';
|
|
@@ -0,0 +1,150 @@
|
|
|
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 walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var sdkApi = require('@dynamic-labs/sdk-api');
|
|
9
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
10
|
+
var useWalletItemActions = require('../useWalletItemActions/useWalletItemActions.cjs');
|
|
11
|
+
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
|
|
12
|
+
require('../../../shared/logger.cjs');
|
|
13
|
+
require('@dynamic-labs/iconic');
|
|
14
|
+
require('react/jsx-runtime');
|
|
15
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
16
|
+
require('@dynamic-labs/wallet-book');
|
|
17
|
+
require('../../constants/colors.cjs');
|
|
18
|
+
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
19
|
+
require('viem');
|
|
20
|
+
require('@dynamic-labs/utils');
|
|
21
|
+
require('../../../shared/consts/index.cjs');
|
|
22
|
+
require('@dynamic-labs/multi-wallet');
|
|
23
|
+
var isProviderEnabled = require('../../functions/isProviderEnabled/isProviderEnabled.cjs');
|
|
24
|
+
var isEmailValid = require('../../functions/isEmailValid/isEmailValid.cjs');
|
|
25
|
+
var api = require('../../../data/api.cjs');
|
|
26
|
+
var useCreateUserProfileByJWTCallback = require('../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.cjs');
|
|
27
|
+
|
|
28
|
+
const mapEmailProviderToProviderEnum = {
|
|
29
|
+
dynamic: sdkApi.ProviderEnum.Dynamic,
|
|
30
|
+
emailOnly: sdkApi.ProviderEnum.EmailOnly,
|
|
31
|
+
magicLink: sdkApi.ProviderEnum.MagicLink,
|
|
32
|
+
};
|
|
33
|
+
const allSupportedProviders = Object.values(mapEmailProviderToProviderEnum);
|
|
34
|
+
/**
|
|
35
|
+
* Hook to connect and verify an email using a one-time password (OTP) with specified email providers.
|
|
36
|
+
*
|
|
37
|
+
* @param props - The properties for the hook. Includes an optional 'provider' to specify the email provider.
|
|
38
|
+
* @returns An object containing two functions:
|
|
39
|
+
* - connectWithEmail: A function to initiate the OTP process with the provided email.
|
|
40
|
+
* - verifyOneTimePassword: A function to verify the provided OTP.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const { connectWithEmail, verifyOneTimePassword } = useConnectWithEmailOtp({ provider: ProviderEnum.MagicLink });
|
|
44
|
+
*
|
|
45
|
+
* // To initiate the OTP process
|
|
46
|
+
* connectWithEmail('user@example.com').then(() => {
|
|
47
|
+
* // OTP sent to the email
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // To verify the OTP
|
|
51
|
+
* verifyOneTimePassword('123456').then(() => {
|
|
52
|
+
* // OTP verification successful
|
|
53
|
+
* }).catch((error) => {
|
|
54
|
+
* // Error handling
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
const useConnectWithEmailOtp = ({ provider, } = {}) => {
|
|
58
|
+
const { walletConnectorOptions, environmentId, projectSettings, setCallback, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
59
|
+
const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback.useCreateUserProfileByJWTCallback();
|
|
60
|
+
const { handleInstalledExtensionClick } = useWalletItemActions.useWalletItemActions();
|
|
61
|
+
const lastVerificationHandlerRef = React.useRef(null);
|
|
62
|
+
const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
|
|
63
|
+
const emailOtpWalletConnector = walletConnectorOptions
|
|
64
|
+
.map(({ walletConnector }) => walletConnector)
|
|
65
|
+
.find(walletConnectorCore.isEmailOTPWalletConnector);
|
|
66
|
+
const mapProviderToEnabled = {
|
|
67
|
+
dynamic: isProviderEnabled.isProviderEnabled(providers, sdkApi.ProviderEnum.Dynamic),
|
|
68
|
+
emailOnly: isProviderEnabled.isProviderEnabled(providers, sdkApi.ProviderEnum.EmailOnly),
|
|
69
|
+
magicLink: isProviderEnabled.isProviderEnabled(providers, sdkApi.ProviderEnum.MagicLink),
|
|
70
|
+
};
|
|
71
|
+
const emailHandler = (email) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const { verificationUUID } = yield api.createEmailVerification({
|
|
73
|
+
email,
|
|
74
|
+
environmentId,
|
|
75
|
+
});
|
|
76
|
+
return (oneTimePassword) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
const { jwt } = yield api.signInWithEmailVerification({
|
|
78
|
+
environmentId,
|
|
79
|
+
verificationToken: oneTimePassword,
|
|
80
|
+
verificationUUID,
|
|
81
|
+
});
|
|
82
|
+
yield createUserProfileByJWT(jwt);
|
|
83
|
+
return {
|
|
84
|
+
email,
|
|
85
|
+
verified: Boolean(jwt),
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
const magicHandler = (email) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
if (!emailOtpWalletConnector) {
|
|
91
|
+
throw new Error('OTP wallet connector was not found');
|
|
92
|
+
}
|
|
93
|
+
emailOtpWalletConnector.setEmail(email);
|
|
94
|
+
handleInstalledExtensionClick(emailOtpWalletConnector);
|
|
95
|
+
return (oneTimePassword) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
return ({
|
|
97
|
+
email,
|
|
98
|
+
verified: yield emailOtpWalletConnector.verifyOneTimePassword(oneTimePassword),
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
const mapProviderToHandler = {
|
|
103
|
+
[sdkApi.ProviderEnum.Dynamic]: emailHandler,
|
|
104
|
+
[sdkApi.ProviderEnum.EmailOnly]: emailHandler,
|
|
105
|
+
[sdkApi.ProviderEnum.MagicLink]: magicHandler,
|
|
106
|
+
};
|
|
107
|
+
const getEffectiveEmailProvider = (email) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
if (provider) {
|
|
109
|
+
return provider;
|
|
110
|
+
}
|
|
111
|
+
const { emailProvider } = yield api.getEmailProvider({
|
|
112
|
+
email,
|
|
113
|
+
environmentId,
|
|
114
|
+
});
|
|
115
|
+
if (!allSupportedProviders.includes(emailProvider)) {
|
|
116
|
+
throw new Error('Email provider is not supported');
|
|
117
|
+
}
|
|
118
|
+
return emailProvider;
|
|
119
|
+
});
|
|
120
|
+
const connectWithEmail = (email) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
if (!isEmailValid.isEmailValid(email)) {
|
|
122
|
+
throw new Error('Email is not valid');
|
|
123
|
+
}
|
|
124
|
+
const effectiveEmailProvider = yield getEffectiveEmailProvider(email);
|
|
125
|
+
if (!mapProviderToEnabled[effectiveEmailProvider]) {
|
|
126
|
+
throw new Error('Email provider is not enabled');
|
|
127
|
+
}
|
|
128
|
+
const verificationHandler = yield mapProviderToHandler[effectiveEmailProvider](email);
|
|
129
|
+
lastVerificationHandlerRef.current = verificationHandler;
|
|
130
|
+
});
|
|
131
|
+
const verifyOneTimePassword = (oneTimePassword) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
if (!lastVerificationHandlerRef.current) {
|
|
133
|
+
throw new Error('Verification have not started, use connectWithEmail before verifying');
|
|
134
|
+
}
|
|
135
|
+
const { email, verified } = yield lastVerificationHandlerRef.current(oneTimePassword);
|
|
136
|
+
dynamicEvents.dynamicEvents.emit('emailVerificationResult', verified, email);
|
|
137
|
+
if (verified) {
|
|
138
|
+
setCallback('authSuccess');
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw new Error('Email verification failed');
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
connectWithEmail,
|
|
146
|
+
verifyOneTimePassword,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
exports.useConnectWithEmailOtp = useConnectWithEmailOtp;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
type EmailProviders = 'magicLink' | 'dynamic' | 'emailOnly';
|
|
2
|
+
type UseConnectWithEmailOtpProps = {
|
|
3
|
+
provider?: EmailProviders;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Hook to connect and verify an email using a one-time password (OTP) with specified email providers.
|
|
7
|
+
*
|
|
8
|
+
* @param props - The properties for the hook. Includes an optional 'provider' to specify the email provider.
|
|
9
|
+
* @returns An object containing two functions:
|
|
10
|
+
* - connectWithEmail: A function to initiate the OTP process with the provided email.
|
|
11
|
+
* - verifyOneTimePassword: A function to verify the provided OTP.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const { connectWithEmail, verifyOneTimePassword } = useConnectWithEmailOtp({ provider: ProviderEnum.MagicLink });
|
|
15
|
+
*
|
|
16
|
+
* // To initiate the OTP process
|
|
17
|
+
* connectWithEmail('user@example.com').then(() => {
|
|
18
|
+
* // OTP sent to the email
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // To verify the OTP
|
|
22
|
+
* verifyOneTimePassword('123456').then(() => {
|
|
23
|
+
* // OTP verification successful
|
|
24
|
+
* }).catch((error) => {
|
|
25
|
+
* // Error handling
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
export declare const useConnectWithEmailOtp: ({ provider, }?: UseConnectWithEmailOtpProps) => {
|
|
29
|
+
connectWithEmail: (email: string) => Promise<void>;
|
|
30
|
+
verifyOneTimePassword: (oneTimePassword: string) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { isEmailOTPWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
5
|
+
import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
6
|
+
import { useWalletItemActions } from '../useWalletItemActions/useWalletItemActions.js';
|
|
7
|
+
import { dynamicEvents } from '../../../events/dynamicEvents.js';
|
|
8
|
+
import '../../../shared/logger.js';
|
|
9
|
+
import '@dynamic-labs/iconic';
|
|
10
|
+
import 'react/jsx-runtime';
|
|
11
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
12
|
+
import '@dynamic-labs/wallet-book';
|
|
13
|
+
import '../../constants/colors.js';
|
|
14
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
15
|
+
import 'viem';
|
|
16
|
+
import '@dynamic-labs/utils';
|
|
17
|
+
import '../../../shared/consts/index.js';
|
|
18
|
+
import '@dynamic-labs/multi-wallet';
|
|
19
|
+
import { isProviderEnabled } from '../../functions/isProviderEnabled/isProviderEnabled.js';
|
|
20
|
+
import { isEmailValid } from '../../functions/isEmailValid/isEmailValid.js';
|
|
21
|
+
import { createEmailVerification, signInWithEmailVerification, getEmailProvider } from '../../../data/api.js';
|
|
22
|
+
import { useCreateUserProfileByJWTCallback } from '../useCreateUserProfileByJWTCallback/useCreateUserProfileByJWTCallback.js';
|
|
23
|
+
|
|
24
|
+
const mapEmailProviderToProviderEnum = {
|
|
25
|
+
dynamic: ProviderEnum.Dynamic,
|
|
26
|
+
emailOnly: ProviderEnum.EmailOnly,
|
|
27
|
+
magicLink: ProviderEnum.MagicLink,
|
|
28
|
+
};
|
|
29
|
+
const allSupportedProviders = Object.values(mapEmailProviderToProviderEnum);
|
|
30
|
+
/**
|
|
31
|
+
* Hook to connect and verify an email using a one-time password (OTP) with specified email providers.
|
|
32
|
+
*
|
|
33
|
+
* @param props - The properties for the hook. Includes an optional 'provider' to specify the email provider.
|
|
34
|
+
* @returns An object containing two functions:
|
|
35
|
+
* - connectWithEmail: A function to initiate the OTP process with the provided email.
|
|
36
|
+
* - verifyOneTimePassword: A function to verify the provided OTP.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const { connectWithEmail, verifyOneTimePassword } = useConnectWithEmailOtp({ provider: ProviderEnum.MagicLink });
|
|
40
|
+
*
|
|
41
|
+
* // To initiate the OTP process
|
|
42
|
+
* connectWithEmail('user@example.com').then(() => {
|
|
43
|
+
* // OTP sent to the email
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // To verify the OTP
|
|
47
|
+
* verifyOneTimePassword('123456').then(() => {
|
|
48
|
+
* // OTP verification successful
|
|
49
|
+
* }).catch((error) => {
|
|
50
|
+
* // Error handling
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
const useConnectWithEmailOtp = ({ provider, } = {}) => {
|
|
54
|
+
const { walletConnectorOptions, environmentId, projectSettings, setCallback, } = useInternalDynamicContext();
|
|
55
|
+
const { createUserProfileByJWT } = useCreateUserProfileByJWTCallback();
|
|
56
|
+
const { handleInstalledExtensionClick } = useWalletItemActions();
|
|
57
|
+
const lastVerificationHandlerRef = useRef(null);
|
|
58
|
+
const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
|
|
59
|
+
const emailOtpWalletConnector = walletConnectorOptions
|
|
60
|
+
.map(({ walletConnector }) => walletConnector)
|
|
61
|
+
.find(isEmailOTPWalletConnector);
|
|
62
|
+
const mapProviderToEnabled = {
|
|
63
|
+
dynamic: isProviderEnabled(providers, ProviderEnum.Dynamic),
|
|
64
|
+
emailOnly: isProviderEnabled(providers, ProviderEnum.EmailOnly),
|
|
65
|
+
magicLink: isProviderEnabled(providers, ProviderEnum.MagicLink),
|
|
66
|
+
};
|
|
67
|
+
const emailHandler = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
const { verificationUUID } = yield createEmailVerification({
|
|
69
|
+
email,
|
|
70
|
+
environmentId,
|
|
71
|
+
});
|
|
72
|
+
return (oneTimePassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const { jwt } = yield signInWithEmailVerification({
|
|
74
|
+
environmentId,
|
|
75
|
+
verificationToken: oneTimePassword,
|
|
76
|
+
verificationUUID,
|
|
77
|
+
});
|
|
78
|
+
yield createUserProfileByJWT(jwt);
|
|
79
|
+
return {
|
|
80
|
+
email,
|
|
81
|
+
verified: Boolean(jwt),
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
const magicHandler = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
if (!emailOtpWalletConnector) {
|
|
87
|
+
throw new Error('OTP wallet connector was not found');
|
|
88
|
+
}
|
|
89
|
+
emailOtpWalletConnector.setEmail(email);
|
|
90
|
+
handleInstalledExtensionClick(emailOtpWalletConnector);
|
|
91
|
+
return (oneTimePassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
return ({
|
|
93
|
+
email,
|
|
94
|
+
verified: yield emailOtpWalletConnector.verifyOneTimePassword(oneTimePassword),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
const mapProviderToHandler = {
|
|
99
|
+
[ProviderEnum.Dynamic]: emailHandler,
|
|
100
|
+
[ProviderEnum.EmailOnly]: emailHandler,
|
|
101
|
+
[ProviderEnum.MagicLink]: magicHandler,
|
|
102
|
+
};
|
|
103
|
+
const getEffectiveEmailProvider = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
if (provider) {
|
|
105
|
+
return provider;
|
|
106
|
+
}
|
|
107
|
+
const { emailProvider } = yield getEmailProvider({
|
|
108
|
+
email,
|
|
109
|
+
environmentId,
|
|
110
|
+
});
|
|
111
|
+
if (!allSupportedProviders.includes(emailProvider)) {
|
|
112
|
+
throw new Error('Email provider is not supported');
|
|
113
|
+
}
|
|
114
|
+
return emailProvider;
|
|
115
|
+
});
|
|
116
|
+
const connectWithEmail = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
if (!isEmailValid(email)) {
|
|
118
|
+
throw new Error('Email is not valid');
|
|
119
|
+
}
|
|
120
|
+
const effectiveEmailProvider = yield getEffectiveEmailProvider(email);
|
|
121
|
+
if (!mapProviderToEnabled[effectiveEmailProvider]) {
|
|
122
|
+
throw new Error('Email provider is not enabled');
|
|
123
|
+
}
|
|
124
|
+
const verificationHandler = yield mapProviderToHandler[effectiveEmailProvider](email);
|
|
125
|
+
lastVerificationHandlerRef.current = verificationHandler;
|
|
126
|
+
});
|
|
127
|
+
const verifyOneTimePassword = (oneTimePassword) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
if (!lastVerificationHandlerRef.current) {
|
|
129
|
+
throw new Error('Verification have not started, use connectWithEmail before verifying');
|
|
130
|
+
}
|
|
131
|
+
const { email, verified } = yield lastVerificationHandlerRef.current(oneTimePassword);
|
|
132
|
+
dynamicEvents.emit('emailVerificationResult', verified, email);
|
|
133
|
+
if (verified) {
|
|
134
|
+
setCallback('authSuccess');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
throw new Error('Email verification failed');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
connectWithEmail,
|
|
142
|
+
verifyOneTimePassword,
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export { useConnectWithEmailOtp };
|
|
@@ -22,6 +22,7 @@ require('viem');
|
|
|
22
22
|
require('@dynamic-labs/utils');
|
|
23
23
|
require('../../../shared/consts/index.cjs');
|
|
24
24
|
require('@dynamic-labs/multi-wallet');
|
|
25
|
+
var isProviderEnabled = require('../../functions/isProviderEnabled/isProviderEnabled.cjs');
|
|
25
26
|
var isTurnkeyEnabled = require('../../functions/isTurnkeyEnabled/isTurnkeyEnabled.cjs');
|
|
26
27
|
|
|
27
28
|
const useEmailProvider = ({ emailWalletConnector }) => {
|
|
@@ -39,9 +40,8 @@ const useEmailProvider = ({ emailWalletConnector }) => {
|
|
|
39
40
|
// for magic, as long as there are magic credentials available, then could have an email
|
|
40
41
|
// address that is a magic address, even if magic was previously turned off in dashboard
|
|
41
42
|
const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(provider.enabledAt && provider.provider === sdkApi.ProviderEnum.Blocto)).length);
|
|
43
|
+
(isProviderEnabled.isProviderEnabled(providers || [], sdkApi.ProviderEnum.MagicLink) ||
|
|
44
|
+
isProviderEnabled.isProviderEnabled(providers || [], sdkApi.ProviderEnum.Blocto));
|
|
45
45
|
const handleEmailOnlyLoginSubmit = (emailInput, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
const { email, verificationUUID } = yield api.createEmailVerification({
|
|
47
47
|
captchaToken,
|
|
@@ -18,6 +18,7 @@ import 'viem';
|
|
|
18
18
|
import '@dynamic-labs/utils';
|
|
19
19
|
import '../../../shared/consts/index.js';
|
|
20
20
|
import '@dynamic-labs/multi-wallet';
|
|
21
|
+
import { isProviderEnabled } from '../../functions/isProviderEnabled/isProviderEnabled.js';
|
|
21
22
|
import { isTurnkeyEnabled } from '../../functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
|
|
22
23
|
|
|
23
24
|
const useEmailProvider = ({ emailWalletConnector }) => {
|
|
@@ -35,9 +36,8 @@ const useEmailProvider = ({ emailWalletConnector }) => {
|
|
|
35
36
|
// for magic, as long as there are magic credentials available, then could have an email
|
|
36
37
|
// address that is a magic address, even if magic was previously turned off in dashboard
|
|
37
38
|
const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(provider.enabledAt && provider.provider === ProviderEnum.Blocto)).length);
|
|
39
|
+
(isProviderEnabled(providers || [], ProviderEnum.MagicLink) ||
|
|
40
|
+
isProviderEnabled(providers || [], ProviderEnum.Blocto));
|
|
41
41
|
const handleEmailOnlyLoginSubmit = (emailInput, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
42
|
const { email, verificationUUID } = yield createEmailVerification({
|
|
43
43
|
captchaToken,
|
|
@@ -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,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({
|