UNPKG

@dynamic-labs/sdk-react-core

Version:

A React SDK for implementing wallet web3 authentication and authorization to your website.

156 lines (151 loc) 11.6 kB
'use client' 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _tslib = require('../../../../_virtual/_tslib.cjs'); var jsxRuntime = require('react/jsx-runtime'); var reactI18next = require('react-i18next'); var utils = require('@dynamic-labs/utils'); var walletBook = require('@dynamic-labs/wallet-book'); var iconic = require('@dynamic-labs/iconic'); require('../../components/Accordion/components/AccordionItem/AccordionItem.cjs'); require('react'); var doubleArrowRight = require('../../shared/assets/double-arrow-right.cjs'); var ViewContext = require('../../context/ViewContext/ViewContext.cjs'); require('@dynamic-labs/sdk-api-core'); require('../../shared/logger.cjs'); require('@dynamic-labs/wallet-connector-core'); var shortenWalletAddress = require('../../shared/utils/functions/shortenWalletAddress/shortenWalletAddress.cjs'); require('../../utils/constants/colors.cjs'); require('../../utils/constants/values.cjs'); require('../../shared/consts/index.cjs'); require('../../components/Alert/Alert.cjs'); require('../../events/dynamicEvents.cjs'); require('../../context/DynamicContext/DynamicContext.cjs'); require('../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs'); require('../../store/state/authMode/authMode.cjs'); var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs'); require('../../context/CaptchaContext/CaptchaContext.cjs'); var ErrorContext = require('../../context/ErrorContext/ErrorContext.cjs'); require('@dynamic-labs/multi-wallet'); require('react-international-phone'); var shortenEmail = require('../../shared/utils/functions/shortenEmail/shortenEmail.cjs'); require('../../store/state/nonce/nonce.cjs'); require('../../store/state/projectSettings/projectSettings.cjs'); require('../../config/ApiEndpoint.cjs'); require('../../store/state/user/user.cjs'); require('../../locale/locale.cjs'); var user = require('../../data/api/user/user.cjs'); require('../../store/state/dynamicContextProps/dynamicContextProps.cjs'); require('../../store/state/primaryWalletId/primaryWalletId.cjs'); require('../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs'); require('../../context/AccessDeniedContext/AccessDeniedContext.cjs'); require('../../context/AccountExistsContext/AccountExistsContext.cjs'); require('../../context/UserWalletsContext/UserWalletsContext.cjs'); var VerificationContext = require('../../context/VerificationContext/VerificationContext.cjs'); require('react-dom'); require('../../utils/functions/compareChains/compareChains.cjs'); require('../Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs'); require('../../context/ThemeContext/ThemeContext.cjs'); require('../../utils/hooks/useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs'); require('bs58'); require('@dynamic-labs/types'); require('../../context/SocialRedirectContext/SocialRedirectContext.cjs'); require('../../context/LoadingContext/LoadingContext.cjs'); require('../../context/WalletContext/WalletContext.cjs'); require('../../utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs'); var useHandleAuthenticatedUser = require('../../utils/hooks/useHandleAuthenticatedUser/useHandleAuthenticatedUser.cjs'); require('yup'); require('../../context/MockContext/MockContext.cjs'); require('../CollectUserDataView/useFields.cjs'); require('../../context/FieldsStateContext/FieldsStateContext.cjs'); require('../../context/UserFieldEditorContext/UserFieldEditorContext.cjs'); require('@dynamic-labs/rpc-providers'); require('../../store/state/walletOptions/walletOptions.cjs'); var Typography = require('../../components/Typography/Typography.cjs'); require('../../context/FooterAnimationContext/index.cjs'); require('../../components/ShadowDOM/ShadowDOM.cjs'); require('../../components/Transition/ZoomTransition/ZoomTransition.cjs'); require('../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs'); require('../../components/Transition/OpacityTransition/OpacityTransition.cjs'); require('../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs'); require('../../context/WalletGroupContext/WalletGroupContext.cjs'); require('../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs'); require('react-focus-lock'); var Icon = require('../../components/Icon/Icon.cjs'); require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs'); require('../../components/IconButton/IconButton.cjs'); require('../../components/MenuList/Dropdown/Dropdown.cjs'); var TypographyButton = require('../../components/TypographyButton/TypographyButton.cjs'); require('formik'); require('../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs'); require('../../store/state/sendBalances.cjs'); require('../../components/Input/Input.cjs'); require('../../components/OverlayCard/OverlayCard.cjs'); require('../TransactionConfirmationView/TransactionConfirmationView.cjs'); require('../../context/PasskeyContext/PasskeyContext.cjs'); require('../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs'); require('../../context/OnrampContext/OnrampContext.cjs'); require('qrcode'); require('../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs'); require('../../../index.cjs'); require('../../context/IpConfigurationContext/IpConfigurationContext.cjs'); require('../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs'); require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs'); require('@hcaptcha/react-hcaptcha'); require('../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs'); require('../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs'); require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs'); require('../../store/state/connectorsInitializing/connectorsInitializing.cjs'); require('../../store/state/tokenBalances.cjs'); require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs'); require('../../components/InlineWidget/InlineWidget.cjs'); require('../../components/IsBrowser/IsBrowser.cjs'); require('../../components/Popper/Popper/Popper.cjs'); require('../../components/Popper/PopperContext/PopperContext.cjs'); const MergeUserAccountsWithSameEmailView = ({ returnToView }) => { const { environmentId, setShowAuthFlow, setCallback, primaryWallet, user: user$1 } = useInternalDynamicContext.useInternalDynamicContext(); const handleAuthenticatedUser = useHandleAuthenticatedUser.useHandleAuthenticatedUser(); const { t } = reactI18next.useTranslation(); const { setError } = ErrorContext.useErrorContext(); const { pushView, clearStackAndPushInitialView } = ViewContext.useViewContext(); const { displayedDestination: email } = VerificationContext.useVerification(); const handleMergeUserAccounts = () => _tslib.__awaiter(void 0, void 0, void 0, function* () { try { const userProfile = yield user.mergeUserAccounts(environmentId); if (!userProfile) { throw new utils.DynamicError('Something went wrong, please try again.'); } yield handleAuthenticatedUser(userProfile); setShowAuthFlow(false); setCallback('authSuccess'); } catch (e) { setError(t('dyn_merge_user_accounts_with_same_email.errors.merge_error')); if (user$1) { setShowAuthFlow(false, { emitCancelAuth: true }); return; } clearStackAndPushInitialView(); } }); const handleUseDifferentEmail = () => { setError(undefined); if (returnToView) { pushView(returnToView); return; } if (user$1) { setShowAuthFlow(false); return; } pushView('collect-user-data'); }; return (jsxRuntime.jsxs("div", { className: 'merge-user-accounts-with-same-email__container', children: [jsxRuntime.jsxs("div", { className: 'merge-user-accounts-with-same-email__accounts', children: [jsxRuntime.jsxs("div", { className: 'merge-user-accounts-with-same-email__accounts__item', children: [jsxRuntime.jsx(walletBook.WalletIcon, { icon: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.metadata.icon, walletKey: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.key, className: 'merge-user-accounts-with-same-email__accounts__item__icon' }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'medium', color: 'secondary', className: 'merge-user-accounts-with-same-email__accounts__item__text', children: shortenWalletAddress.shortenWalletAddress(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.address, 3, 3) })] }), jsxRuntime.jsx("div", { className: 'merge-user-accounts-with-same-email__accounts__divider', children: jsxRuntime.jsx(Icon.Icon, { color: 'text-secondary', size: 'small', children: jsxRuntime.jsx(doubleArrowRight.ReactComponent, {}) }) }), jsxRuntime.jsxs("div", { className: 'merge-user-accounts-with-same-email__accounts__item', children: [jsxRuntime.jsx(iconic.UserProfileIcon, { className: 'merge-user-accounts-with-same-email__accounts__item__icon' }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'medium', color: 'secondary', className: 'merge-user-accounts-with-same-email__accounts__item__text', children: shortenEmail.shortenEmail(email, { breakpoint: 4, cutEnd: 1, cutStart: 2, }) })] })] }), jsxRuntime.jsx(Typography.Typography, { weight: 'regular', variant: 'title', className: 'merge-user-accounts-with-same-email__text merge-user-accounts-with-same-email__text__header', copykey: 'dyn_merge_user_accounts_with_same_email.title', children: t('dyn_merge_user_accounts_with_same_email.title') }), jsxRuntime.jsxs(Typography.Typography, { weight: 'medium', variant: 'body_normal', className: 'merge-user-accounts-with-same-email__text merge-user-accounts-with-same-email__text__body', copykey: 'dyn_merge_user_accounts_with_same_email.existing_account', children: [t('dyn_merge_user_accounts_with_same_email.existing_account'), ' ', jsxRuntime.jsx("span", { className: 'merge-user-accounts-with-same-email__text--bold', children: shortenEmail.shortenEmail(email, { breakpoint: 14, }) }), ' ', t('dyn_merge_user_accounts_with_same_email.existing_account_trail')] }), jsxRuntime.jsxs("div", { className: 'merge-user-accounts-with-same-email__buttons', children: [jsxRuntime.jsx(TypographyButton.TypographyButton, { className: 'merge-user-accounts-with-same-email__buttons__button', onClick: handleMergeUserAccounts, buttonVariant: 'primary', buttonPadding: 'large', copykey: 'dyn_merge_user_accounts_with_same_email.confirm_button', children: t('dyn_merge_user_accounts_with_same_email.confirm_button') }), jsxRuntime.jsx(TypographyButton.TypographyButton, { className: 'merge-user-accounts-with-same-email__buttons__button', onClick: handleUseDifferentEmail, buttonVariant: 'secondary', buttonPadding: 'large', copykey: 'dyn_merge_user_accounts_with_same_email.cancel_button', children: t('dyn_merge_user_accounts_with_same_email.cancel_button') })] })] })); }; exports.MergeUserAccountsWithSameEmailView = MergeUserAccountsWithSameEmailView;