@dynamic-labs/sdk-react-core
Version:
A React SDK for implementing wallet web3 authentication and authorization to your website.
169 lines (164 loc) • 10.8 kB
JavaScript
'use client'
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var reactI18next = require('react-i18next');
var iconic = require('@dynamic-labs/iconic');
var DotsMenu = require('../../../components/DotsMenu/DotsMenu.cjs');
var classNames = require('../../../../../utils/functions/classNames/classNames.cjs');
require('../../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
var ViewContext = require('../../../../../context/ViewContext/ViewContext.cjs');
require('../../../../../../../_virtual/_tslib.cjs');
require('@dynamic-labs/sdk-api-core');
require('../../../../../shared/logger.cjs');
require('@dynamic-labs/wallet-connector-core');
require('@dynamic-labs/wallet-book');
require('@dynamic-labs/utils');
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');
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');
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');
require('../../../../../context/VerificationContext/VerificationContext.cjs');
require('react-dom');
require('../../../../../utils/functions/compareChains/compareChains.cjs');
require('../../../../../views/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');
require('yup');
require('../../../../../context/MockContext/MockContext.cjs');
require('../../../../../views/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('../../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
require('react-focus-lock');
var getPasskeyProviderFromUserAgent = require('../../../helpers/getPasskeyProviderFromUserAgent.cjs');
var getTimeSince = require('../../../helpers/getTimeSince.cjs');
require('../../../context/DynamicWidgetContext.cjs');
require('formik');
require('../../../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
require('../../../../../components/IconButton/IconButton.cjs');
require('../../../../../store/state/sendBalances.cjs');
require('../../../../../components/Input/Input.cjs');
require('../../../../../components/OverlayCard/OverlayCard.cjs');
require('../../../../../components/MenuList/Dropdown/Dropdown.cjs');
require('../../../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
var PasskeyContext = require('../../../../../context/PasskeyContext/PasskeyContext.cjs');
require('../../../../../context/OnrampContext/OnrampContext.cjs');
require('qrcode');
require('../../ReceiveWalletFunds/ReceiveWalletFunds.cjs');
require('../../../../../../index.cjs');
require('../../../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
require('../../../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
require('../../../../DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
require('@hcaptcha/react-hcaptcha');
require('../../../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
require('../../../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
require('../../../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 mapPasskeyProviderToIcon = {
android: jsxRuntime.jsx(iconic.AndroidIcon, {}),
brave: jsxRuntime.jsx(iconic.BraveIcon, {}),
chrome: jsxRuntime.jsx(iconic.ChromeIcon, {}),
edge: jsxRuntime.jsx(iconic.EdgeIcon, {}),
firefox: jsxRuntime.jsx(iconic.FirefoxIcon, {}),
iPhone: jsxRuntime.jsx(iconic.AppleIcon, {}),
opera: jsxRuntime.jsx(iconic.OperaIcon, {}),
safari: jsxRuntime.jsx(iconic.SafariIcon, {}),
};
const PasskeyCard = ({ passkey }) => {
var _a;
const { t } = reactI18next.useTranslation();
const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
const { pushView } = ViewContext.useViewContext();
const { setPasskey, setPasskeyIcon } = PasskeyContext.usePasskeyContext();
const menuOptions = [
{
Icon: null,
callback: () => {
setShowAuthFlow(true);
setPasskey(passkey);
setPasskeyIcon(() => { var _a; return (_a = PasskeyProviderIcon()) !== null && _a !== void 0 ? _a : undefined; });
pushView('rename-passkey');
},
text: 'Rename',
},
];
const [showTooltip, setShowTooltip] = React.useState(false);
const { value: timeSinceValue, unit: timeSinceUnit } = getTimeSince.getTimeSince(passkey.createdAt);
const PasskeyProviderIcon = () => {
if (!passkey.userAgent)
return null;
const provider = getPasskeyProviderFromUserAgent.getPasskeyProviderFromUserAgent(passkey.userAgent);
if (!provider)
return null;
return mapPasskeyProviderToIcon[provider];
};
const getPasskeyProviderName = () => {
if (!passkey.userAgent)
return null;
const provider = getPasskeyProviderFromUserAgent.getPasskeyProviderFromUserAgent(passkey.userAgent);
if (!provider)
return null;
return t(`dyn_manage_passkeys.passkey_providers.${provider}`);
};
const handleShowTooltip = () => {
setShowTooltip(true);
setTimeout(() => {
setShowTooltip(false);
}, 2000);
};
return (jsxRuntime.jsxs("div", { className: 'passkey-card', children: [jsxRuntime.jsx("div", { className: 'passkey-card__info', children: jsxRuntime.jsxs("div", { className: 'passkey-card__info__text', children: [jsxRuntime.jsxs(Typography.Typography, { "data-testid": 'passkey-alias', variant: 'body_normal', color: 'primary', title: passkey.alias, onClick: handleShowTooltip, children: [jsxRuntime.jsxs("div", { className: 'passkey-card__body', children: [jsxRuntime.jsxs("div", { className: 'passkey-card__left', children: [jsxRuntime.jsx("div", { className: 'passkey-card__info__icon', "data-testid": 'provider-icon', children: jsxRuntime.jsx(PasskeyProviderIcon, {}) }), ((_a = passkey.alias) === null || _a === void 0 ? void 0 : _a.includes('@'))
? shortenEmail.shortenEmail(passkey.alias, {
breakpoint: 12,
cutEnd: 4,
cutStart: 4,
})
: passkey.alias] }), jsxRuntime.jsx(DotsMenu.DotsMenu, { options: menuOptions })] }), jsxRuntime.jsx("span", { className: classNames.classNames('passkey-card__info__tooltip', {
'passkey-card__info__tooltip--visible': showTooltip,
}), children: passkey.alias })] }), getPasskeyProviderName() && (jsxRuntime.jsxs(Typography.Typography, { variant: 'body_small', color: 'secondary', children: [t('dyn_manage_passkeys.passkey_from'), " ", getPasskeyProviderName()] }))] }) }), jsxRuntime.jsx("div", { className: 'passkey-card__date', children: jsxRuntime.jsxs(Typography.Typography, { variant: 'body_small', color: 'secondary', copykey: 'dyn_time_since.created', children: [t('dyn_time_since.created'), ' ', `${timeSinceValue} ${timeSinceUnit} ${t('dyn_time_since.ago')}`] }) })] }));
};
exports.PasskeyCard = PasskeyCard;