@@ -6,7 +6,7 @@ import { Button } from "../ui/button";
66import Image from "next/image" ;
77import React from "react" ;
88import { cn } from "@/lib/utils" ;
9- import { ArrowRight , ChevronRight , X } from "lucide-react" ;
9+ import { AlertTriangle , ArrowRight , ChevronRight , X } from "lucide-react" ;
1010import CoinSVG from "../assets/CoinSVG" ;
1111import NetworkSVG from "../assets/NetworkSVG" ;
1212import {
@@ -39,18 +39,19 @@ function GiftDonutForm({
3939
4040 const selectedToken = giftDonutModalManager . getToken ( ) ;
4141 const selectedNetwork = giftDonutModalManager . getNetwork ( ) ;
42- const tokenBalance = giftDonutModalManager . getBalanceBySymbol (
43- selectedToken . name ,
44- ) ;
42+ const tokenBalance = giftDonutModalManager . getBalanceBySymbol ( selectedToken . name ) ;
4543 const maxDonutPurchasable = Math . trunc ( parseFloat ( tokenBalance ) / 1.0 ) ;
4644
45+ // Allow any count >= 0.
4746 const setDonutCount = ( newCount : number ) => {
4847 if ( newCount < 0 ) return ;
49- if ( newCount > maxDonutPurchasable ) return ;
5048 setCount ( newCount ) ;
5149 giftDonutModalManager . setDonutCount ( newCount ) ;
5250 } ;
5351
52+ // Check whether the selected count exceeds the available balance.
53+ const isExceeded = count > maxDonutPurchasable ;
54+
5455 return (
5556 < div className = { cn ( "flex flex-col items-start gap-4" , className ) } >
5657 < div className = "grid grid-cols-3 items-center w-full" >
@@ -63,7 +64,7 @@ function GiftDonutForm({
6364 </ Button >
6465 </ div >
6566 </ div >
66- < div className = "flex items-center gap-2 w-full bg-primary-foreground p-4 rounded-3xl " >
67+ < div className = "flex items-center gap-2 w-full bg-primary-foreground p-4 rounded-3xl" >
6768 < Image src = "/donut-cover.png" alt = "Gift Donut" width = { 80 } height = { 80 } />
6869 < div className = "flex flex-col gap-2 w-full h-full" >
6970 < p className = "text-primary font-bold" > Donut #1</ p >
@@ -74,7 +75,6 @@ function GiftDonutForm({
7475 variant = "link"
7576 size = "sm"
7677 onClick = { ( ) => setDonutCount ( maxDonutPurchasable ) }
77- disabled = { count >= maxDonutPurchasable }
7878 className = "text-xs h-auto p-0 text-secondary hover:text-primary"
7979 >
8080 Max: { maxDonutPurchasable }
@@ -98,12 +98,12 @@ function GiftDonutForm({
9898 onClick = { ( ) => setDonutCount ( count + 1 ) }
9999 style = { { backgroundColor : "var(--tertiary-foreground)" } }
100100 className = "h-8 w-8 rounded-full p-0"
101- disabled = { count >= maxDonutPurchasable }
102101 >
103102 +
104103 </ Button >
105104 </ div >
106105 </ div >
106+ { /* Removed inline error message block */ }
107107 </ div >
108108 </ div >
109109 </ div >
@@ -112,8 +112,7 @@ function GiftDonutForm({
112112 < div
113113 className = "w-10 h-10 rounded-full flex items-center justify-center"
114114 style = { {
115- background :
116- "var(--foreground-foreground-secondary, rgba(42, 42, 42, 1))" ,
115+ background : "var(--foreground-foreground-secondary, rgba(42, 42, 42, 1))" ,
117116 } }
118117 >
119118 < CoinSVG />
@@ -147,8 +146,7 @@ function GiftDonutForm({
147146 < div
148147 className = "w-10 h-10 rounded-full flex items-center justify-center"
149148 style = { {
150- background :
151- "var(--foreground-foreground-secondary, rgba(42, 42, 42, 1))" ,
149+ background : "var(--foreground-foreground-secondary, rgba(42, 42, 42, 1))" ,
152150 } }
153151 >
154152 < NetworkSVG />
@@ -179,28 +177,47 @@ function GiftDonutForm({
179177 </ div >
180178 </ div >
181179 </ div >
180+ { /* Total Section Updated with Tooltip and Warning Icon */ }
182181 < div className = "flex justify-between w-full items-center" >
183182 < p className = "text-secondary" > Total</ p >
184- < p className = "text-md font-bold text-primary" >
185- ${ ( count * 1.0 ) . toFixed ( 2 ) }
186- </ p >
183+ { isExceeded ? (
184+ < TooltipProvider >
185+ < Tooltip >
186+ < TooltipTrigger asChild >
187+ < div className = "flex items-center gap-2" >
188+ < AlertTriangle className = "h-4 w-4 text-yellow-500" />
189+ < p className = "text-md font-bold text-yellow-500" >
190+ ${ ( count * 1.0 ) . toFixed ( 2 ) }
191+ </ p >
192+ </ div >
193+ </ TooltipTrigger >
194+ < TooltipContent className = "bg-primary-foreground" >
195+ < p className = "text-xs text-primary" >
196+ Warning: Your selected count exceeds your token balance
197+ </ p >
198+ </ TooltipContent >
199+ </ Tooltip >
200+ </ TooltipProvider >
201+ ) : (
202+ < p className = "text-md font-bold text-primary" >
203+ ${ ( count * 1.0 ) . toFixed ( 2 ) }
204+ </ p >
205+ ) }
187206 </ div >
188207 < div className = "flex gap-2 w-full" >
189208 < button
190209 onClick = { onClose }
191210 type = "button"
192211 style = { {
193- border :
194- "1px solid var(--border-border-secondary, rgba(79, 79, 79, 1))" ,
212+ border : "1px solid var(--border-border-secondary, rgba(79, 79, 79, 1))" ,
195213 } }
196214 className = "flex flex-1 text-primary items-center justify-center border-secondary rounded-lg"
197215 >
198- Cancle
216+ Cancel
199217 </ button >
200218 < Button
201219 style = { {
202- background :
203- "var(--foreground-foreground-accent-primary-010, rgba(9, 136, 240, 0.1))" ,
220+ background : "var(--foreground-foreground-accent-primary-010, rgba(9, 136, 240, 0.1))" ,
204221 } }
205222 onClick = { ( ) => onViewChange ( "CheckoutReceipentAddress" ) }
206223 type = "button"
@@ -209,9 +226,7 @@ function GiftDonutForm({
209226 >
210227 < p
211228 className = "flex items-center"
212- style = { {
213- color : "var(--text-text-accent-primary, rgba(9, 136, 240, 1))" ,
214- } }
229+ style = { { color : "var(--text-text-accent-primary, rgba(9, 136, 240, 1))" } }
215230 >
216231 Next < ArrowRight className = "w-4 h-4" />
217232 </ p >
0 commit comments