@dynamic-labs/sdk-react-core 0.18.0-beta.30 → 0.18.0-beta.31

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.
@@ -0,0 +1,99 @@
1
+ import { __awaiter } from '../../../../_virtual/_tslib.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { DynamicError } from '@dynamic-labs/utils';
4
+ import { WalletIcon } from '@dynamic-labs/wallet-book';
5
+ import { UserProfileIcon } from '@dynamic-labs/iconic';
6
+ import 'react';
7
+ import { Typography } from '../../components/Typography/Typography.js';
8
+ import { decodeJwt } from '../../shared/utils/functions/decodeJwt/decodeJwt.js';
9
+ import '@dynamic-labs/wallet-connector-core';
10
+ import { useViewContext } from '../../context/ViewContext/ViewContext.js';
11
+ import { ReactComponent as SvgDoubleArrowRight } from '../../shared/assets/double-arrow-right.js';
12
+ import '../../shared/logger.js';
13
+ import { shortenWalletAddress } from '../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.js';
14
+ import '../../utils/constants/colors.js';
15
+ import '../../shared/utils/classes/storage/localStorage.js';
16
+ import 'ethers';
17
+ import '../../shared/consts/index.js';
18
+ import { useInternalDynamicContext } from '../../context/DynamicContext/useInternalDynamicContext.js';
19
+ import { storeAuthToken } from '../../utils/functions/storeAuthToken/index.js';
20
+ import '@dynamic-labs/multi-wallet';
21
+ import { createUserProfile } from '../../utils/functions/createUserProfile/createUserProfile.js';
22
+ import '@dynamic-labs/sdk-api';
23
+ import '../../components/ShadowDOM/ShadowDOM.js';
24
+ import '../../context/ThemeContext/ThemeContext.js';
25
+ import { Icon } from '../../components/Icon/Icon.js';
26
+ import 'react-dom';
27
+ import 'react-focus-lock';
28
+ import '../../components/Transition/ZoomTransition/ZoomTransition.js';
29
+ import '../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
30
+ import '../../components/Transition/OpacityTransition/OpacityTransition.js';
31
+ import { mergeUserAccounts } from '../../data/api.js';
32
+ import '@dynamic-labs/rpc-providers';
33
+ import '../../utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.js';
34
+ import { useErrorContext } from '../../context/ErrorContext/ErrorContext.js';
35
+ import '../../context/AccessDeniedContext/AccessDeniedContext.js';
36
+ import '../../context/AccountExistsContext/AccountExistsContext.js';
37
+ import '../../components/IconButton/IconButton.js';
38
+ import { Button } from '../../components/Button/Button.js';
39
+ import '../../components/Alert/Alert.js';
40
+ import '../../context/MockContext/MockContext.js';
41
+ import '../../context/CaptchaContext/CaptchaContext.js';
42
+ import '../../utils/hooks/useUserUpdateRequest/useUserUpdateRequest.js';
43
+ import { shortenEmail } from '../../shared/utils/functions/shortenEmail/shortenEmail.js';
44
+ import '../../components/Popper/Popper/Popper.js';
45
+ import '../../components/Popper/PopperContext/PopperContext.js';
46
+ import 'formik';
47
+ import 'yup';
48
+ import '../../components/InlineWidget/InlineWidget.js';
49
+ import '../../components/MenuList/Dropdown/Dropdown.js';
50
+ import { useEmailVerificationContext } from '../../context/EmailVerificationContext/EmailVerificationContext.js';
51
+
52
+ const MergeUserAccountsView = () => {
53
+ const { environmentId, setUser, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, primaryWallet, user, authToken, onboardingOnlyJwt, } = useInternalDynamicContext();
54
+ const { setError } = useErrorContext();
55
+ const { setView, goToInitialView } = useViewContext();
56
+ const { email } = useEmailVerificationContext();
57
+ // If user tries to update an email for logged user there is already an authToken and onboardingOnlyJwt is undefined
58
+ // If user tries to merge during KYC step, authToken is undefined and onboardingOnlyJwt is defined
59
+ const jwtToken = authToken || onboardingOnlyJwt;
60
+ const handleMergeUserAccounts = () => __awaiter(void 0, void 0, void 0, function* () {
61
+ if (!jwtToken) {
62
+ return;
63
+ }
64
+ try {
65
+ const newJwt = yield mergeUserAccounts(jwtToken, environmentId);
66
+ if (newJwt) {
67
+ storeAuthToken(newJwt);
68
+ const decodedJwt = decodeJwt(newJwt);
69
+ if (decodedJwt === undefined) {
70
+ throw new DynamicError('Invalid token!');
71
+ }
72
+ const newUser = createUserProfile(decodedJwt);
73
+ setOnboardingOnlyJwt(undefined);
74
+ setUser(newUser);
75
+ setShowAuthFlow(false);
76
+ setCallback('authSuccess');
77
+ return;
78
+ }
79
+ throw new DynamicError('Something went wrong, please try again.');
80
+ }
81
+ catch (e) {
82
+ setError('Something went wrong, please try again.');
83
+ goToInitialView();
84
+ }
85
+ });
86
+ const handleUseDifferentEmail = () => {
87
+ setError(undefined);
88
+ if (user) {
89
+ setShowAuthFlow(false);
90
+ return;
91
+ }
92
+ setView('collect-user-data');
93
+ };
94
+ return (jsxs("div", Object.assign({ className: 'merge-user-accounts__container' }, { children: [jsxs("div", Object.assign({ className: 'merge-user-accounts__accounts' }, { children: [jsxs("div", Object.assign({ className: 'merge-user-accounts__accounts__item' }, { children: [jsx(WalletIcon, { walletName: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.name, className: 'merge-user-accounts__accounts__item__icon' }), jsx(Typography, Object.assign({ variant: 'body_normal', weight: 'medium', color: 'secondary', className: 'merge-user-accounts__accounts__item__text' }, { children: shortenWalletAddress(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address, 3, 3) }))] })), jsx("div", Object.assign({ className: 'merge-user-accounts__accounts__divider' }, { children: jsx(Icon, Object.assign({ color: 'text-secondary', size: 'small' }, { children: jsx(SvgDoubleArrowRight, {}) })) })), jsxs("div", Object.assign({ className: 'merge-user-accounts__accounts__item' }, { children: [jsx(UserProfileIcon, { className: 'merge-user-accounts__accounts__item__icon' }), jsx(Typography, Object.assign({ variant: 'body_normal', weight: 'medium', color: 'secondary', className: 'merge-user-accounts__accounts__item__text' }, { children: shortenEmail(email, {
95
+ breakpoint: 4,
96
+ }) }))] }))] })), jsxs(Typography, Object.assign({ weight: 'regular', variant: 'title', className: 'merge-user-accounts__text' }, { children: ["An account already exists that uses", ' ', jsx("span", Object.assign({ className: 'merge-user-accounts__text--bold' }, { children: email })), "."] })), jsxs("div", Object.assign({ className: 'merge-user-accounts__buttons' }, { children: [jsx(Button, Object.assign({ className: 'merge-user-accounts__buttons__button', onClick: handleMergeUserAccounts, buttonVariant: 'primary', buttonPadding: 'large', buttonRounded: 'default' }, { children: "Link wallet to existing account" })), jsx(Button, Object.assign({ className: 'merge-user-accounts__buttons__button', onClick: handleUseDifferentEmail, buttonVariant: 'secondary', buttonPadding: 'large', buttonRounded: 'default' }, { children: "Use different email" }))] }))] })));
97
+ };
98
+
99
+ export { MergeUserAccountsView };
@@ -0,0 +1 @@
1
+ export { MergeUserAccountsView } from './MergeUserAccountsView';
@@ -29,6 +29,7 @@ var BridgeWelcomeView = require('./BridgeWelcomeView/BridgeWelcomeView.cjs');
29
29
  var BridgeSummaryView = require('./BridgeSummaryView/BridgeSummaryView.cjs');
30
30
  var BridgeNextWalletConnectionView = require('./BridgeNextWalletConnectionView/BridgeNextWalletConnectionView.cjs');
31
31
  var AccountExistsView = require('./AccountExistsView/AccountExistsView.cjs');
32
+ var MergeUserAccountsView = require('./MergeUserAccountsView/MergeUserAccountsView.cjs');
32
33
 
33
34
  const viewToComponentMap = {
34
35
  'account-exists': jsxRuntime.jsx(AccountExistsView.AccountExistsView, {}),
@@ -44,6 +45,7 @@ const viewToComponentMap = {
44
45
  'login-with-email-or-wallet': jsxRuntime.jsx(LoginWithEmailView.LoginWithEmailView, {}),
45
46
  'login-with-email-or-wallet-full-wallet-list': jsxRuntime.jsx(WalletList.WalletList, {}),
46
47
  'login-with-email-verification': jsxRuntime.jsx(EmailVerification.EmailVerification, {}),
48
+ 'merge-user-accounts': jsxRuntime.jsx(MergeUserAccountsView.MergeUserAccountsView, {}),
47
49
  'network-not-supported': jsxRuntime.jsx(NetworkNotSupported.NetworkNotSupported, {}),
48
50
  'network-not-supported-manual': jsxRuntime.jsx(NetworkNotSupportedSwitchManual.NetworkNotSupportedSwitchManual, {}),
49
51
  'no-access': jsxRuntime.jsx(NoAccess.NoAccess, {}),
@@ -25,6 +25,7 @@ import { BridgeWelcomeView } from './BridgeWelcomeView/BridgeWelcomeView.js';
25
25
  import { BridgeSummaryView } from './BridgeSummaryView/BridgeSummaryView.js';
26
26
  import { BridgeNextWalletConnectionView } from './BridgeNextWalletConnectionView/BridgeNextWalletConnectionView.js';
27
27
  import { AccountExistsView } from './AccountExistsView/AccountExistsView.js';
28
+ import { MergeUserAccountsView } from './MergeUserAccountsView/MergeUserAccountsView.js';
28
29
 
29
30
  const viewToComponentMap = {
30
31
  'account-exists': jsx(AccountExistsView, {}),
@@ -40,6 +41,7 @@ const viewToComponentMap = {
40
41
  'login-with-email-or-wallet': jsx(LoginWithEmailView, {}),
41
42
  'login-with-email-or-wallet-full-wallet-list': jsx(WalletList, {}),
42
43
  'login-with-email-verification': jsx(EmailVerification, {}),
44
+ 'merge-user-accounts': jsx(MergeUserAccountsView, {}),
43
45
  'network-not-supported': jsx(NetworkNotSupported, {}),
44
46
  'network-not-supported-manual': jsx(NetworkNotSupportedSwitchManual, {}),
45
47
  'no-access': jsx(NoAccess, {}),