@turnkey/react-wallet-kit
Version:
The easiest and most powerful way to integrate Turnkey's Embedded Wallets into your React applications.
165 lines (162 loc) • 8.07 kB
JavaScript
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime, 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,
stampWith = props.stampWith;
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."]);
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, {
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__*/_regeneratorRuntime().mark(function _callee() {
var exportBundle;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
setIsLoading(true);
_context.prev = 1;
_context.t0 = exportType;
_context.next = _context.t0 === ExportType.Wallet ? 5 : _context.t0 === ExportType.PrivateKey ? 13 : _context.t0 === ExportType.WalletAccount ? 21 : 29;
break;
case 5:
_context.next = 7;
return exportWallet(_objectSpread2({
walletId: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}));
case 7:
exportBundle = _context.sent;
if (exportBundle) {
_context.next = 10;
break;
}
throw new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
case 10:
_context.next = 12;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectWalletExportBundle(exportBundle, session === null || session === void 0 ? void 0 : session.organizationId);
case 12:
return _context.abrupt("break", 30);
case 13:
_context.next = 15;
return exportPrivateKey(_objectSpread2({
privateKeyId: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}));
case 15:
exportBundle = _context.sent;
if (exportBundle) {
_context.next = 18;
break;
}
throw new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
case 18:
_context.next = 20;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectKeyExportBundle(exportBundle, session === null || session === void 0 ? void 0 : session.organizationId);
case 20:
return _context.abrupt("break", 30);
case 21:
_context.next = 23;
return exportWalletAccount(_objectSpread2({
address: target,
targetPublicKey: targetPublicKey || (exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.iframePublicKey)
}, stampWith && {
stampWith: stampWith
}));
case 23:
exportBundle = _context.sent;
if (exportBundle) {
_context.next = 26;
break;
}
throw new TurnkeyError("Failed to retrieve export bundle", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
case 26:
_context.next = 28;
return exportIframeClient === null || exportIframeClient === void 0 ? void 0 : exportIframeClient.injectKeyExportBundle(exportBundle, session === null || session === void 0 ? void 0 : session.organizationId);
case 28:
return _context.abrupt("break", 30);
case 29:
throw new TurnkeyError("Invalid export type", TurnkeyErrorCodes.EXPORT_WALLET_ERROR);
case 30:
if (props.setExportIframeVisible) {
props.setExportIframeVisible(true);
}
_context.next = 36;
break;
case 33:
_context.prev = 33;
_context.t1 = _context["catch"](1);
throw new TurnkeyError("Error exporting wallet", TurnkeyErrorCodes.EXPORT_WALLET_ERROR, _context.t1);
case 36:
_context.prev = 36;
setIsLoading(false);
return _context.finish(36);
case 39:
case "end":
return _context.stop();
}
}, _callee, null, [[1, 33, 36, 39]]);
}));
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