@dynamic-labs/sdk-react-core 0.18.0-RC.12 → 0.18.0-RC.14
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 +37 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +9 -9
- package/src/lib/Main.cjs +2 -2
- package/src/lib/Main.js +2 -2
- package/src/lib/context/DynamicContext/DynamicContext.cjs +11 -11
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +5 -4
- package/src/lib/context/DynamicContext/DynamicContext.js +11 -11
- package/src/lib/context/DynamicContext/useDynamicContext.cjs +2 -2
- package/src/lib/context/DynamicContext/useDynamicContext.d.ts +1 -1
- package/src/lib/context/DynamicContext/useDynamicContext.js +2 -2
- package/src/lib/layout/DynamicAuthLayout/HelpContent/WalletListHelpContent/NewToWeb3WalletItem/NewToWeb3WalletItem.cjs +1 -1
- package/src/lib/layout/DynamicAuthLayout/HelpContent/WalletListHelpContent/NewToWeb3WalletItem/NewToWeb3WalletItem.js +1 -1
- package/src/lib/utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.cjs +1 -0
- package/src/lib/utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.js +1 -0
- package/src/lib/utils/functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.cjs +2 -2
- package/src/lib/utils/functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.d.ts +1 -1
- package/src/lib/utils/functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.js +2 -2
- package/src/lib/utils/hooks/authenticationHooks/helpers/showPendingConnectView.cjs +1 -1
- package/src/lib/utils/hooks/authenticationHooks/helpers/showPendingConnectView.js +1 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +4 -3
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +5 -4
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectWithEmail/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.cjs +1 -4
- package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.d.ts +1 -4
- package/src/lib/utils/hooks/useConnectWithEmail/useConnectWithEmail.js +1 -4
- package/src/lib/utils/hooks/useEmailProvider/index.d.ts +1 -0
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.cjs +54 -0
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.d.ts +10 -0
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.js +50 -0
- package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +3 -0
- package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +3 -0
- package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.cjs +17 -0
- package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.d.ts +2 -0
- package/src/lib/utils/hooks/useWalletConnectorEvents/useWalletConnectorEvents.js +13 -0
- package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.cjs +3 -3
- package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.js +3 -3
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.cjs +24 -51
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.js +24 -51
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.cjs +2 -2
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailWalletList/LoginWithEmailWalletList.js +2 -2
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.cjs +7 -5
- package/src/lib/views/LoginWithEmailView/components/SocialSignIn/SocialSignIn.js +7 -5
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +14 -14
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +14 -14
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.cjs +20 -24
- package/src/lib/views/NetworkNotSupportedSwitchManual/NetworkNotSupportedSwitchManual.js +21 -25
- package/src/lib/views/WalletList/WalletList.cjs +2 -2
- package/src/lib/views/WalletList/WalletList.js +2 -2
- package/src/lib/views/WalletList/WalletListItem/WalletListItem.types.d.ts +1 -2
|
@@ -16,9 +16,8 @@ import { useErrorContext } from '../../../context/ErrorContext/ErrorContext.js';
|
|
|
16
16
|
|
|
17
17
|
const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
|
|
18
18
|
const { error } = useErrorContext();
|
|
19
|
-
const [email, setEmail] = useState('');
|
|
20
19
|
const [loading, setLoading] = useState(false);
|
|
21
|
-
const connectWithEmail = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const connectWithEmail = (email) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
21
|
if (!email || !emailWalletConnector || loading)
|
|
23
22
|
return;
|
|
24
23
|
setLoading(true);
|
|
@@ -38,9 +37,7 @@ const useConnectWithEmail = ({ emailWalletConnector, handleConnect, }) => {
|
|
|
38
37
|
}, [error, loading]);
|
|
39
38
|
return {
|
|
40
39
|
connectWithEmail,
|
|
41
|
-
email,
|
|
42
40
|
loading,
|
|
43
|
-
setEmail,
|
|
44
41
|
};
|
|
45
42
|
};
|
|
46
43
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEmailProvider } from './useEmailProvider';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var sdkApi = require('@dynamic-labs/sdk-api');
|
|
7
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
8
|
+
var EmailVerificationContext = require('../../../context/EmailVerificationContext/EmailVerificationContext.cjs');
|
|
9
|
+
var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
|
|
10
|
+
var useWalletItemActions = require('../useWalletItemActions/useWalletItemActions.cjs');
|
|
11
|
+
var useConnectWithEmail = require('../useConnectWithEmail/useConnectWithEmail.cjs');
|
|
12
|
+
var api = require('../../../data/api.cjs');
|
|
13
|
+
|
|
14
|
+
const useEmailProvider = ({ emailWalletConnector }) => {
|
|
15
|
+
const { projectSettings, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
|
|
16
|
+
const { setEmail: setEmailForVerification, setVerificationUUID } = EmailVerificationContext.useEmailVerificationContext();
|
|
17
|
+
const { setView } = ViewContext.useViewContext();
|
|
18
|
+
const { handleInstalledExtensionClick } = useWalletItemActions.useWalletItemActions();
|
|
19
|
+
const { connectWithEmail, loading: isEmailProviderLoading } = useConnectWithEmail.useConnectWithEmail({
|
|
20
|
+
emailWalletConnector,
|
|
21
|
+
handleConnect: handleInstalledExtensionClick,
|
|
22
|
+
});
|
|
23
|
+
const { providers } = projectSettings || {};
|
|
24
|
+
const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
|
|
25
|
+
const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
|
|
26
|
+
Boolean(providers === null || providers === void 0 ? void 0 : providers.filter((provider) => provider.provider === sdkApi.ProviderEnum.MagicLink ||
|
|
27
|
+
provider.provider === sdkApi.ProviderEnum.Blocto).length);
|
|
28
|
+
const handleEmailOnlyLoginSubmit = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
const { email, verificationUUID } = yield api.createEmailVerification({
|
|
30
|
+
email: emailInput,
|
|
31
|
+
environmentId,
|
|
32
|
+
});
|
|
33
|
+
setView('login-with-email-verification');
|
|
34
|
+
setEmailForVerification(email);
|
|
35
|
+
setVerificationUUID(verificationUUID);
|
|
36
|
+
});
|
|
37
|
+
const handleMagicLinkOrBloctoSubmit = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
yield connectWithEmail(emailInput);
|
|
39
|
+
});
|
|
40
|
+
const submitEmail = (emailInput) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
if (isMagicOrBloctoEnabled) {
|
|
42
|
+
yield handleMagicLinkOrBloctoSubmit(emailInput);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
yield handleEmailOnlyLoginSubmit(emailInput);
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
handleEmailOnlyLoginSubmit,
|
|
49
|
+
isEmailProviderLoading,
|
|
50
|
+
submitEmail,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.useEmailProvider = useEmailProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IEmailWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
type Props = {
|
|
3
|
+
emailWalletConnector: IEmailWalletConnector | undefined;
|
|
4
|
+
};
|
|
5
|
+
export declare const useEmailProvider: ({ emailWalletConnector }: Props) => {
|
|
6
|
+
handleEmailOnlyLoginSubmit: (emailInput: string) => Promise<void>;
|
|
7
|
+
isEmailProviderLoading: boolean;
|
|
8
|
+
submitEmail: (emailInput: string) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
3
|
+
import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
4
|
+
import { useEmailVerificationContext } from '../../../context/EmailVerificationContext/EmailVerificationContext.js';
|
|
5
|
+
import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
|
|
6
|
+
import { useWalletItemActions } from '../useWalletItemActions/useWalletItemActions.js';
|
|
7
|
+
import { useConnectWithEmail } from '../useConnectWithEmail/useConnectWithEmail.js';
|
|
8
|
+
import { createEmailVerification } from '../../../data/api.js';
|
|
9
|
+
|
|
10
|
+
const useEmailProvider = ({ emailWalletConnector }) => {
|
|
11
|
+
const { projectSettings, environmentId } = useInternalDynamicContext();
|
|
12
|
+
const { setEmail: setEmailForVerification, setVerificationUUID } = useEmailVerificationContext();
|
|
13
|
+
const { setView } = useViewContext();
|
|
14
|
+
const { handleInstalledExtensionClick } = useWalletItemActions();
|
|
15
|
+
const { connectWithEmail, loading: isEmailProviderLoading } = useConnectWithEmail({
|
|
16
|
+
emailWalletConnector,
|
|
17
|
+
handleConnect: handleInstalledExtensionClick,
|
|
18
|
+
});
|
|
19
|
+
const { providers } = projectSettings || {};
|
|
20
|
+
const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
|
|
21
|
+
const isMagicOrBloctoEnabled = isInjectedWalletProviderEnabled &&
|
|
22
|
+
Boolean(providers === null || providers === void 0 ? void 0 : providers.filter((provider) => provider.provider === ProviderEnum.MagicLink ||
|
|
23
|
+
provider.provider === ProviderEnum.Blocto).length);
|
|
24
|
+
const handleEmailOnlyLoginSubmit = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const { email, verificationUUID } = yield createEmailVerification({
|
|
26
|
+
email: emailInput,
|
|
27
|
+
environmentId,
|
|
28
|
+
});
|
|
29
|
+
setView('login-with-email-verification');
|
|
30
|
+
setEmailForVerification(email);
|
|
31
|
+
setVerificationUUID(verificationUUID);
|
|
32
|
+
});
|
|
33
|
+
const handleMagicLinkOrBloctoSubmit = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
yield connectWithEmail(emailInput);
|
|
35
|
+
});
|
|
36
|
+
const submitEmail = (emailInput) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
if (isMagicOrBloctoEnabled) {
|
|
38
|
+
yield handleMagicLinkOrBloctoSubmit(emailInput);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
yield handleEmailOnlyLoginSubmit(emailInput);
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
handleEmailOnlyLoginSubmit,
|
|
45
|
+
isEmailProviderLoading,
|
|
46
|
+
submitEmail,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { useEmailProvider };
|
|
@@ -40,6 +40,9 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
|
|
|
40
40
|
let currentWalletConnectV1Bridge;
|
|
41
41
|
if (walletConnectors) {
|
|
42
42
|
for (const connector of walletConnectors) {
|
|
43
|
+
if (!connector.isWalletConnect) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
43
46
|
const session = yield connector.getSession();
|
|
44
47
|
const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
|
|
45
48
|
if (bridge) {
|
|
@@ -36,6 +36,9 @@ const useValidateSession = ({ handleLogOut, user, authToken, walletConnectV1Brid
|
|
|
36
36
|
let currentWalletConnectV1Bridge;
|
|
37
37
|
if (walletConnectors) {
|
|
38
38
|
for (const connector of walletConnectors) {
|
|
39
|
+
if (!connector.isWalletConnect) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
39
42
|
const session = yield connector.getSession();
|
|
40
43
|
const bridge = session && (session === null || session === void 0 ? void 0 : session.bridge);
|
|
41
44
|
if (bridge) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
const useWalletConnectorEvents = (walletConnector, listeners) => {
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (!walletConnector || !listeners) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
walletConnector.setupEventListeners(listeners);
|
|
13
|
+
return () => walletConnector.teardownEventListeners();
|
|
14
|
+
}, [walletConnector, listeners]);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.useWalletConnectorEvents = useWalletConnectorEvents;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useWalletConnectorEvents = (walletConnector, listeners) => {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!walletConnector || !listeners) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
walletConnector.setupEventListeners(listeners);
|
|
9
|
+
return () => walletConnector.teardownEventListeners();
|
|
10
|
+
}, [walletConnector, listeners]);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { useWalletConnectorEvents };
|
|
@@ -28,7 +28,7 @@ var useConnectAndSignSplitSteps = require('../authenticationHooks/useConnectAndS
|
|
|
28
28
|
var isSelectedWalletAlreadyConnected = require('../../functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.cjs');
|
|
29
29
|
|
|
30
30
|
const useWalletItemActions = () => {
|
|
31
|
-
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user,
|
|
31
|
+
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, linkedWallets, setIsVerifying, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
32
32
|
const { mockedSDK } = MockContext.useMockContext();
|
|
33
33
|
const { setError } = ErrorContext.useErrorContext();
|
|
34
34
|
const { setView } = ViewContext.useViewContext();
|
|
@@ -79,7 +79,7 @@ const useWalletItemActions = () => {
|
|
|
79
79
|
});
|
|
80
80
|
const handleAlreadyConnectedWallet = (walletConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
81
81
|
const connectedAccounts = yield walletConnector.getConnectedAccounts();
|
|
82
|
-
const activeAccountAlreadyLinked =
|
|
82
|
+
const activeAccountAlreadyLinked = linkedWallets.find((wallet) => { var _a; return wallet.address.toLowerCase() === ((_a = connectedAccounts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
|
|
83
83
|
if (activeAccountAlreadyLinked) {
|
|
84
84
|
setMultiWalletWidgetState('awaiting_account_switch', 'linking_new_wallet');
|
|
85
85
|
}
|
|
@@ -112,7 +112,7 @@ const useWalletItemActions = () => {
|
|
|
112
112
|
yield walletConnector.endSession();
|
|
113
113
|
}
|
|
114
114
|
setIsVerifying(false);
|
|
115
|
-
if (isSelectedWalletAlreadyConnected.isSelectedWalletAlreadyConnected(
|
|
115
|
+
if (isSelectedWalletAlreadyConnected.isSelectedWalletAlreadyConnected(linkedWallets, walletConnector, user) &&
|
|
116
116
|
walletConnector.connectedChain !== 'FLOW') {
|
|
117
117
|
// wallet is already connected
|
|
118
118
|
handleAlreadyConnectedWallet(walletConnector);
|
|
@@ -24,7 +24,7 @@ import { useConnectAndSignSplitSteps } from '../authenticationHooks/useConnectAn
|
|
|
24
24
|
import { isSelectedWalletAlreadyConnected } from '../../functions/isSelectedWalletAlreadyConnected/isSelectedWalletAlreadyConnected.js';
|
|
25
25
|
|
|
26
26
|
const useWalletItemActions = () => {
|
|
27
|
-
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user,
|
|
27
|
+
const { setMultiWalletWidgetState, setShowAuthFlow, setSelectedWalletConnector, wallets, setQrcodeUri, setDesktopUri, user, linkedWallets, setIsVerifying, } = useInternalDynamicContext();
|
|
28
28
|
const { mockedSDK } = useMockContext();
|
|
29
29
|
const { setError } = useErrorContext();
|
|
30
30
|
const { setView } = useViewContext();
|
|
@@ -75,7 +75,7 @@ const useWalletItemActions = () => {
|
|
|
75
75
|
});
|
|
76
76
|
const handleAlreadyConnectedWallet = (walletConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
77
|
const connectedAccounts = yield walletConnector.getConnectedAccounts();
|
|
78
|
-
const activeAccountAlreadyLinked =
|
|
78
|
+
const activeAccountAlreadyLinked = linkedWallets.find((wallet) => { var _a; return wallet.address.toLowerCase() === ((_a = connectedAccounts[0]) === null || _a === void 0 ? void 0 : _a.toLowerCase()); });
|
|
79
79
|
if (activeAccountAlreadyLinked) {
|
|
80
80
|
setMultiWalletWidgetState('awaiting_account_switch', 'linking_new_wallet');
|
|
81
81
|
}
|
|
@@ -108,7 +108,7 @@ const useWalletItemActions = () => {
|
|
|
108
108
|
yield walletConnector.endSession();
|
|
109
109
|
}
|
|
110
110
|
setIsVerifying(false);
|
|
111
|
-
if (isSelectedWalletAlreadyConnected(
|
|
111
|
+
if (isSelectedWalletAlreadyConnected(linkedWallets, walletConnector, user) &&
|
|
112
112
|
walletConnector.connectedChain !== 'FLOW') {
|
|
113
113
|
// wallet is already connected
|
|
114
114
|
handleAlreadyConnectedWallet(walletConnector);
|
package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.cjs
CHANGED
|
@@ -7,113 +7,86 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
9
|
var sdkApi = require('@dynamic-labs/sdk-api');
|
|
10
|
-
require('@dynamic-labs/utils');
|
|
11
|
-
var api = require('../../../../data/api.cjs');
|
|
12
10
|
var logger = require('../../../../shared/logger.cjs');
|
|
13
11
|
require('@dynamic-labs/iconic');
|
|
14
|
-
|
|
12
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
15
13
|
require('@dynamic-labs/wallet-book');
|
|
14
|
+
require('@dynamic-labs/utils');
|
|
16
15
|
require('../../../../utils/constants/colors.cjs');
|
|
17
16
|
require('../../../../shared/utils/classes/storage/localStorage.cjs');
|
|
18
17
|
require('ethers');
|
|
19
18
|
require('../../../../shared/consts/index.cjs');
|
|
20
|
-
require('@dynamic-labs/multi-wallet');
|
|
21
|
-
require('@dynamic-labs/rpc-providers');
|
|
22
|
-
require('../../../../utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.cjs');
|
|
23
19
|
var useInternalDynamicContext = require('../../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
24
|
-
|
|
25
|
-
require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
26
|
-
require('react-dom');
|
|
20
|
+
require('@dynamic-labs/multi-wallet');
|
|
27
21
|
require('../../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
28
22
|
require('../../../../context/ThemeContext/ThemeContext.cjs');
|
|
29
23
|
var Input = require('../../../../components/Input/Input.cjs');
|
|
24
|
+
require('react-dom');
|
|
30
25
|
require('react-focus-lock');
|
|
31
26
|
require('../../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
32
27
|
require('../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
33
28
|
require('../../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
34
|
-
var
|
|
29
|
+
var api = require('../../../../data/api.cjs');
|
|
30
|
+
require('@dynamic-labs/rpc-providers');
|
|
31
|
+
require('../../../../utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.cjs');
|
|
32
|
+
var ErrorContext = require('../../../../context/ErrorContext/ErrorContext.cjs');
|
|
33
|
+
require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
35
34
|
require('../../../../components/IconButton/IconButton.cjs');
|
|
35
|
+
var Button = require('../../../../components/Button/Button.cjs');
|
|
36
36
|
require('../../../../components/Alert/Alert.cjs');
|
|
37
|
+
require('../../../../context/MockContext/MockContext.cjs');
|
|
38
|
+
require('../../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
39
|
+
require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
37
40
|
require('../../../../components/Popper/Popper/Popper.cjs');
|
|
38
41
|
require('../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
39
42
|
require('formik');
|
|
40
43
|
require('yup');
|
|
41
44
|
require('../../../../components/InlineWidget/InlineWidget.cjs');
|
|
42
|
-
var useWalletItemActions = require('../../../../utils/hooks/useWalletItemActions/useWalletItemActions.cjs');
|
|
43
|
-
require('../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.cjs');
|
|
44
|
-
var useConnectWithEmail = require('../../../../utils/hooks/useConnectWithEmail/useConnectWithEmail.cjs');
|
|
45
|
-
var EmailVerificationContext = require('../../../../context/EmailVerificationContext/EmailVerificationContext.cjs');
|
|
46
45
|
var LoadingContext = require('../../../../context/LoadingContext/LoadingContext.cjs');
|
|
46
|
+
var useEmailProvider = require('../../../../utils/hooks/useEmailProvider/useEmailProvider.cjs');
|
|
47
47
|
|
|
48
48
|
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
49
49
|
const LoginWithEmailForm = () => {
|
|
50
50
|
const { environmentId, wallets, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
|
|
51
|
-
const { setView } = ViewContext.useViewContext();
|
|
52
51
|
const { loading, setLoading } = LoadingContext.useLoadingContext();
|
|
53
52
|
const { setErrorMessage } = ErrorContext.useErrorContext();
|
|
54
|
-
const { setEmail: setEmailForVerification, setVerificationUUID } = EmailVerificationContext.useEmailVerificationContext();
|
|
55
53
|
const [emailInput, setEmailInput] = React.useState('');
|
|
56
54
|
const [emailError, setEmailError] = React.useState(false);
|
|
57
55
|
const emailWalletConnector = wallets
|
|
58
56
|
.map(({ walletConnector }) => walletConnector)
|
|
59
57
|
.find(walletConnectorCore.isEmailWalletConnector);
|
|
60
|
-
const {
|
|
61
|
-
const { connectWithEmail, email: magicEmail, setEmail: setEmailForMagic, loading: isMagicLoading, } = useConnectWithEmail.useConnectWithEmail({
|
|
58
|
+
const { handleEmailOnlyLoginSubmit, submitEmail, isEmailProviderLoading } = useEmailProvider.useEmailProvider({
|
|
62
59
|
emailWalletConnector,
|
|
63
|
-
handleConnect: handleInstalledExtensionClick,
|
|
64
60
|
});
|
|
65
|
-
const isLoading = React.useMemo(() =>
|
|
66
|
-
const handleMagicOnChangeEvent = (event) => {
|
|
67
|
-
const { value } = event.currentTarget;
|
|
68
|
-
setEmailForMagic(value);
|
|
69
|
-
};
|
|
61
|
+
const isLoading = React.useMemo(() => isEmailProviderLoading || loading, [isEmailProviderLoading, loading]);
|
|
70
62
|
const handleEmailOnChangeEvent = (event) => {
|
|
71
63
|
const { value } = event.currentTarget;
|
|
72
64
|
setEmailInput(value);
|
|
73
65
|
};
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
const handleEmailLoginSubmit = (emailInputOverride) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
-
const emailToVerify = emailInputOverride !== null && emailInputOverride !== void 0 ? emailInputOverride : emailInput;
|
|
79
|
-
const { email, verificationUUID } = yield api.createEmailVerification({
|
|
80
|
-
email: emailToVerify,
|
|
81
|
-
environmentId,
|
|
82
|
-
});
|
|
83
|
-
setView('login-with-email-verification');
|
|
84
|
-
setEmailForVerification(email);
|
|
85
|
-
setVerificationUUID(verificationUUID);
|
|
86
|
-
});
|
|
87
|
-
const magicLinkEnabled = emailWalletConnector !== undefined;
|
|
88
|
-
const submitHandler = magicLinkEnabled
|
|
89
|
-
? handleMagicLinkSubmit
|
|
90
|
-
: handleEmailLoginSubmit;
|
|
91
|
-
const onChangeHandler = magicLinkEnabled
|
|
92
|
-
? handleMagicOnChangeEvent
|
|
93
|
-
: handleEmailOnChangeEvent;
|
|
94
|
-
const emailValue = magicLinkEnabled ? magicEmail : emailInput;
|
|
66
|
+
const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
|
|
67
|
+
const onChangeHandler = handleEmailOnChangeEvent;
|
|
95
68
|
const handleSubmit = (e) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
96
69
|
e.preventDefault();
|
|
97
|
-
if (!EMAIL_REGEX.test(
|
|
70
|
+
if (!EMAIL_REGEX.test(emailInput)) {
|
|
98
71
|
setEmailError(true);
|
|
99
72
|
return;
|
|
100
73
|
}
|
|
101
74
|
try {
|
|
102
75
|
setLoading(true);
|
|
103
|
-
if (
|
|
76
|
+
if (isInjectedWalletProviderEnabled &&
|
|
104
77
|
(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
|
|
105
78
|
// see: https://linear.app/dynamic-labs/issue/DYN-2517
|
|
106
79
|
// if confirmWalletTransfers setting is true, check api first to confirm emailProvider
|
|
107
80
|
const { emailProvider } = yield api.getEmailProvider({
|
|
108
|
-
email:
|
|
81
|
+
email: emailInput,
|
|
109
82
|
environmentId,
|
|
110
83
|
});
|
|
111
84
|
if (emailProvider === sdkApi.ProviderEnum.EmailOnly) {
|
|
112
|
-
yield
|
|
85
|
+
yield handleEmailOnlyLoginSubmit(emailInput);
|
|
113
86
|
return;
|
|
114
87
|
}
|
|
115
88
|
}
|
|
116
|
-
yield
|
|
89
|
+
yield submitEmail(emailInput);
|
|
117
90
|
}
|
|
118
91
|
catch (error) {
|
|
119
92
|
logger.logger.debug(error);
|
|
@@ -124,7 +97,7 @@ const LoginWithEmailForm = () => {
|
|
|
124
97
|
}
|
|
125
98
|
});
|
|
126
99
|
// social sign in currently coupled to email... might be better to decouple
|
|
127
|
-
return (jsxRuntime.jsxs("form", Object.assign({ className: 'login-with-email-form', onSubmit: (e) => handleSubmit(e) }, { children: [jsxRuntime.jsx(Input.Input, { id: 'email_field', value:
|
|
100
|
+
return (jsxRuntime.jsxs("form", Object.assign({ className: 'login-with-email-form', onSubmit: (e) => handleSubmit(e) }, { children: [jsxRuntime.jsx(Input.Input, { id: 'email_field', value: emailInput, onChange: onChangeHandler, label: 'Enter your email', error: emailError, message: emailError && 'Please enter a valid email address' }), jsxRuntime.jsx(Button.Button, Object.assign({ buttonClassName: 'login-with-email-form__button', type: 'submit', loading: isLoading, disabled: isLoading, buttonVariant: 'primary', buttonPadding: 'large', buttonRounded: 'medium', expanded: true }, { children: "Continue" }))] })));
|
|
128
101
|
};
|
|
129
102
|
|
|
130
103
|
exports.EMAIL_REGEX = EMAIL_REGEX;
|
package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.js
CHANGED
|
@@ -3,113 +3,86 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { useState, useMemo } from 'react';
|
|
4
4
|
import { isEmailWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
6
|
-
import '@dynamic-labs/utils';
|
|
7
|
-
import { getEmailProvider, createEmailVerification } from '../../../../data/api.js';
|
|
8
6
|
import { logger } from '../../../../shared/logger.js';
|
|
9
7
|
import '@dynamic-labs/iconic';
|
|
10
|
-
import
|
|
8
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
11
9
|
import '@dynamic-labs/wallet-book';
|
|
10
|
+
import '@dynamic-labs/utils';
|
|
12
11
|
import '../../../../utils/constants/colors.js';
|
|
13
12
|
import '../../../../shared/utils/classes/storage/localStorage.js';
|
|
14
13
|
import 'ethers';
|
|
15
14
|
import '../../../../shared/consts/index.js';
|
|
16
|
-
import '@dynamic-labs/multi-wallet';
|
|
17
|
-
import '@dynamic-labs/rpc-providers';
|
|
18
|
-
import '../../../../utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.js';
|
|
19
15
|
import { useInternalDynamicContext } from '../../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
20
|
-
import
|
|
21
|
-
import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
22
|
-
import 'react-dom';
|
|
16
|
+
import '@dynamic-labs/multi-wallet';
|
|
23
17
|
import '../../../../components/ShadowDOM/ShadowDOM.js';
|
|
24
18
|
import '../../../../context/ThemeContext/ThemeContext.js';
|
|
25
19
|
import { Input } from '../../../../components/Input/Input.js';
|
|
20
|
+
import 'react-dom';
|
|
26
21
|
import 'react-focus-lock';
|
|
27
22
|
import '../../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
28
23
|
import '../../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
29
24
|
import '../../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
30
|
-
import {
|
|
25
|
+
import { getEmailProvider } from '../../../../data/api.js';
|
|
26
|
+
import '@dynamic-labs/rpc-providers';
|
|
27
|
+
import '../../../../utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.js';
|
|
28
|
+
import { useErrorContext } from '../../../../context/ErrorContext/ErrorContext.js';
|
|
29
|
+
import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
31
30
|
import '../../../../components/IconButton/IconButton.js';
|
|
31
|
+
import { Button } from '../../../../components/Button/Button.js';
|
|
32
32
|
import '../../../../components/Alert/Alert.js';
|
|
33
|
+
import '../../../../context/MockContext/MockContext.js';
|
|
34
|
+
import '../../../../context/CaptchaContext/CaptchaContext.js';
|
|
35
|
+
import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
33
36
|
import '../../../../components/Popper/Popper/Popper.js';
|
|
34
37
|
import '../../../../components/Popper/PopperContext/PopperContext.js';
|
|
35
38
|
import 'formik';
|
|
36
39
|
import 'yup';
|
|
37
40
|
import '../../../../components/InlineWidget/InlineWidget.js';
|
|
38
|
-
import { useWalletItemActions } from '../../../../utils/hooks/useWalletItemActions/useWalletItemActions.js';
|
|
39
|
-
import '../../../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
|
|
40
|
-
import { useConnectWithEmail } from '../../../../utils/hooks/useConnectWithEmail/useConnectWithEmail.js';
|
|
41
|
-
import { useEmailVerificationContext } from '../../../../context/EmailVerificationContext/EmailVerificationContext.js';
|
|
42
41
|
import { useLoadingContext } from '../../../../context/LoadingContext/LoadingContext.js';
|
|
42
|
+
import { useEmailProvider } from '../../../../utils/hooks/useEmailProvider/useEmailProvider.js';
|
|
43
43
|
|
|
44
44
|
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
45
45
|
const LoginWithEmailForm = () => {
|
|
46
46
|
const { environmentId, wallets, projectSettings } = useInternalDynamicContext();
|
|
47
|
-
const { setView } = useViewContext();
|
|
48
47
|
const { loading, setLoading } = useLoadingContext();
|
|
49
48
|
const { setErrorMessage } = useErrorContext();
|
|
50
|
-
const { setEmail: setEmailForVerification, setVerificationUUID } = useEmailVerificationContext();
|
|
51
49
|
const [emailInput, setEmailInput] = useState('');
|
|
52
50
|
const [emailError, setEmailError] = useState(false);
|
|
53
51
|
const emailWalletConnector = wallets
|
|
54
52
|
.map(({ walletConnector }) => walletConnector)
|
|
55
53
|
.find(isEmailWalletConnector);
|
|
56
|
-
const {
|
|
57
|
-
const { connectWithEmail, email: magicEmail, setEmail: setEmailForMagic, loading: isMagicLoading, } = useConnectWithEmail({
|
|
54
|
+
const { handleEmailOnlyLoginSubmit, submitEmail, isEmailProviderLoading } = useEmailProvider({
|
|
58
55
|
emailWalletConnector,
|
|
59
|
-
handleConnect: handleInstalledExtensionClick,
|
|
60
56
|
});
|
|
61
|
-
const isLoading = useMemo(() =>
|
|
62
|
-
const handleMagicOnChangeEvent = (event) => {
|
|
63
|
-
const { value } = event.currentTarget;
|
|
64
|
-
setEmailForMagic(value);
|
|
65
|
-
};
|
|
57
|
+
const isLoading = useMemo(() => isEmailProviderLoading || loading, [isEmailProviderLoading, loading]);
|
|
66
58
|
const handleEmailOnChangeEvent = (event) => {
|
|
67
59
|
const { value } = event.currentTarget;
|
|
68
60
|
setEmailInput(value);
|
|
69
61
|
};
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
const handleEmailLoginSubmit = (emailInputOverride) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
-
const emailToVerify = emailInputOverride !== null && emailInputOverride !== void 0 ? emailInputOverride : emailInput;
|
|
75
|
-
const { email, verificationUUID } = yield createEmailVerification({
|
|
76
|
-
email: emailToVerify,
|
|
77
|
-
environmentId,
|
|
78
|
-
});
|
|
79
|
-
setView('login-with-email-verification');
|
|
80
|
-
setEmailForVerification(email);
|
|
81
|
-
setVerificationUUID(verificationUUID);
|
|
82
|
-
});
|
|
83
|
-
const magicLinkEnabled = emailWalletConnector !== undefined;
|
|
84
|
-
const submitHandler = magicLinkEnabled
|
|
85
|
-
? handleMagicLinkSubmit
|
|
86
|
-
: handleEmailLoginSubmit;
|
|
87
|
-
const onChangeHandler = magicLinkEnabled
|
|
88
|
-
? handleMagicOnChangeEvent
|
|
89
|
-
: handleEmailOnChangeEvent;
|
|
90
|
-
const emailValue = magicLinkEnabled ? magicEmail : emailInput;
|
|
62
|
+
const isInjectedWalletProviderEnabled = emailWalletConnector !== undefined;
|
|
63
|
+
const onChangeHandler = handleEmailOnChangeEvent;
|
|
91
64
|
const handleSubmit = (e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
65
|
e.preventDefault();
|
|
93
|
-
if (!EMAIL_REGEX.test(
|
|
66
|
+
if (!EMAIL_REGEX.test(emailInput)) {
|
|
94
67
|
setEmailError(true);
|
|
95
68
|
return;
|
|
96
69
|
}
|
|
97
70
|
try {
|
|
98
71
|
setLoading(true);
|
|
99
|
-
if (
|
|
72
|
+
if (isInjectedWalletProviderEnabled &&
|
|
100
73
|
(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.confirmEmailProviderForVerify)) {
|
|
101
74
|
// see: https://linear.app/dynamic-labs/issue/DYN-2517
|
|
102
75
|
// if confirmWalletTransfers setting is true, check api first to confirm emailProvider
|
|
103
76
|
const { emailProvider } = yield getEmailProvider({
|
|
104
|
-
email:
|
|
77
|
+
email: emailInput,
|
|
105
78
|
environmentId,
|
|
106
79
|
});
|
|
107
80
|
if (emailProvider === ProviderEnum.EmailOnly) {
|
|
108
|
-
yield
|
|
81
|
+
yield handleEmailOnlyLoginSubmit(emailInput);
|
|
109
82
|
return;
|
|
110
83
|
}
|
|
111
84
|
}
|
|
112
|
-
yield
|
|
85
|
+
yield submitEmail(emailInput);
|
|
113
86
|
}
|
|
114
87
|
catch (error) {
|
|
115
88
|
logger.debug(error);
|
|
@@ -120,7 +93,7 @@ const LoginWithEmailForm = () => {
|
|
|
120
93
|
}
|
|
121
94
|
});
|
|
122
95
|
// social sign in currently coupled to email... might be better to decouple
|
|
123
|
-
return (jsxs("form", Object.assign({ className: 'login-with-email-form', onSubmit: (e) => handleSubmit(e) }, { children: [jsx(Input, { id: 'email_field', value:
|
|
96
|
+
return (jsxs("form", Object.assign({ className: 'login-with-email-form', onSubmit: (e) => handleSubmit(e) }, { children: [jsx(Input, { id: 'email_field', value: emailInput, onChange: onChangeHandler, label: 'Enter your email', error: emailError, message: emailError && 'Please enter a valid email address' }), jsx(Button, Object.assign({ buttonClassName: 'login-with-email-form__button', type: 'submit', loading: isLoading, disabled: isLoading, buttonVariant: 'primary', buttonPadding: 'large', buttonRounded: 'medium', expanded: true }, { children: "Continue" }))] })));
|
|
124
97
|
};
|
|
125
98
|
|
|
126
99
|
export { EMAIL_REGEX, LoginWithEmailForm };
|
|
@@ -24,9 +24,9 @@ var ListItemButton = require('../ListItemButton/ListItemButton.cjs');
|
|
|
24
24
|
const NUMBER_OF_WALLETS = 3;
|
|
25
25
|
const LoginWithEmailWalletList = ({ walletsList, numberOfWallets, }) => {
|
|
26
26
|
const { setView } = ViewContext.useViewContext();
|
|
27
|
-
const { projectSettings
|
|
27
|
+
const { projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
|
|
28
28
|
const isUsingMultiWallet = Boolean(localStorage.LocalStorage.getFromLS(localStorage$1.AUTH_USER));
|
|
29
|
-
return !projectSettings ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: NUMBER_OF_WALLETS + 1, className: 'login-with-email-wallet-list__skeleton' })) : (jsxRuntime.jsxs("div", Object.assign({ className: 'login-with-email-wallet-list__container' }, { children: [walletsList.map((wallet) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet,
|
|
29
|
+
return !projectSettings ? (jsxRuntime.jsx(Skeleton.Skeleton, { count: NUMBER_OF_WALLETS + 1, className: 'login-with-email-wallet-list__skeleton' })) : (jsxRuntime.jsxs("div", Object.assign({ className: 'login-with-email-wallet-list__container' }, { children: [walletsList.map((wallet) => (jsxRuntime.jsx(WalletListItem.WalletListItem, { wallet: wallet, usingMultiWallet: isUsingMultiWallet }, wallet.key))), jsxRuntime.jsx(ListItemButton.ListItemButton, { text: 'View all wallets', onClick: () => setView('login-with-email-or-wallet-full-wallet-list'), numberOfWallets: numberOfWallets })] })));
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
exports.LoginWithEmailWalletList = LoginWithEmailWalletList;
|
|
@@ -20,9 +20,9 @@ import { ListItemButton } from '../ListItemButton/ListItemButton.js';
|
|
|
20
20
|
const NUMBER_OF_WALLETS = 3;
|
|
21
21
|
const LoginWithEmailWalletList = ({ walletsList, numberOfWallets, }) => {
|
|
22
22
|
const { setView } = useViewContext();
|
|
23
|
-
const { projectSettings
|
|
23
|
+
const { projectSettings } = useInternalDynamicContext();
|
|
24
24
|
const isUsingMultiWallet = Boolean(LocalStorage.getFromLS(AUTH_USER));
|
|
25
|
-
return !projectSettings ? (jsx(Skeleton, { count: NUMBER_OF_WALLETS + 1, className: 'login-with-email-wallet-list__skeleton' })) : (jsxs("div", Object.assign({ className: 'login-with-email-wallet-list__container' }, { children: [walletsList.map((wallet) => (jsx(WalletListItem, { wallet: wallet,
|
|
25
|
+
return !projectSettings ? (jsx(Skeleton, { count: NUMBER_OF_WALLETS + 1, className: 'login-with-email-wallet-list__skeleton' })) : (jsxs("div", Object.assign({ className: 'login-with-email-wallet-list__container' }, { children: [walletsList.map((wallet) => (jsx(WalletListItem, { wallet: wallet, usingMultiWallet: isUsingMultiWallet }, wallet.key))), jsx(ListItemButton, { text: 'View all wallets', onClick: () => setView('login-with-email-or-wallet-full-wallet-list'), numberOfWallets: numberOfWallets })] })));
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export { LoginWithEmailWalletList, NUMBER_OF_WALLETS };
|