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