UNPKG

@turnkey/react-wallet-kit

Version:

The easiest and most powerful way to integrate Turnkey's Embedded Wallets into your React applications.

138 lines (134 loc) 5.81 kB
'use strict'; var jsxRuntime = require('react/jsx-runtime'); var reactFontawesome = require('@fortawesome/react-fontawesome'); var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons'); var base = require('../../types/base.js'); var Hook = require('../../providers/client/Hook.js'); var sdkTypes = require('@turnkey/sdk-types'); var Buttons = require('../design/Buttons.js'); var react = require('react'); function ExportWarning(props) { const { target, exportIframeClient, targetPublicKey, exportType, keyFormat, stampWith, onError } = props; const [isLoading, setIsLoading] = react.useState(false); const { exportWallet, exportPrivateKey, exportWalletAccount, session } = Hook.useTurnkey(); const warnings = { [base.ExportType.Wallet]: ["Keep your seed phrase private.", "Anyone who has your seed phrase can access your wallet.", "Make sure nobody can see your screen when viewing your seed phrase."], [base.ExportType.PrivateKey]: ["Keep your private key private.", "Anyone who has your private key can access your wallet.", "Make sure nobody can see your screen when viewing your private key."], [base.ExportType.WalletAccount]: ["Keep your account details private.", "Anyone who has your account details can access your wallet.", "Make sure nobody can see your screen when viewing your account details."] }; const organizationId = props.organizationId || session?.organizationId; if (!organizationId) { throw new sdkTypes.TurnkeyError("Organization ID is required for exporting.", sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR); } return jsxRuntime.jsxs("div", { className: "flex flex-col w-full px-10", children: [jsxRuntime.jsxs("div", { className: "flex flex-col gap-4 py-6 text-icon-text-light dark:text-icon-text-dark", children: [jsxRuntime.jsx(IconText, { icon: freeSolidSvgIcons.faTriangleExclamation, text: warnings[exportType][0] }), jsxRuntime.jsx(IconText, { icon: freeSolidSvgIcons.faUnlock, text: warnings[exportType][1] }), jsxRuntime.jsx(IconText, { icon: freeSolidSvgIcons.faEye, text: warnings[exportType][2] })] }), jsxRuntime.jsx(Buttons.ActionButton, { name: "confirm-export-warning-button", loading: isLoading, spinnerClassName: "text-primary-text-light dark:text-primary-text-dark", className: "text-primary-text-light dark:text-primary-text-dark bg-primary-light dark:bg-primary-dark", onClick: async () => { setIsLoading(true); try { let exportBundle; switch (exportType) { case base.ExportType.Wallet: exportBundle = await exportWallet({ walletId: target, targetPublicKey: targetPublicKey || exportIframeClient?.iframePublicKey, ...(stampWith && { stampWith: stampWith }), organizationId }); if (!exportBundle) { onError(new sdkTypes.TurnkeyError("Failed to retrieve export bundle", sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR)); } await exportIframeClient?.injectWalletExportBundle(exportBundle, organizationId); break; case base.ExportType.PrivateKey: exportBundle = await exportPrivateKey({ privateKeyId: target, targetPublicKey: targetPublicKey || exportIframeClient?.iframePublicKey, ...(stampWith && { stampWith: stampWith }), organizationId }); if (!exportBundle) { onError(new sdkTypes.TurnkeyError("Failed to retrieve export bundle", sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR)); } await exportIframeClient?.injectKeyExportBundle(exportBundle, session?.organizationId, keyFormat); break; case base.ExportType.WalletAccount: exportBundle = await exportWalletAccount({ address: target, targetPublicKey: targetPublicKey || exportIframeClient?.iframePublicKey, ...(stampWith && { stampWith: stampWith }), organizationId }); if (!exportBundle) { onError(new sdkTypes.TurnkeyError("Failed to retrieve export bundle", sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR)); } await exportIframeClient?.injectKeyExportBundle(exportBundle, session?.organizationId, keyFormat); break; default: throw new sdkTypes.TurnkeyError("Invalid export type", sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR); } if (props.setExportIframeVisible) { props.setExportIframeVisible(true); } } catch (error) { onError(new sdkTypes.TurnkeyError(`Error exporting wallet`, sdkTypes.TurnkeyErrorCodes.EXPORT_WALLET_ERROR, error)); } finally { setIsLoading(false); } }, children: exportType === base.ExportType.PrivateKey ? "Export Private Key" : "Export Wallet" })] }); } function IconText(props) { return jsxRuntime.jsxs("div", { className: "flex items-center gap-4", children: [jsxRuntime.jsx("div", { className: "w-6 h-fit shrink-0 flex items-center justify-center", children: jsxRuntime.jsx(reactFontawesome.FontAwesomeIcon, { size: "lg", icon: props.icon }) }), jsxRuntime.jsx("span", { className: "text-sm", children: props.text })] }); } exports.ExportWarning = ExportWarning; //# sourceMappingURL=ExportWarning.js.map