@turnkey/react-wallet-kit
Version:
The easiest and most powerful way to integrate Turnkey's Embedded Wallets into your React applications.
168 lines (165 loc) • 8.22 kB
JavaScript
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
import { jsxs, jsx } from 'react/jsx-runtime';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTriangleExclamation, faUnlock, faEye } from '@fortawesome/free-solid-svg-icons';
import { ExportType } from '../../types/base.mjs';
import { useTurnkey } from '../../providers/client/Hook.mjs';
import { TurnkeyError, TurnkeyErrorCodes } from '@turnkey/sdk-types';
import { ActionButton } from '../design/Buttons.mjs';
import { useState } from 'react';
function ExportWarning(props) {
var target = props.target,
exportIframeClient = props.exportIframeClient,
targetPublicKey = props.targetPublicKey,
exportType = props.exportType,
keyFormat = props.keyFormat,
stampWith = props.stampWith,
onError = props.onError;
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isLoading = _useState2[0],
setIsLoading = _useState2[1];
var _useTurnkey = useTurnkey(),
exportWallet = _useTurnkey.exportWallet,
exportPrivateKey = _useTurnkey.exportPrivateKey,
exportWalletAccount = _useTurnkey.exportWalletAccount,
session = _useTurnkey.session;
var warnings = _defineProperty(_defineProperty(_defineProperty({}, 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."]), 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."]), 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."]);
var organizationId = props.organizationId || (session === null || session === void 0 ? void 0 : session.organizationId);
if (!organizationId) {
throw new TurnkeyError("Organization ID is required for exporting.", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
}
return jsxs("div", {
className: "flex flex-col w-full px-10",
children: [jsxs("div", {
className: "flex flex-col gap-4 py-6 text-icon-text-light dark:text-icon-text-dark",
children: [jsx(IconText, {
icon: faTriangleExclamation,
text: warnings[exportType][0]
}), jsx(IconText, {
icon: faUnlock,
text: warnings[exportType][1]
}), jsx(IconText, {
icon: faEye,
text: warnings[exportType][2]
})]
}), jsx(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: function () {
var _onClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
var exportBundle, _t, _t2;
return _regenerator().w(function (_context) {
while (1) switch (_context.p = _context.n) {
case 0:
setIsLoading(true);
_context.p = 1;
_t = exportType;
_context.n = _t === ExportType.Wallet ? 2 : _t === ExportType.PrivateKey ? 5 : _t === ExportType.WalletAccount ? 8 : 11;
break;
case 2:
_context.n = 3;
return exportWallet(_objectSpread2(_objectSpread2({
walletId: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}), {}, {
organizationId: organizationId
}));
case 3:
exportBundle = _context.v;
if (!exportBundle) {
onError(new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR));
}
_context.n = 4;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectWalletExportBundle(exportBundle, organizationId);
case 4:
return _context.a(3, 12);
case 5:
_context.n = 6;
return exportPrivateKey(_objectSpread2(_objectSpread2({
privateKeyId: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}), {}, {
organizationId: organizationId
}));
case 6:
exportBundle = _context.v;
if (!exportBundle) {
onError(new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR));
}
_context.n = 7;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectKeyExportBundle(exportBundle, session === null || session === void 0 ? void 0 : session.organizationId, keyFormat);
case 7:
return _context.a(3, 12);
case 8:
_context.n = 9;
return exportWalletAccount(_objectSpread2(_objectSpread2({
address: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}), {}, {
organizationId: organizationId
}));
case 9:
exportBundle = _context.v;
if (!exportBundle) {
onError(new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR));
}
_context.n = 10;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectKeyExportBundle(exportBundle, session === null || session === void 0 ? void 0 : session.organizationId, keyFormat);
case 10:
return _context.a(3, 12);
case 11:
throw new TurnkeyError("Invalid export type", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
case 12:
if (props.setExportIframeVisible) {
props.setExportIframeVisible(true);
}
_context.n = 14;
break;
case 13:
_context.p = 13;
_t2 = _context.v;
onError(new TurnkeyError("Error exporting wallet", TurnkeyErrorCodes.EXPORT_WALLET_ERROR, _t2));
case 14:
_context.p = 14;
setIsLoading(false);
return _context.f(14);
case 15:
return _context.a(2);
}
}, _callee, null, [[1, 13, 14, 15]]);
}));
function onClick() {
return _onClick.apply(this, arguments);
}
return onClick;
}(),
children: exportType === ExportType.PrivateKey ? "Export Private Key" : "Export Wallet"
})]
});
}
function IconText(props) {
return jsxs("div", {
className: "flex items-center gap-4",
children: [jsx("div", {
className: "w-6 h-fit shrink-0 flex items-center justify-center",
children: jsx(FontAwesomeIcon, {
size: "lg",
icon: props.icon
})
}), jsx("span", {
className: "text-sm",
children: props.text
})]
});
}
export { ExportWarning };
//# sourceMappingURL=ExportWarning.mjs.map