@babylonlabs-io/core-ui 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  export declare const BTC_DECIMAL_PLACES = 8;
2
2
  export declare const BBN_DECIMAL_PLACES = 5;
3
3
  export declare const WINDOW_BREAKPOINT = 640;
4
+ export declare const MAX_WINDOW_HEIGHT = 500;
@@ -1,3 +1,4 @@
1
1
  export const BTC_DECIMAL_PLACES = 8;
2
2
  export const BBN_DECIMAL_PLACES = 5;
3
3
  export const WINDOW_BREAKPOINT = 640;
4
+ export const MAX_WINDOW_HEIGHT = 500;
@@ -23,6 +23,15 @@ interface PreviewModalProps {
23
23
  bsns: Info[];
24
24
  finalityProviders: Info[];
25
25
  details: StakingDetails;
26
+ /**
27
+ * When provided, only the specified field labels will be rendered in the itemised list.
28
+ * Labels should match the exact ones defined internally (e.g. "Stake Amount", "Transaction Fees").
29
+ */
30
+ visibleFields?: string[];
31
+ /** Custom notice text displayed under "Attention!" heading. If not provided, default disclaimers are shown. */
32
+ attentionText?: string;
33
+ /** Label for the primary action button; defaults to "Proceed to Signing" */
34
+ proceedLabel?: string;
26
35
  }
27
- export declare const PreviewModal: ({ open, processing, onClose, onProceed, bsns, finalityProviders, details, }: PropsWithChildren<PreviewModalProps>) => import("react/jsx-runtime").JSX.Element;
36
+ export declare const PreviewModal: ({ open, processing, onClose, onProceed, bsns, finalityProviders, details, visibleFields, attentionText, proceedLabel, }: PropsWithChildren<PreviewModalProps>) => import("react/jsx-runtime").JSX.Element;
28
37
  export {};
@@ -12,8 +12,8 @@ function ResponsiveDialog({ className, ...restProps }) {
12
12
  const DialogComponent = isMobileView ? MobileDialog : Dialog;
13
13
  return _jsx(DialogComponent, { ...restProps, className: twMerge("w-[41.25rem] max-w-full", className) });
14
14
  }
15
- export const PreviewModal = ({ open, processing = false, onClose, onProceed, bsns, finalityProviders, details, }) => {
16
- const fields = [
15
+ export const PreviewModal = ({ open, processing = false, onClose, onProceed, bsns, finalityProviders, details, visibleFields, attentionText, proceedLabel = "Proceed to Signing", }) => {
16
+ const allFields = [
17
17
  { label: "Stake Amount", value: details.stakeAmount },
18
18
  { label: "Fee Rate", value: details.feeRate },
19
19
  { label: "Transaction Fees", value: details.transactionFees },
@@ -24,14 +24,25 @@ export const PreviewModal = ({ open, processing = false, onClose, onProceed, bsn
24
24
  { label: "Unbonding", value: details.unbonding },
25
25
  { label: "Unbonding Fee", value: details.unbondingFee },
26
26
  ];
27
- return (_jsxs(ResponsiveDialog, { open: open, onClose: onClose, children: [_jsx(DialogHeader, { title: "Preview", onClose: onClose, className: "text-accent-primary" }), _jsxs(DialogBody, { className: "no-scrollbar mb-8 mt-4 flex max-h-[calc(100vh-12rem)] flex-col gap-4 overflow-y-auto text-accent-primary", children: [_jsx(Table, { data: [
28
- ["BSNs", "Finality Provider"],
29
- ...bsns.map((bsnItem, index) => {
30
- const fpItem = finalityProviders[index];
31
- return [
32
- _jsxs("div", { className: "flex w-full items-center justify-center gap-2 py-1", children: [bsnItem.icon, _jsx(Text, { variant: "body2", className: "font-medium", children: bsnItem.name })] }, `bsn-${index}`),
33
- fpItem ? (_jsxs("div", { className: "flex w-full items-center justify-center gap-2 py-1", children: [fpItem.icon, _jsx(Text, { variant: "body2", className: "font-medium", children: fpItem.name })] }, `fp-${index}`)) : (_jsx("div", {}, `fp-${index}`)),
34
- ];
35
- }),
36
- ] }), _jsx("div", { className: "flex flex-col", children: fields.map((field, index) => (_jsxs("div", { className: "flex flex-row items-center justify-between py-3", children: [_jsx(Text, { variant: "body1", className: "text-secondary font-normal", children: field.label }), _jsx(Text, { variant: "body1", className: "text-right font-normal", children: field.value })] }, index))) }), _jsx("div", { className: "border-divider w-full border-t" }), _jsxs("div", { className: "pt-2", children: [_jsx(Heading, { variant: "h6", className: "text-primary mb-2", children: "Attention!" }), _jsx(Text, { variant: "body2", className: "text-secondary", children: "1. No third party possesses your staked BTC. You are the only one who can unbond and withdraw your stake." }), _jsx(Text, { variant: "body2", className: "text-secondary", children: "2. Your stake will first be sent to Babylon Genesis for verification (~20 seconds), then you will be prompted to submit it to the Bitcoin ledger. It will be marked as 'Pending' until it receives 10 Bitcoin confirmations." })] })] }), _jsxs(DialogFooter, { className: "flex flex-col gap-4 pb-8 pt-0 sm:flex-row", children: [_jsx(Button, { variant: "contained", color: "primary", onClick: onProceed, className: "w-full sm:flex-1 sm:order-2", disabled: processing, children: processing ? "Processing..." : "Proceed to Signing" }), _jsx(Button, { variant: "outlined", color: "primary", onClick: onClose, className: "w-full sm:flex-1 sm:order-1", children: "Cancel" })] })] }));
27
+ const fields = visibleFields && visibleFields.length > 0 ? allFields.filter((f) => visibleFields.includes(f.label)) : allFields;
28
+ // If no finality providers are supplied, we display a single-column table labelled "Validator"
29
+ const isSingleColumn = !finalityProviders || finalityProviders.length === 0;
30
+ const tableData = isSingleColumn
31
+ ? [
32
+ ["Validator"],
33
+ ...bsns.map((item, index) => [
34
+ _jsxs("div", { className: "flex w-full items-center gap-2 py-1", children: [item.icon, _jsx(Text, { variant: "body2", className: "font-medium", children: item.name })] }, `validator-${index}`),
35
+ ]),
36
+ ]
37
+ : [
38
+ ["BSNs", "Finality Provider"],
39
+ ...bsns.map((bsnItem, index) => {
40
+ const fpItem = finalityProviders[index];
41
+ return [
42
+ _jsxs("div", { className: "flex w-full items-center gap-2 py-1", children: [bsnItem.icon, _jsx(Text, { variant: "body2", className: "font-medium", children: bsnItem.name })] }, `bsn-${index}`),
43
+ fpItem ? (_jsxs("div", { className: "flex w-full items-center gap-2 py-1", children: [fpItem.icon, _jsx(Text, { variant: "body2", className: "font-medium", children: fpItem.name })] }, `fp-${index}`)) : (_jsx("div", {}, `fp-${index}`)),
44
+ ];
45
+ }),
46
+ ];
47
+ return (_jsxs(ResponsiveDialog, { open: open, onClose: onClose, children: [_jsx(DialogHeader, { title: "Preview", onClose: onClose, className: "text-accent-primary" }), _jsxs(DialogBody, { className: "no-scrollbar mb-8 mt-4 flex max-h-[calc(100vh-12rem)] flex-col gap-4 overflow-y-auto text-accent-primary", children: [_jsx(Table, { data: tableData }), _jsx("div", { className: "flex flex-col", children: fields.map((field, index) => (_jsxs("div", { className: "flex flex-row items-center justify-between py-3", children: [_jsx(Text, { variant: "body1", className: "text-secondary font-normal", children: field.label }), _jsx(Text, { variant: "body1", className: "text-right font-normal", children: field.value })] }, index))) }), _jsx("div", { className: "border-divider w-full border-t" }), _jsxs("div", { className: "pt-2", children: [_jsx(Heading, { variant: "h6", className: "text-primary mb-2", children: "Attention!" }), attentionText ? (_jsx(Text, { variant: "body2", className: "text-secondary", children: attentionText })) : (_jsxs(_Fragment, { children: [_jsx(Text, { variant: "body2", className: "text-secondary", children: "1. No third party possesses your staked BTC. You are the only one who can unbond and withdraw your stake." }), _jsx(Text, { variant: "body2", className: "text-secondary", children: "2. Your stake will first be sent to Babylon Genesis for verification (~20 seconds), then you will be prompted to submit it to the Bitcoin ledger. It will be marked as 'Pending' until it receives 10 Bitcoin confirmations." })] }))] })] }), _jsxs(DialogFooter, { className: "flex flex-col gap-4 pb-8 pt-0 sm:flex-row", children: [_jsx(Button, { variant: "contained", color: "primary", onClick: onProceed, className: "w-full sm:flex-1 sm:order-2", disabled: processing, children: processing ? "Processing..." : proceedLabel }), _jsx(Button, { variant: "outlined", color: "primary", onClick: onClose, className: "w-full sm:flex-1 sm:order-1", children: "Cancel" })] })] }));
37
48
  };
@@ -4,3 +4,4 @@ declare const meta: Meta<typeof PreviewModal>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  export declare const Default: Story;
7
+ export declare const ValidatorOnly: Story;
@@ -45,3 +45,32 @@ export const Default = {
45
45
  },
46
46
  },
47
47
  };
48
+ export const ValidatorOnly = {
49
+ args: {
50
+ open: true,
51
+ processing: false,
52
+ onClose: () => { },
53
+ onProceed: () => { },
54
+ bsns: [
55
+ {
56
+ icon: _jsx(PlaceholderIcon, { text: "K", bgColor: "bg-black" }),
57
+ name: "Keplr",
58
+ },
59
+ ],
60
+ finalityProviders: [],
61
+ details: {
62
+ stakeAmount: "0.5 BTC",
63
+ feeRate: "5 sat/vB",
64
+ transactionFees: "0.0001 BTC",
65
+ term: {
66
+ blocks: "60000 blocks",
67
+ duration: "~ 60 weeks",
68
+ },
69
+ unbonding: "~ 1 day",
70
+ unbondingFee: "0 BTC",
71
+ },
72
+ visibleFields: ["Stake Amount", "Transaction Fees"],
73
+ attentionText: "The staking transaction may take up to one (1) hour to process. Funds will not be deducted instantly; a sufficient available balance must be maintained until the transaction is confirmed and the deduction is finalized.",
74
+ proceedLabel: "Stake",
75
+ },
76
+ };
@@ -0,0 +1,25 @@
1
+ import type { ColumnProps } from "@/components/Table/types";
2
+ import { ReactNode, PropsWithChildren } from "react";
3
+ export interface ValidatorRow {
4
+ id: string | number;
5
+ icon?: ReactNode;
6
+ name: string;
7
+ apr: string;
8
+ votingPower: string;
9
+ commission: string;
10
+ }
11
+ interface ValidatorSelectorProps {
12
+ open: boolean;
13
+ validators: ValidatorRow[];
14
+ /** Column configuration for the table */
15
+ columns: ColumnProps<ValidatorRow>[];
16
+ onClose: () => void;
17
+ /** Called when the user confirms selection. Provides selected validator row. */
18
+ onSelect: (validator: ValidatorRow) => void;
19
+ /** Optional title for the dialog – defaults to "Select Validator" */
20
+ title?: string;
21
+ /** Optional description text to display above the search input */
22
+ description?: string;
23
+ }
24
+ export declare const ValidatorSelector: ({ open, validators, columns, onClose, onSelect, title, description, }: PropsWithChildren<ValidatorSelectorProps>) => import("react/jsx-runtime").JSX.Element;
25
+ export {};
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Dialog, MobileDialog, DialogBody, DialogHeader } from "@/components/Dialog";
3
+ import { Table } from "@/components/Table";
4
+ import { Input } from "@/components/Form/Input";
5
+ import { Text } from "@/components/Text";
6
+ import { WINDOW_BREAKPOINT, MAX_WINDOW_HEIGHT } from "../../../utils/constants";
7
+ import { useIsMobile } from "@/hooks/useIsMobile";
8
+ import { useState, useMemo } from "react";
9
+ import { twMerge } from "tailwind-merge";
10
+ import { MdCancel } from "react-icons/md";
11
+ import { RiSearchLine } from "react-icons/ri";
12
+ function ResponsiveDialog({ className, ...restProps }) {
13
+ const isMobileView = useIsMobile(WINDOW_BREAKPOINT);
14
+ const DialogComponent = isMobileView ? MobileDialog : Dialog;
15
+ return _jsx(DialogComponent, { ...restProps, className: twMerge("w-[41.25rem] max-w-full", className) });
16
+ }
17
+ export const ValidatorSelector = ({ open, validators, columns, onClose, onSelect, title = "", description, }) => {
18
+ const [searchTerm, setSearchTerm] = useState("");
19
+ const onClearSearch = () => {
20
+ setSearchTerm("");
21
+ };
22
+ const searchPrefix = searchTerm ? (_jsx("button", { onClick: onClearSearch, className: "opacity-60 hover:opacity-100 transition-opacity", children: _jsx(MdCancel, { size: 18, className: "text-secondary-strokeDark" }) })) : (_jsx("span", { className: "text-secondary-strokeDark", children: _jsx(RiSearchLine, { size: 20 }) }));
23
+ const filteredValidators = useMemo(() => {
24
+ if (!searchTerm.trim())
25
+ return validators;
26
+ return validators.filter((validator) => validator.name.toLowerCase().includes(searchTerm.toLowerCase()));
27
+ }, [validators, searchTerm]);
28
+ return (_jsxs(ResponsiveDialog, { open: open, onClose: onClose, children: [_jsx(DialogHeader, { title: title, onClose: onClose, className: "text-accent-primary" }), _jsxs(DialogBody, { style: { maxHeight: MAX_WINDOW_HEIGHT }, className: "no-scrollbar mt-4 flex flex-col gap-6 overflow-y-auto text-accent-primary", children: [description && (_jsx("div", { children: _jsx(Text, { variant: "body2", className: "text-accent-secondary", children: description }) })), _jsx("div", { children: _jsx(Input, { placeholder: "Search", value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), prefix: searchPrefix, className: "w-full" }) }), _jsx(Table, { data: filteredValidators, columns: columns, className: "w-full", wrapperClassName: "w-full", onRowSelect: (row) => {
29
+ if (row) {
30
+ onSelect(row);
31
+ onClose();
32
+ }
33
+ } })] })] }));
34
+ };
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { ValidatorSelector } from "./ValidatorSelector";
3
+ declare const meta: Meta<typeof ValidatorSelector>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof meta>;
6
+ export declare const Default: Story;
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ValidatorSelector } from "./ValidatorSelector";
3
+ import { FinalityProviderLogo } from "@/elements/FinalityProviderLogo";
4
+ const sampleValidators = Array.from({ length: 15 }, (_, i) => {
5
+ const index = i + 1;
6
+ return {
7
+ id: index,
8
+ icon: (_jsx(FinalityProviderLogo, { rank: index, moniker: `V${index}`, size: "sm" })),
9
+ name: `Validator ${index}`,
10
+ apr: `${25 + (index % 6)}.${(index * 7) % 100}`.padEnd(6, "0") + "%", // simple varied APR
11
+ votingPower: `${(Math.random() * 1).toFixed(6)} sBTC`,
12
+ commission: `${2 + (index % 5)}%`,
13
+ };
14
+ });
15
+ const columns = [
16
+ {
17
+ key: "name",
18
+ header: "Validator",
19
+ sorter: (a, b) => a.name.localeCompare(b.name),
20
+ render: (_value, row) => (_jsxs("div", { className: "flex items-center gap-2", children: [row.icon, _jsx("span", { children: row.name })] })),
21
+ },
22
+ { key: "apr", header: "Expected APR" },
23
+ {
24
+ key: "votingPower",
25
+ header: "Voting Power",
26
+ sorter: (a, b) => {
27
+ const parse = (str) => parseFloat(str.split(" ")[0]);
28
+ return parse(a.votingPower) - parse(b.votingPower);
29
+ },
30
+ },
31
+ {
32
+ key: "commission",
33
+ header: "Commission",
34
+ sorter: (a, b) => parseFloat(a.commission) - parseFloat(b.commission),
35
+ },
36
+ ];
37
+ const meta = {
38
+ component: ValidatorSelector,
39
+ tags: ["autodocs"],
40
+ };
41
+ export default meta;
42
+ export const Default = {
43
+ args: {
44
+ open: true,
45
+ validators: sampleValidators,
46
+ columns,
47
+ title: "Select Validator",
48
+ description: "Validators are responsible for verifying transactions, proposing and confirming new blocks, and helping maintain the security and consensus of Babylon Genesis.",
49
+ onClose: () => { },
50
+ onSelect: (validator) => alert(`Selected ${validator.name}`),
51
+ },
52
+ };
@@ -0,0 +1 @@
1
+ export { ValidatorSelector } from "./ValidatorSelector";
@@ -0,0 +1 @@
1
+ export { ValidatorSelector } from "./ValidatorSelector";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonlabs-io/core-ui",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {