@@ -12,48 +12,48 @@ The `BuyActionHelperText` component now supports displaying a disabled reason me
1212import BuyActionHelperText from ' @/components/common/BuyActionHelperText' ;
1313
1414<BuyActionHelperText
15- state = " idle"
16- disabledReason = " Insufficient balance to complete this purchase"
17- className = " mt-4"
18- />
15+ state = " idle"
16+ disabledReason = " Insufficient balance to complete this purchase"
17+ className = " mt-4"
18+ />;
1919```
2020
2121### With CreatorCard
2222
2323``` tsx
2424const CreatorCard: React .FC <CreatorCardProps > = ({ creator , className }) => {
25- const { isConnected } = useAccount ();
26- const [transactionState, setTransactionState] = useState <
27- ' idle' | ' submitting' | ' failed' | ' success'
28- > (' idle' );
29-
30- // Example: Check if user has sufficient balance
31- const hasInsufficientBalance = true ; // Replace with actual balance check
32- const disabledReason = hasInsufficientBalance
33- ? ' Insufficient balance to complete this purchase'
34- : undefined ;
35-
36- return (
37- <div >
38- { /* ... other card content ... */ }
39-
40- <BuyActionHelperText
41- state = { transactionState }
42- disabledReason = { disabledReason }
43- className = " mt-4"
44- />
45- </div >
46- );
25+ const { isConnected } = useAccount ();
26+ const [transactionState, setTransactionState] = useState <
27+ ' idle' | ' submitting' | ' failed' | ' success'
28+ > (' idle' );
29+
30+ // Example: Check if user has sufficient balance
31+ const hasInsufficientBalance = true ; // Replace with actual balance check
32+ const disabledReason = hasInsufficientBalance
33+ ? ' Insufficient balance to complete this purchase'
34+ : undefined ;
35+
36+ return (
37+ <div >
38+ { /* ... other card content ... */ }
39+
40+ <BuyActionHelperText
41+ state = { transactionState }
42+ disabledReason = { disabledReason }
43+ className = " mt-4"
44+ />
45+ </div >
46+ );
4747};
4848```
4949
5050## Props
5151
52- | Prop | Type | Required | Description |
53- | ------| ------| ----------| -------------|
54- | ` state ` | ` 'idle' \| 'submitting' \| 'failed' \| 'success' ` | Yes | Current transaction state |
55- | ` className ` | ` string ` | No | Additional CSS classes |
56- | ` disabledReason ` | ` string ` | No | Reason message when action is disabled |
52+ | Prop | Type | Required | Description |
53+ | ---------------- | ------------------------------------------------- | -------- | -------------------------------------- |
54+ | ` state ` | ` 'idle' \| 'submitting' \| 'failed' \| 'success' ` | Yes | Current transaction state |
55+ | ` className ` | ` string ` | No | Additional CSS classes |
56+ | ` disabledReason ` | ` string ` | No | Reason message when action is disabled |
5757
5858## Behavior
5959
@@ -64,6 +64,7 @@ const CreatorCard: React.FC<CreatorCardProps> = ({ creator, className }) => {
6464## Styling
6565
6666The disabled reason text uses:
67+
6768- Font size: ` 0.72rem ` (matching the main message)
6869- Color: ` text-white/40 ` (subtle, non-intrusive)
6970- Animation: Framer Motion with opacity and height transitions
@@ -73,19 +74,19 @@ The disabled reason text uses:
7374
7475``` tsx
7576// Insufficient balance
76- disabledReason = " Insufficient balance to complete this purchase"
77+ disabledReason = ' Insufficient balance to complete this purchase' ;
7778
7879// Network issue
79- disabledReason = " Network connection required to proceed"
80+ disabledReason = ' Network connection required to proceed' ;
8081
8182// Wallet not connected
82- disabledReason = " Connect your wallet to enable purchases"
83+ disabledReason = ' Connect your wallet to enable purchases' ;
8384
8485// Creator unavailable
85- disabledReason = " This creator is currently unavailable"
86+ disabledReason = ' This creator is currently unavailable' ;
8687
8788// Maximum keys reached
88- disabledReason = " Maximum number of keys already purchased"
89+ disabledReason = ' Maximum number of keys already purchased' ;
8990```
9091
9192## Safe Empty Content Handling
@@ -110,6 +111,7 @@ const hasDisabledReason = disabledReason && disabledReason.trim().length > 0;
110111```
111112
112113This ensures:
114+
113115- Null/undefined values are handled
114116- Empty strings are ignored
115117- Whitespace-only strings are ignored
@@ -130,53 +132,53 @@ import BuyActionHelperText from '@/components/common/BuyActionHelperText';
130132import { Button } from ' @/components/ui/button' ;
131133
132134export function BuyActionExample() {
133- const { isConnected } = useAccount ();
134- const [transactionState, setTransactionState] = useState <
135- ' idle' | ' submitting' | ' failed' | ' success'
136- > (' idle' );
137-
138- // Example conditions that might disable an action
139- const userBalance = 0.5 ; // ETH
140- const requiredAmount = 1.0 ; // ETH
141- const isNetworkAvailable = true ;
142- const hasReachedLimit = false ;
143-
144- // Determine disabled reason based on conditions
145- const getDisabledReason = () => {
146- if (! isConnected ) {
147- return ' Connect your wallet to enable purchases' ;
148- }
149- if (userBalance < requiredAmount ) {
150- return ` Insufficient balance. You need ${requiredAmount - userBalance } ETH more ` ;
151- }
152- if (! isNetworkAvailable ) {
153- return ' Network connection required to proceed' ;
154- }
155- if (hasReachedLimit ) {
156- return ' Maximum number of keys already purchased' ;
157- }
158- return undefined ; // No disabled reason
159- };
160-
161- const disabledReason = getDisabledReason ();
162- const isDisabled = !! disabledReason || transactionState === ' submitting' ;
163-
164- return (
165- <div className = " space-y-4" >
166- <Button
167- onClick = { () => setTransactionState (' submitting' )}
168- disabled = { isDisabled }
169- variant = { isConnected ? ' default' : ' outline' }
170- >
171- Buy Key
172- </Button >
173-
174- <BuyActionHelperText
175- state = { transactionState }
176- disabledReason = { disabledReason }
177- className = " mt-4"
178- />
179- </div >
180- );
135+ const { isConnected } = useAccount ();
136+ const [transactionState, setTransactionState] = useState <
137+ ' idle' | ' submitting' | ' failed' | ' success'
138+ > (' idle' );
139+
140+ // Example conditions that might disable an action
141+ const userBalance = 0.5 ; // ETH
142+ const requiredAmount = 1.0 ; // ETH
143+ const isNetworkAvailable = true ;
144+ const hasReachedLimit = false ;
145+
146+ // Determine disabled reason based on conditions
147+ const getDisabledReason = () => {
148+ if (! isConnected ) {
149+ return ' Connect your wallet to enable purchases' ;
150+ }
151+ if (userBalance < requiredAmount ) {
152+ return ` Insufficient balance. You need ${requiredAmount - userBalance } ETH more ` ;
153+ }
154+ if (! isNetworkAvailable ) {
155+ return ' Network connection required to proceed' ;
156+ }
157+ if (hasReachedLimit ) {
158+ return ' Maximum number of keys already purchased' ;
159+ }
160+ return undefined ; // No disabled reason
161+ };
162+
163+ const disabledReason = getDisabledReason ();
164+ const isDisabled = !! disabledReason || transactionState === ' submitting' ;
165+
166+ return (
167+ <div className = " space-y-4" >
168+ <Button
169+ onClick = { () => setTransactionState (' submitting' )}
170+ disabled = { isDisabled }
171+ variant = { isConnected ? ' default' : ' outline' }
172+ >
173+ Buy Key
174+ </Button >
175+
176+ <BuyActionHelperText
177+ state = { transactionState }
178+ disabledReason = { disabledReason }
179+ className = " mt-4"
180+ />
181+ </div >
182+ );
181183}
182184```
0 commit comments