@dynamic-labs/sdk-react-core 1.1.0-alpha.3 → 1.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/lib/data/api.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/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -0
- 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/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/WalletList/WalletList.cjs +5 -8
- package/src/lib/views/WalletList/WalletList.js +5 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.1.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.3...v1.1.0-alpha.4) (2023-12-21)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add bitcoin integration ([#4216](https://github.com/dynamic-labs/DynamicAuth/issues/4216)) ([9584f1c](https://github.com/dynamic-labs/DynamicAuth/commit/9584f1cc3133835049ad1c53da980192263b8f21))
|
|
8
|
+
* add default footer to wallet list when tos and pp not enabled ([#4224](https://github.com/dynamic-labs/DynamicAuth/issues/4224)) ([0ad81c4](https://github.com/dynamic-labs/DynamicAuth/commit/0ad81c409bcb4aafb0dc565685525d620a95efce))
|
|
9
|
+
* adds useConnectWithEmailOtp ([#4234](https://github.com/dynamic-labs/DynamicAuth/issues/4234)) ([4a4e50a](https://github.com/dynamic-labs/DynamicAuth/commit/4a4e50ac8651c2a249d5125ae6bcf49aaf49be8c))
|
|
10
|
+
|
|
2
11
|
## [1.1.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2023-12-19)
|
|
3
12
|
|
|
4
13
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sdk-react-core",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"react-focus-lock": "2.9.2",
|
|
18
18
|
"react-i18next": "^13.2.0",
|
|
19
19
|
"yup": "0.32.11",
|
|
20
|
-
"@dynamic-labs/ethereum": "1.1.0-alpha.
|
|
21
|
-
"@dynamic-labs/logger": "1.1.0-alpha.
|
|
22
|
-
"@dynamic-labs/multi-wallet": "1.1.0-alpha.
|
|
23
|
-
"@dynamic-labs/rpc-providers": "1.1.0-alpha.
|
|
24
|
-
"@dynamic-labs/types": "1.1.0-alpha.
|
|
25
|
-
"@dynamic-labs/utils": "1.1.0-alpha.
|
|
26
|
-
"@dynamic-labs/viem-utils": "1.1.0-alpha.
|
|
27
|
-
"@dynamic-labs/wallet-book": "1.1.0-alpha.
|
|
28
|
-
"@dynamic-labs/wallet-connector-core": "1.1.0-alpha.
|
|
20
|
+
"@dynamic-labs/ethereum": "1.1.0-alpha.4",
|
|
21
|
+
"@dynamic-labs/logger": "1.1.0-alpha.4",
|
|
22
|
+
"@dynamic-labs/multi-wallet": "1.1.0-alpha.4",
|
|
23
|
+
"@dynamic-labs/rpc-providers": "1.1.0-alpha.4",
|
|
24
|
+
"@dynamic-labs/types": "1.1.0-alpha.4",
|
|
25
|
+
"@dynamic-labs/utils": "1.1.0-alpha.4",
|
|
26
|
+
"@dynamic-labs/viem-utils": "1.1.0-alpha.4",
|
|
27
|
+
"@dynamic-labs/wallet-book": "1.1.0-alpha.4",
|
|
28
|
+
"@dynamic-labs/wallet-connector-core": "1.1.0-alpha.4",
|
|
29
29
|
"eventemitter3": "5.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/src/index.cjs
CHANGED
|
@@ -181,6 +181,7 @@ var index$3 = require('./lib/utils/functions/walletFilters/index.cjs');
|
|
|
181
181
|
var SendBalanceContext = require('./lib/context/SendBalanceContext/SendBalanceContext.cjs');
|
|
182
182
|
require('./lib/context/FundingContext/FundingContext.cjs');
|
|
183
183
|
var useFunding = require('./lib/context/FundingContext/useFunding/useFunding.cjs');
|
|
184
|
+
var useConnectWithEmailOtp = require('./lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.cjs');
|
|
184
185
|
|
|
185
186
|
|
|
186
187
|
|
|
@@ -342,3 +343,4 @@ exports.SortWallets = index$3.SortWallets;
|
|
|
342
343
|
exports.UniswapFilter = index$3.UniswapFilter;
|
|
343
344
|
exports.useSendBalance = SendBalanceContext.useSendBalance;
|
|
344
345
|
exports.useFunding = useFunding.useFunding;
|
|
346
|
+
exports.useConnectWithEmailOtp = useConnectWithEmailOtp.useConnectWithEmailOtp;
|
package/src/index.d.ts
CHANGED
|
@@ -32,3 +32,4 @@ export { type DynamicJwt, DynamicJwtFromJSON } from '@dynamic-labs/sdk-api';
|
|
|
32
32
|
export { useSendBalance } from './lib/context/SendBalanceContext';
|
|
33
33
|
export type { LocaleResource } from './lib/locale';
|
|
34
34
|
export { useFunding } from './lib/context/FundingContext';
|
|
35
|
+
export { useConnectWithEmailOtp } from './lib/utils/hooks/useConnectWithEmailOtp';
|
package/src/index.js
CHANGED
|
@@ -177,3 +177,4 @@ export { FilterAndSortWallets, FilterBridgeChainsName, FilterWallets, RemoveWall
|
|
|
177
177
|
export { useSendBalance } from './lib/context/SendBalanceContext/SendBalanceContext.js';
|
|
178
178
|
import './lib/context/FundingContext/FundingContext.js';
|
|
179
179
|
export { useFunding } from './lib/context/FundingContext/useFunding/useFunding.js';
|
|
180
|
+
export { useConnectWithEmailOtp } from './lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.js';
|
package/src/lib/data/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
2
|
-
import { NoAccessError, AccountExistsError,
|
|
2
|
+
import { EmailVerificationError, NoAccessError, AccountExistsError, UserHasAccountWithEmailError, DynamicError, EmailAlreadyExistsError, UsernameAlreadyExistsError, EmailProviderError, WalletUsedError, WalletNotDeployedError, ChainalysisError, GateBlockedError, SocialAccountAlreadyExistsError } from '@dynamic-labs/utils';
|
|
3
3
|
import { UnprocessableEntityErrorCode, SDKApi, Configuration, VerifyRequestFromJSON, ChainEnum, WalletProviderEnum, AuthModeEnum, EmbeddedWalletProviderEnum } from '@dynamic-labs/sdk-api';
|
|
4
4
|
import { VERSION, API_VERSION } from '../../version.js';
|
|
5
5
|
import ApiEndpoint from '../config/ApiEndpoint.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isEmailValid } from './isEmailValid';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEmailValid: (email: string) => boolean;
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var sdkApi = require('@dynamic-labs/sdk-api');
|
|
6
|
+
|
|
7
|
+
const isProviderEnabled = (providers, provider) => providers.some((providerItem) => {
|
|
8
|
+
const providerEnabled = providerItem.provider === provider && Boolean(providerItem.enabledAt);
|
|
9
|
+
if (providerItem.provider === sdkApi.ProviderEnum.MagicLink) {
|
|
10
|
+
return providerEnabled && Boolean(providerItem.providerProjectId);
|
|
11
|
+
}
|
|
12
|
+
return providerEnabled;
|
|
13
|
+
});
|
|
6
14
|
|
|
7
15
|
exports.isProviderEnabled = isProviderEnabled;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
2
|
+
|
|
3
|
+
const isProviderEnabled = (providers, provider) => providers.some((providerItem) => {
|
|
4
|
+
const providerEnabled = providerItem.provider === provider && Boolean(providerItem.enabledAt);
|
|
5
|
+
if (providerItem.provider === ProviderEnum.MagicLink) {
|
|
6
|
+
return providerEnabled && Boolean(providerItem.providerProjectId);
|
|
7
|
+
}
|
|
8
|
+
return providerEnabled;
|
|
9
|
+
});
|
|
2
10
|
|
|
3
11
|
export { isProviderEnabled };
|
|
@@ -94,12 +94,14 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
94
94
|
view === 'passkey-intro' ||
|
|
95
95
|
(view === 'merge-user-accounts' && !user);
|
|
96
96
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
97
|
+
const showDefaultFooter = !showDynamicFooter && !showToSFooter;
|
|
97
98
|
return {
|
|
98
99
|
displayBorderBelowHeader,
|
|
99
100
|
isWalletListTypeView,
|
|
100
101
|
showBackButton,
|
|
101
102
|
showCloseButton,
|
|
102
103
|
showConnectedWalletProgress,
|
|
104
|
+
showDefaultFooter,
|
|
103
105
|
showDynamicFooter,
|
|
104
106
|
showHeader,
|
|
105
107
|
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;
|
|
@@ -90,12 +90,14 @@ const useAuthLayoutChecks = (walletConnector) => {
|
|
|
90
90
|
view === 'passkey-intro' ||
|
|
91
91
|
(view === 'merge-user-accounts' && !user);
|
|
92
92
|
const showQrCodePreHeader = view === 'qr-code' && showQrCodeMessage && !showQrCodeImage;
|
|
93
|
+
const showDefaultFooter = !showDynamicFooter && !showToSFooter;
|
|
93
94
|
return {
|
|
94
95
|
displayBorderBelowHeader,
|
|
95
96
|
isWalletListTypeView,
|
|
96
97
|
showBackButton,
|
|
97
98
|
showCloseButton,
|
|
98
99
|
showConnectedWalletProgress,
|
|
100
|
+
showDefaultFooter,
|
|
99
101
|
showDynamicFooter,
|
|
100
102
|
showHeader,
|
|
101
103
|
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,
|
|
@@ -25,6 +25,7 @@ require('viem');
|
|
|
25
25
|
require('../../../../shared/consts/index.cjs');
|
|
26
26
|
require('@dynamic-labs/multi-wallet');
|
|
27
27
|
var isEmailProviderEnabled = require('../../../../utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.cjs');
|
|
28
|
+
var isEmailValid = require('../../../../utils/functions/isEmailValid/isEmailValid.cjs');
|
|
28
29
|
require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
29
30
|
require('../../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
30
31
|
require('../../../../config/ApiEndpoint.cjs');
|
|
@@ -66,7 +67,6 @@ require('../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
|
66
67
|
require('react-focus-lock');
|
|
67
68
|
var useEmailProvider = require('../../../../utils/hooks/useEmailProvider/useEmailProvider.cjs');
|
|
68
69
|
|
|
69
|
-
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
70
70
|
const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError, currentEmail, }) => {
|
|
71
71
|
var _a, _b, _c;
|
|
72
72
|
const { t } = reactI18next.useTranslation();
|
|
@@ -112,7 +112,7 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
112
112
|
const handleSubmit = (e) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
113
113
|
var _d;
|
|
114
114
|
e.preventDefault();
|
|
115
|
-
if (!
|
|
115
|
+
if (!isEmailValid.isEmailValid(emailInput)) {
|
|
116
116
|
setInvalidEmail(true);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
@@ -153,5 +153,4 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
153
153
|
}, children: "Continue" }))] }));
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
exports.EMAIL_REGEX = EMAIL_REGEX;
|
|
157
156
|
exports.LoginEmailForm = LoginEmailForm;
|
|
@@ -21,6 +21,7 @@ import 'viem';
|
|
|
21
21
|
import '../../../../shared/consts/index.js';
|
|
22
22
|
import '@dynamic-labs/multi-wallet';
|
|
23
23
|
import { isEmailProviderEnabled } from '../../../../utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.js';
|
|
24
|
+
import { isEmailValid } from '../../../../utils/functions/isEmailValid/isEmailValid.js';
|
|
24
25
|
import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
25
26
|
import '../../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
26
27
|
import '../../../../config/ApiEndpoint.js';
|
|
@@ -62,7 +63,6 @@ import '../../../../components/Popper/PopperContext/PopperContext.js';
|
|
|
62
63
|
import 'react-focus-lock';
|
|
63
64
|
import { useEmailProvider } from '../../../../utils/hooks/useEmailProvider/useEmailProvider.js';
|
|
64
65
|
|
|
65
|
-
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
66
66
|
const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError, currentEmail, }) => {
|
|
67
67
|
var _a, _b, _c;
|
|
68
68
|
const { t } = useTranslation();
|
|
@@ -108,7 +108,7 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
108
108
|
const handleSubmit = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
109
|
var _d;
|
|
110
110
|
e.preventDefault();
|
|
111
|
-
if (!
|
|
111
|
+
if (!isEmailValid(emailInput)) {
|
|
112
112
|
setInvalidEmail(true);
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
@@ -149,4 +149,4 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
149
149
|
}, children: "Continue" }))] }));
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
-
export {
|
|
152
|
+
export { LoginEmailForm };
|
|
@@ -15,30 +15,27 @@ require('../../utils/constants/colors.cjs');
|
|
|
15
15
|
var walletListBuilder = require('../../utils/functions/walletListBuilder/walletListBuilder.cjs');
|
|
16
16
|
var classNames = require('../../utils/functions/classNames/classNames.cjs');
|
|
17
17
|
var useInternalDynamicContext = require('../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
18
|
-
var MockContext = require('../../context/MockContext/MockContext.cjs');
|
|
19
|
-
var ViewContext = require('../../context/ViewContext/ViewContext.cjs');
|
|
20
|
-
var isUserLinkingWallet = require('../../shared/utils/functions/isUserLinkingWallet/isUserLinkingWallet.cjs');
|
|
21
18
|
var index = require('../../utils/functions/walletFilters/index.cjs');
|
|
22
19
|
require('@dynamic-labs/sdk-api');
|
|
23
20
|
require('../../shared/logger.cjs');
|
|
24
21
|
require('@dynamic-labs/iconic');
|
|
25
22
|
require('@dynamic-labs/wallet-connector-core');
|
|
23
|
+
require('../../context/ViewContext/ViewContext.cjs');
|
|
26
24
|
var localStorage = require('../../shared/utils/classes/storage/localStorage.cjs');
|
|
27
25
|
require('viem');
|
|
28
26
|
require('@dynamic-labs/utils');
|
|
29
27
|
require('../../shared/consts/index.cjs');
|
|
30
28
|
var noWalletFound = require('../../assets/no-wallet-found.cjs');
|
|
29
|
+
var useAuthLayoutChecks = require('../../utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs');
|
|
31
30
|
var SearchNotFoundMessage = require('./SearchNotFoundMessage/SearchNotFoundMessage.cjs');
|
|
32
31
|
var WalletListItem = require('./WalletListItem/WalletListItem.cjs');
|
|
33
32
|
|
|
34
33
|
localStorage.LocalStorage.setToLS(localStorage$1.WALLET_PICKER_SEARCH_KEY, '');
|
|
35
34
|
const WalletList = ({ isWalletConnectList = false, }) => {
|
|
36
35
|
var _a;
|
|
37
|
-
const { walletsFilter, signWithEmailWalletName,
|
|
36
|
+
const { walletsFilter, signWithEmailWalletName, walletConnectorOptions, projectSettings, defaultNumberOfWalletsToShow, bridgeChainsToConnect, connectedWallets, authMode, multiWallet, walletConnector, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
38
37
|
const { walletBook: walletBook$1 } = walletBook.useWalletBookContext();
|
|
39
38
|
const { error } = ErrorContext.useErrorContext();
|
|
40
|
-
const { view } = ViewContext.useViewContext();
|
|
41
|
-
const { mockedSDK } = MockContext.useMockContext();
|
|
42
39
|
const { t } = reactI18next.useTranslation();
|
|
43
40
|
const [filterValue, setFilterValue] = React.useState((_a = localStorage.LocalStorage.getFromLS(localStorage$1.WALLET_PICKER_SEARCH_KEY)) !== null && _a !== void 0 ? _a : '');
|
|
44
41
|
const [footerIsVisible, setFooterIsVisibile] = React.useState(false);
|
|
@@ -62,7 +59,7 @@ const WalletList = ({ isWalletConnectList = false, }) => {
|
|
|
62
59
|
});
|
|
63
60
|
const isSearchEnabled = numberOfWallets > defaultNumberOfWalletsToShow &&
|
|
64
61
|
walletsList.length !== numberOfWallets;
|
|
65
|
-
const
|
|
62
|
+
const { showDefaultFooter } = useAuthLayoutChecks.useAuthLayoutChecks(walletConnector);
|
|
66
63
|
const walletListScrollRef = React.useRef(null);
|
|
67
64
|
/* istanbul ignore next */
|
|
68
65
|
const handleScroll = () => {
|
|
@@ -87,7 +84,7 @@ const WalletList = ({ isWalletConnectList = false, }) => {
|
|
|
87
84
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [searchContainer, Boolean(error) && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { className: 'wallet-list__error-container', withIcon: false, children: error })), jsxRuntime.jsx("div", { className: 'wallet-list__container', children: jsxRuntime.jsxs("div", { className: classNames.classNames('wallet-list__scroll-container', {
|
|
88
85
|
'wallet-list__scroll-container--error': Boolean(error),
|
|
89
86
|
'wallet-list__scroll-container--full-height': isSearchEnabled,
|
|
90
|
-
}), "data-testid": 'wallet-list-scroll-container', ref: walletListScrollRef, onScroll: handleScroll, children: [!projectSettings ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [walletConnectorOptions.length === 0 && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsxRuntime.jsx(noWalletFound.ReactComponent, {}) })) : (walletsList.map((wallet, index) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet, usingMultiWallet: multiWallet, onResetSearchValue: () => handleFilterValueChange('') }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, {}))] }) }),
|
|
87
|
+
}), "data-testid": 'wallet-list-scroll-container', ref: walletListScrollRef, onScroll: handleScroll, children: [!projectSettings ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [walletConnectorOptions.length === 0 && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsxRuntime.jsx(noWalletFound.ReactComponent, {}) })) : (walletsList.map((wallet, index) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet, usingMultiWallet: multiWallet, onResetSearchValue: () => handleFilterValueChange('') }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsxRuntime.jsx(SearchNotFoundMessage.SearchNotFoundMessage, {}))] }) }), showDefaultFooter && (jsxRuntime.jsx("div", { className: classNames.classNames('wallet-list__tiny-footer', {
|
|
91
88
|
'wallet-list__tiny-footer--hidden': footerIsVisible,
|
|
92
89
|
}), "data-testid": 'wallet-list-tiny-footer' }))] }));
|
|
93
90
|
};
|
|
@@ -11,30 +11,27 @@ import '../../utils/constants/colors.js';
|
|
|
11
11
|
import { walletListBuilder } from '../../utils/functions/walletListBuilder/walletListBuilder.js';
|
|
12
12
|
import { classNames } from '../../utils/functions/classNames/classNames.js';
|
|
13
13
|
import { useInternalDynamicContext } from '../../context/DynamicContext/useInternalDynamicContext.js';
|
|
14
|
-
import { useMockContext } from '../../context/MockContext/MockContext.js';
|
|
15
|
-
import { useViewContext } from '../../context/ViewContext/ViewContext.js';
|
|
16
|
-
import { isUserLinkingWallet } from '../../shared/utils/functions/isUserLinkingWallet/isUserLinkingWallet.js';
|
|
17
14
|
import { FilterBridgeChainsName } from '../../utils/functions/walletFilters/index.js';
|
|
18
15
|
import '@dynamic-labs/sdk-api';
|
|
19
16
|
import '../../shared/logger.js';
|
|
20
17
|
import '@dynamic-labs/iconic';
|
|
21
18
|
import '@dynamic-labs/wallet-connector-core';
|
|
19
|
+
import '../../context/ViewContext/ViewContext.js';
|
|
22
20
|
import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js';
|
|
23
21
|
import 'viem';
|
|
24
22
|
import '@dynamic-labs/utils';
|
|
25
23
|
import '../../shared/consts/index.js';
|
|
26
24
|
import { ReactComponent as SvgNoWalletFound } from '../../assets/no-wallet-found.js';
|
|
25
|
+
import { useAuthLayoutChecks } from '../../utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js';
|
|
27
26
|
import { SearchNotFoundMessage } from './SearchNotFoundMessage/SearchNotFoundMessage.js';
|
|
28
27
|
import { WalletListItem } from './WalletListItem/WalletListItem.js';
|
|
29
28
|
|
|
30
29
|
LocalStorage.setToLS(WALLET_PICKER_SEARCH_KEY, '');
|
|
31
30
|
const WalletList = ({ isWalletConnectList = false, }) => {
|
|
32
31
|
var _a;
|
|
33
|
-
const { walletsFilter, signWithEmailWalletName,
|
|
32
|
+
const { walletsFilter, signWithEmailWalletName, walletConnectorOptions, projectSettings, defaultNumberOfWalletsToShow, bridgeChainsToConnect, connectedWallets, authMode, multiWallet, walletConnector, } = useInternalDynamicContext();
|
|
34
33
|
const { walletBook } = useWalletBookContext();
|
|
35
34
|
const { error } = useErrorContext();
|
|
36
|
-
const { view } = useViewContext();
|
|
37
|
-
const { mockedSDK } = useMockContext();
|
|
38
35
|
const { t } = useTranslation();
|
|
39
36
|
const [filterValue, setFilterValue] = useState((_a = LocalStorage.getFromLS(WALLET_PICKER_SEARCH_KEY)) !== null && _a !== void 0 ? _a : '');
|
|
40
37
|
const [footerIsVisible, setFooterIsVisibile] = useState(false);
|
|
@@ -58,7 +55,7 @@ const WalletList = ({ isWalletConnectList = false, }) => {
|
|
|
58
55
|
});
|
|
59
56
|
const isSearchEnabled = numberOfWallets > defaultNumberOfWalletsToShow &&
|
|
60
57
|
walletsList.length !== numberOfWallets;
|
|
61
|
-
const
|
|
58
|
+
const { showDefaultFooter } = useAuthLayoutChecks(walletConnector);
|
|
62
59
|
const walletListScrollRef = useRef(null);
|
|
63
60
|
/* istanbul ignore next */
|
|
64
61
|
const handleScroll = () => {
|
|
@@ -83,7 +80,7 @@ const WalletList = ({ isWalletConnectList = false, }) => {
|
|
|
83
80
|
return (jsxs(Fragment, { children: [searchContainer, Boolean(error) && (jsx(ErrorContainer, { className: 'wallet-list__error-container', withIcon: false, children: error })), jsx("div", { className: 'wallet-list__container', children: jsxs("div", { className: classNames('wallet-list__scroll-container', {
|
|
84
81
|
'wallet-list__scroll-container--error': Boolean(error),
|
|
85
82
|
'wallet-list__scroll-container--full-height': isSearchEnabled,
|
|
86
|
-
}), "data-testid": 'wallet-list-scroll-container', ref: walletListScrollRef, onScroll: handleScroll, children: [!projectSettings ? (jsx(Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxs(Fragment, { children: [walletConnectorOptions.length === 0 && (jsx(ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsx(SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsx(SvgNoWalletFound, {}) })) : (walletsList.map((wallet, index) => (jsx(WalletListItem, { wallet: wallet, usingMultiWallet: multiWallet, onResetSearchValue: () => handleFilterValueChange('') }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsx(SearchNotFoundMessage, {}))] }) }),
|
|
83
|
+
}), "data-testid": 'wallet-list-scroll-container', ref: walletListScrollRef, onScroll: handleScroll, children: [!projectSettings ? (jsx(Skeleton, { count: 10, className: 'wallet-list__tile-skeleton' })) : (jsxs(Fragment, { children: [walletConnectorOptions.length === 0 && (jsx(ErrorContainer, { copykey: 'dyn_wallet_list.configuration_mismatch', children: t('dyn_wallet_list.configuration_mismatch') })), walletConnectorOptions.length && walletsList.length === 0 ? (jsx(SearchNotFoundMessage, { title: t('dyn_wallet_list.search.not_found.title'), subtitle: t('dyn_wallet_list.search.not_found.description'), image: jsx(SvgNoWalletFound, {}) })) : (walletsList.map((wallet, index) => (jsx(WalletListItem, { wallet: wallet, usingMultiWallet: multiWallet, onResetSearchValue: () => handleFilterValueChange('') }, `${wallet.key}_${index}`))))] })), isSearchEnabled && !filterValue && projectSettings && (jsx(SearchNotFoundMessage, {}))] }) }), showDefaultFooter && (jsx("div", { className: classNames('wallet-list__tiny-footer', {
|
|
87
84
|
'wallet-list__tiny-footer--hidden': footerIsVisible,
|
|
88
85
|
}), "data-testid": 'wallet-list-tiny-footer' }))] }));
|
|
89
86
|
};
|