Skip to content

Commit

Permalink
chore: handing donut increment, token selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KannuSingh committed Feb 3, 2025
1 parent c468be8 commit f3323ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { cn } from "@/lib/utils";
import { ArrowRight, ChevronRight, X } from "lucide-react";
import CoinSVG from "../assets/CoinSVG";
import NetworkSVG from "../assets/NetworkSVG";
import { useWalletAssets } from "@/context/WalletAssetsProvider";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";

function CheckoutView({ onViewChange, onClose }: GiftDonutModalViewProps) {
return (
Expand All @@ -29,13 +31,18 @@ function GiftDonutForm({
onClose,
}: GiftDonutFormProps) {
const donutCount = giftDonutModalManager.getDonutCount();
const {getBalanceBySymbol} = useWalletAssets();
const [count, setCount] = React.useState(donutCount);

const selectedToken = giftDonutModalManager.getToken();
const selectedNetwork = giftDonutModalManager.getNetwork();

const tokenBalance = getBalanceBySymbol(selectedToken.name);
const maxDonutPurchasable = Math.trunc(parseFloat(tokenBalance) / 1.00);

const setDonutCount = (count: number) => {
if (count < 0) return;
const balance = getBalanceBySymbol(selectedToken.name);
if (count > parseFloat(balance)) return;
setCount(count);
giftDonutModalManager.setDonutCount(count);
};
Expand Down Expand Up @@ -69,14 +76,24 @@ function GiftDonutForm({
-
</Button>
{count}
<Button
variant="outline"
onClick={() => setDonutCount(count + 1)}
style={{ backgroundColor: "var(--tertiary-foreground)" }}
className="ml-2 rounded-full "
>
+
</Button>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
onClick={() => setDonutCount(count + 1)}
style={{ backgroundColor: "var(--tertiary-foreground)" }}
className="ml-2 rounded-full "
>
+
</Button>
</TooltipTrigger>
<TooltipContent >
<p>Maximum donuts you can gift: {maxDonutPurchasable}</p>
<p className="text-xs">Available: {tokenBalance} {selectedToken.name}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GiftDonutModalManager {
views: {},
state: {
token: supportedTokens[0],
donutCount: 1,
donutCount: 0,
},
});
}
Expand Down Expand Up @@ -98,6 +98,7 @@ class GiftDonutModalManager {
}

setToken(token: Token): void {
this.state.state.donutCount = 0; // Reset donut count when changing token
this.state.state.token = token;
}

Expand Down

0 comments on commit f3323ca

Please sign in to comment.