@babylonlabs-io/core-ui 1.21.0 → 1.23.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.
@@ -12,9 +12,10 @@ interface Props {
12
12
  placeholder?: string;
13
13
  displayBalance?: boolean;
14
14
  balanceDetails?: BalanceDetails;
15
+ prefix?: string;
15
16
  min?: string;
16
17
  step?: string;
17
18
  autoFocus?: boolean;
18
19
  }
19
- export declare const AmountSubsection: ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder, balanceDetails, min, step, autoFocus, }: Props) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const AmountSubsection: ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder, balanceDetails, prefix, min, step, autoFocus, }: Props) => import("react/jsx-runtime").JSX.Element;
20
21
  export {};
@@ -5,7 +5,7 @@ import { useFormContext, useWatch } from "react-hook-form";
5
5
  import { AmountItem } from "../../../components/AmountItem/AmountItem";
6
6
  import { calculateTokenValueInCurrency, maxDecimals } from "@/utils/helpers";
7
7
  import { BTC_DECIMAL_PLACES } from "@/utils/constants";
8
- export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder = "Enter Amount", balanceDetails, min = "0", step = "any", autoFocus = true, }) => {
8
+ export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displayBalance, placeholder = "Enter Amount", balanceDetails, prefix, min = "0", step = "any", autoFocus = true, }) => {
9
9
  const amount = useWatch({ name: fieldName, defaultValue: "" });
10
10
  const { setValue } = useFormContext();
11
11
  const amountValue = parseFloat(amount || "0");
@@ -24,6 +24,12 @@ export const AmountSubsection = ({ fieldName, currencyIcon, currencyName, displa
24
24
  e.preventDefault();
25
25
  }
26
26
  };
27
- const subtitle = `Stakable: ${maxDecimals(Number(balanceDetails?.balance), balanceDetails?.decimals ?? BTC_DECIMAL_PLACES)} ${balanceDetails?.symbol}`;
27
+ let subtitle;
28
+ if (balanceDetails) {
29
+ subtitle = `${maxDecimals(Number(balanceDetails.balance), balanceDetails.decimals ?? BTC_DECIMAL_PLACES)} ${balanceDetails.symbol}`;
30
+ if (prefix) {
31
+ subtitle = `${prefix}: ${subtitle}`;
32
+ }
33
+ }
28
34
  return (_jsxs(_Fragment, { children: [_jsx(HiddenField, { name: fieldName, defaultValue: "" }), _jsx(SubSection, { className: "flex w-full flex-col content-center justify-between gap-4", children: _jsx(AmountItem, { amount: amount, currencyIcon: currencyIcon, currencyName: currencyName, placeholder: placeholder, displayBalance: displayBalance, balanceDetails: balanceDetails, min: min, step: step, autoFocus: autoFocus, onChange: handleInputChange, onKeyDown: handleKeyDown, amountUsd: amountUsd, subtitle: subtitle }) })] }));
29
35
  };
@@ -4,3 +4,12 @@ declare const meta: Meta<typeof AmountSubsection>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  export declare const Default: Story;
7
+ export declare const WithoutBalance: Story;
8
+ export declare const BitcoinCurrency: Story;
9
+ export declare const LargeBalance: Story;
10
+ export declare const WithoutUSDPrice: Story;
11
+ export declare const ZeroBalance: Story;
12
+ export declare const SmallBalance: Story;
13
+ export declare const NoAutoFocus: Story;
14
+ export declare const CustomMinStep: Story;
15
+ export declare const NoPrefix: Story;
@@ -20,6 +20,7 @@ export const Default = {
20
20
  currencyIcon: "https://placehold.co/40x40",
21
21
  currencyName: "BBN",
22
22
  placeholder: "Enter Amount",
23
+ prefix: "Stakable",
23
24
  displayBalance: true,
24
25
  balanceDetails: {
25
26
  balance: 1234.56789,
@@ -33,3 +34,176 @@ export const Default = {
33
34
  (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
34
35
  ],
35
36
  };
37
+ export const WithoutBalance = {
38
+ args: {
39
+ fieldName: "amount",
40
+ currencyIcon: "https://placehold.co/40x40",
41
+ currencyName: "BBN",
42
+ placeholder: "Enter staking amount",
43
+ displayBalance: false,
44
+ },
45
+ decorators: [
46
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
47
+ ],
48
+ };
49
+ export const BitcoinCurrency = {
50
+ args: {
51
+ fieldName: "amount",
52
+ currencyIcon: "https://placehold.co/40x40/FF9500/FFFFFF?text=₿",
53
+ currencyName: "BTC",
54
+ placeholder: "Enter BTC amount",
55
+ prefix: "Available",
56
+ displayBalance: true,
57
+ balanceDetails: {
58
+ balance: 0.12345678,
59
+ symbol: "BTC",
60
+ price: 65000,
61
+ displayUSD: true,
62
+ decimals: 8,
63
+ },
64
+ },
65
+ decorators: [
66
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
67
+ ],
68
+ };
69
+ export const LargeBalance = {
70
+ args: {
71
+ fieldName: "amount",
72
+ currencyIcon: "https://placehold.co/40x40/4CAF50/FFFFFF?text=T",
73
+ currencyName: "USDT",
74
+ placeholder: "Enter USDT amount",
75
+ prefix: "Total",
76
+ displayBalance: true,
77
+ balanceDetails: {
78
+ balance: 1000000.123456,
79
+ symbol: "USDT",
80
+ price: 1.0,
81
+ displayUSD: true,
82
+ decimals: 6,
83
+ },
84
+ },
85
+ decorators: [
86
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
87
+ ],
88
+ };
89
+ export const WithoutUSDPrice = {
90
+ args: {
91
+ fieldName: "amount",
92
+ currencyIcon: "https://placehold.co/40x40/8B5CF6/FFFFFF?text=S",
93
+ currencyName: "SOL",
94
+ placeholder: "Enter amount",
95
+ prefix: "Delegated",
96
+ displayBalance: true,
97
+ balanceDetails: {
98
+ balance: 500.789,
99
+ symbol: "SOL",
100
+ displayUSD: false,
101
+ decimals: 9,
102
+ },
103
+ },
104
+ decorators: [
105
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
106
+ ],
107
+ };
108
+ export const ZeroBalance = {
109
+ args: {
110
+ fieldName: "amount",
111
+ currencyIcon: "https://placehold.co/40x40/E53E3E/FFFFFF?text=X",
112
+ currencyName: "XRP",
113
+ placeholder: "Enter XRP amount",
114
+ prefix: "Available",
115
+ displayBalance: true,
116
+ balanceDetails: {
117
+ balance: 0,
118
+ symbol: "XRP",
119
+ price: 0.5,
120
+ displayUSD: true,
121
+ decimals: 6,
122
+ },
123
+ },
124
+ decorators: [
125
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
126
+ ],
127
+ };
128
+ export const SmallBalance = {
129
+ args: {
130
+ fieldName: "amount",
131
+ currencyIcon: "https://placehold.co/40x40/627EEA/FFFFFF?text=Ξ",
132
+ currencyName: "ETH",
133
+ placeholder: "Enter ETH amount",
134
+ prefix: "Staked",
135
+ displayBalance: true,
136
+ balanceDetails: {
137
+ balance: 0.000123456789,
138
+ symbol: "ETH",
139
+ price: 3500,
140
+ displayUSD: true,
141
+ decimals: 18,
142
+ },
143
+ },
144
+ decorators: [
145
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
146
+ ],
147
+ };
148
+ export const NoAutoFocus = {
149
+ args: {
150
+ fieldName: "amount",
151
+ currencyIcon: "https://placehold.co/40x40",
152
+ currencyName: "BBN",
153
+ placeholder: "Click to enter amount",
154
+ prefix: "Unbonded",
155
+ displayBalance: true,
156
+ autoFocus: false,
157
+ balanceDetails: {
158
+ balance: 999.87654321,
159
+ symbol: "BBN",
160
+ price: 0.15,
161
+ displayUSD: true,
162
+ decimals: 8,
163
+ },
164
+ },
165
+ decorators: [
166
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
167
+ ],
168
+ };
169
+ export const CustomMinStep = {
170
+ args: {
171
+ fieldName: "amount",
172
+ currencyIcon: "https://placehold.co/40x40/F7931A/FFFFFF?text=₿",
173
+ currencyName: "BTC",
174
+ placeholder: "Minimum 0.001 BTC",
175
+ prefix: "Withdrawable",
176
+ displayBalance: true,
177
+ min: "0.001",
178
+ step: "0.001",
179
+ balanceDetails: {
180
+ balance: 2.5,
181
+ symbol: "BTC",
182
+ price: 65000,
183
+ displayUSD: true,
184
+ decimals: 8,
185
+ },
186
+ },
187
+ decorators: [
188
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
189
+ ],
190
+ };
191
+ export const NoPrefix = {
192
+ args: {
193
+ fieldName: "amount",
194
+ currencyIcon: "https://placehold.co/40x40/1DA1F2/FFFFFF?text=D",
195
+ currencyName: "DOGE",
196
+ placeholder: "Much amount, very input",
197
+ displayBalance: true,
198
+ balanceDetails: {
199
+ balance: 42069.42,
200
+ symbol: "DOGE",
201
+ price: 0.08,
202
+ displayUSD: true,
203
+ decimals: 8,
204
+ },
205
+ },
206
+ decorators: [
207
+ (Story) => (_jsx(Form, { onChange: console.log, schema: schema, children: _jsx(Story, {}) })),
208
+ ],
209
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonlabs-io/core-ui",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "publishConfig": {