@aptos-labs/wallet-adapter-ant-design
Version:
Aptos Wallet Adapter ant-design
248 lines (246 loc) • 9.96 kB
JavaScript
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
// src/WalletSelector.tsx
import { ArrowLeftOutlined, ArrowRightOutlined } from "@ant-design/icons";
import {
AboutAptosConnect,
AptosPrivacyPolicy,
WalletItem,
groupAndSortWallets,
isInstallRequired,
truncateAddress,
useWallet
} from "@aptos-labs/wallet-adapter-react";
import {
Button,
Collapse,
Divider,
Flex,
Modal,
Typography
} from "antd";
import { useEffect, useState } from "react";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var { Text } = Typography;
function WalletSelector(_a) {
var _b = _a, {
isModalOpen,
setModalOpen
} = _b, walletSortingOptions = __objRest(_b, [
"isModalOpen",
"setModalOpen"
]);
var _a2;
const [walletSelectorModalOpen, setWalletSelectorModalOpen] = useState(false);
useEffect(() => {
if (isModalOpen !== void 0) {
setWalletSelectorModalOpen(isModalOpen);
}
}, [isModalOpen]);
const {
account,
connected,
disconnect,
wallets = [],
notDetectedWallets = []
} = useWallet();
const { aptosConnectWallets, availableWallets, installableWallets } = groupAndSortWallets(
[...wallets, ...notDetectedWallets],
walletSortingOptions
);
const hasAptosConnectWallets = !!aptosConnectWallets.length;
const onWalletButtonClick = () => {
if (connected) {
disconnect();
} else {
setWalletSelectorModalOpen(true);
}
};
const closeModal = () => {
setWalletSelectorModalOpen(false);
if (setModalOpen) {
setModalOpen(false);
}
};
const buttonText = (account == null ? void 0 : account.ansName) || truncateAddress((_a2 = account == null ? void 0 : account.address) == null ? void 0 : _a2.toString()) || "Unknown";
const modalProps = {
centered: true,
open: walletSelectorModalOpen,
onCancel: closeModal,
footer: null,
zIndex: 9999,
className: "wallet-selector-modal"
};
const renderEducationScreens = (screen) => /* @__PURE__ */ jsxs(
Modal,
__spreadProps(__spreadValues({}, modalProps), {
afterClose: screen.cancel,
title: /* @__PURE__ */ jsxs("div", { className: "about-aptos-connect-header", children: [
/* @__PURE__ */ jsx(
Button,
{
type: "text",
icon: /* @__PURE__ */ jsx(ArrowLeftOutlined, {}),
onClick: screen.cancel
}
),
/* @__PURE__ */ jsx("div", { className: "wallet-modal-title", children: "About Aptos Connect" })
] }),
children: [
/* @__PURE__ */ jsx("div", { className: "about-aptos-connect-graphic-wrapper", children: /* @__PURE__ */ jsx(screen.Graphic, {}) }),
/* @__PURE__ */ jsxs("div", { className: "about-aptos-connect-text-wrapper", children: [
/* @__PURE__ */ jsx(screen.Title, { className: "about-aptos-connect-title" }),
/* @__PURE__ */ jsx(screen.Description, { className: "about-aptos-connect-description" })
] }),
/* @__PURE__ */ jsxs("div", { className: "about-aptos-connect-footer-wrapper", children: [
/* @__PURE__ */ jsx(
Button,
{
type: "text",
style: { justifySelf: "start" },
onClick: screen.back,
children: "Back"
}
),
/* @__PURE__ */ jsx("div", { className: "about-aptos-connect-screen-indicators-wrapper", children: screen.screenIndicators.map((ScreenIndicator, i) => /* @__PURE__ */ jsx(
ScreenIndicator,
{
className: "about-aptos-connect-screen-indicator",
children: /* @__PURE__ */ jsx("div", {})
},
i
)) }),
/* @__PURE__ */ jsx(
Button,
{
type: "text",
icon: /* @__PURE__ */ jsx(ArrowRightOutlined, {}),
iconPosition: "end",
style: { justifySelf: "end" },
onClick: screen.next,
children: screen.screenIndex === screen.totalScreens - 1 ? "Finish" : "Next"
}
)
] })
]
})
);
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(Button, { className: "wallet-button", onClick: onWalletButtonClick, children: connected ? buttonText : "Connect Wallet" }),
/* @__PURE__ */ jsx(AboutAptosConnect, { renderEducationScreen: renderEducationScreens, children: /* @__PURE__ */ jsx(
Modal,
__spreadProps(__spreadValues({}, modalProps), {
title: /* @__PURE__ */ jsx("div", { className: "wallet-modal-title", children: hasAptosConnectWallets ? /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx("span", { children: "Log in or sign up" }),
/* @__PURE__ */ jsx("span", { children: "with Social + Aptos Connect" })
] }) : "Connect Wallet" }),
children: !connected && /* @__PURE__ */ jsxs(Fragment, { children: [
hasAptosConnectWallets && /* @__PURE__ */ jsxs(Flex, { vertical: true, gap: 12, children: [
aptosConnectWallets.map((wallet) => /* @__PURE__ */ jsx(
AptosConnectWalletRow,
{
wallet,
onConnect: closeModal
},
wallet.name
)),
/* @__PURE__ */ jsxs("p", { className: "about-aptos-connect-trigger-wrapper", children: [
"Learn more about",
" ",
/* @__PURE__ */ jsxs(AboutAptosConnect.Trigger, { className: "about-aptos-connect-trigger", children: [
"Aptos Connect",
/* @__PURE__ */ jsx(ArrowRightOutlined, {})
] })
] }),
/* @__PURE__ */ jsxs(AptosPrivacyPolicy, { className: "aptos-connect-privacy-policy-wrapper", children: [
/* @__PURE__ */ jsxs("p", { className: "aptos-connect-privacy-policy-text", children: [
/* @__PURE__ */ jsx(AptosPrivacyPolicy.Disclaimer, {}),
" ",
/* @__PURE__ */ jsx(AptosPrivacyPolicy.Link, { className: "aptos-connect-privacy-policy-link" }),
/* @__PURE__ */ jsx("span", { children: "." })
] }),
/* @__PURE__ */ jsx(AptosPrivacyPolicy.PoweredBy, { className: "aptos-connect-powered-by" })
] }),
/* @__PURE__ */ jsx(Divider, { children: "Or" })
] }),
/* @__PURE__ */ jsx(Flex, { vertical: true, gap: 12, children: availableWallets.map((wallet) => /* @__PURE__ */ jsx(
WalletRow,
{
wallet,
onConnect: closeModal
},
wallet.name
)) }),
!!installableWallets.length && /* @__PURE__ */ jsx(
Collapse,
{
ghost: true,
expandIconPosition: "end",
items: [
{
key: "more-wallets",
label: "More Wallets",
children: /* @__PURE__ */ jsx(Flex, { vertical: true, gap: 12, children: installableWallets.map((wallet) => /* @__PURE__ */ jsx(
WalletRow,
{
wallet,
onConnect: closeModal
},
wallet.name
)) })
}
]
}
)
] })
})
) })
] });
}
function WalletRow({ wallet, onConnect }) {
return /* @__PURE__ */ jsx(WalletItem, { wallet, onConnect, asChild: true, children: /* @__PURE__ */ jsxs("div", { className: "wallet-menu-wrapper", children: [
/* @__PURE__ */ jsxs("div", { className: "wallet-name-wrapper", children: [
/* @__PURE__ */ jsx(WalletItem.Icon, { className: "wallet-selector-icon" }),
/* @__PURE__ */ jsx(WalletItem.Name, { asChild: true, children: /* @__PURE__ */ jsx(Text, { className: "wallet-selector-text", children: wallet.name }) })
] }),
isInstallRequired(wallet) ? /* @__PURE__ */ jsx(WalletItem.InstallLink, { className: "wallet-connect-install" }) : /* @__PURE__ */ jsx(WalletItem.ConnectButton, { asChild: true, children: /* @__PURE__ */ jsx(Button, { className: "wallet-connect-button", children: "Connect" }) })
] }) });
}
function AptosConnectWalletRow({ wallet, onConnect }) {
return /* @__PURE__ */ jsx(WalletItem, { wallet, onConnect, asChild: true, children: /* @__PURE__ */ jsx(WalletItem.ConnectButton, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { size: "large", className: "aptos-connect-button", children: [
/* @__PURE__ */ jsx(WalletItem.Icon, { className: "wallet-selector-icon" }),
/* @__PURE__ */ jsx(WalletItem.Name, {})
] }) }) });
}
export {
WalletSelector
};