@turnkey/react-wallet-kit
Version:
The easiest and most powerful way to integrate Turnkey's Embedded Wallets into your React applications.
163 lines (160 loc) • 6.79 kB
JavaScript
import { asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
import { jsx } from 'react/jsx-runtime';
import { ExternalWalletSelector, UnlinkWalletScreen, WalletConnectScreen } from '../auth/Wallet.mjs';
import { useModal } from '../../providers/modal/Hook.mjs';
import { useTurnkey } from '../../providers/client/Hook.mjs';
import { ActionPage } from '../auth/Action.mjs';
import { SuccessPage } from '../design/Success.mjs';
import { isWalletConnect } from '../../utils.mjs';
function LinkWalletModal(props) {
var providers = props.providers,
successPageDuration = props.successPageDuration;
var _useModal = useModal(),
pushPage = _useModal.pushPage,
closeModal = _useModal.closeModal;
var _useTurnkey = useTurnkey(),
connectWalletAccount = _useTurnkey.connectWalletAccount,
disconnectWalletAccount = _useTurnkey.disconnectWalletAccount;
var handleLinkWallet = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(provider) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
if (!isWalletConnect(provider)) {
_context2.next = 3;
break;
}
// for WalletConnect we route to a dedicated screen
// to handle the connection process, as it requires a different flow (pairing via QR code or deep link)
pushPage({
key: "Link WalletConnect",
content: jsx(WalletConnectScreen, {
provider: provider,
onAction: connectWalletAccount,
successPageDuration: successPageDuration
})
});
return _context2.abrupt("return");
case 3:
pushPage({
key: "Link ".concat(provider.info.name),
content: jsx(ActionPage, {
title: "Linking ".concat(provider.info.name),
icon: jsx("img", {
className: "size-11 rounded-full",
src: provider.info.icon || ""
}),
closeOnComplete: false,
action: function () {
var _action = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return connectWalletAccount(provider);
case 2:
if (successPageDuration && successPageDuration > 0) {
pushPage({
key: "Link Success",
content: jsx(SuccessPage, {
text: "Successfully linked wallet!",
onComplete: function onComplete() {
return closeModal();
},
duration: successPageDuration
}),
preventBack: true,
showTitle: false
});
} else {
closeModal();
}
case 3:
case "end":
return _context.stop();
}
}, _callee);
}));
function action() {
return _action.apply(this, arguments);
}
return action;
}()
}),
showTitle: false
});
case 4:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function handleLinkWallet(_x) {
return _ref.apply(this, arguments);
};
}();
var handleUnlinkWallet = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(provider) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
pushPage({
key: "Unlink ".concat(provider.info.name),
content: jsx(UnlinkWalletScreen, {
provider: provider,
onUnlink: function () {
var _onUnlink = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return disconnectWalletAccount(provider);
case 2:
if (successPageDuration) {
pushPage({
key: "Unlink Success",
content: jsx(SuccessPage, {
text: "Successfully unlinked wallet!",
onComplete: function onComplete() {
return closeModal();
},
duration: successPageDuration
}),
preventBack: true,
showTitle: false
});
} else {
closeModal();
}
case 3:
case "end":
return _context3.stop();
}
}, _callee3);
}));
function onUnlink() {
return _onUnlink.apply(this, arguments);
}
return onUnlink;
}()
}),
showTitle: false
});
case 1:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return function handleUnlinkWallet(_x2) {
return _ref2.apply(this, arguments);
};
}();
return jsx(ExternalWalletSelector, {
providers: providers,
onSelect: handleLinkWallet,
onUnlink: handleUnlinkWallet
});
}
export { LinkWalletModal };
//# sourceMappingURL=LinkWallet.mjs.map