Skip to content

Commit

Permalink
mint lords button
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Oct 9, 2023
1 parent 4599f0b commit e2437a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
20 changes: 16 additions & 4 deletions ui/src/app/components/navigation/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef } from "react";
import { useRef, useState } from "react";
import { useBalance, useAccount, useConnectors } from "@starknet-react/core";
import { useContracts } from "@/app/hooks/useContracts";
import useAdventurerStore from "@/app/hooks/useAdventurerStore";
Expand Down Expand Up @@ -61,6 +61,8 @@ export default function Header({ multicall, mintLords }: HeaderProps) {
const displayCartButtonRef = useRef<HTMLButtonElement>(null);
const displayHistoryButtonRef = useRef<HTMLButtonElement>(null);

const [showLordsMint, setShowLordsMint] = useState(false);

return (
<div className="flex flex-row justify-between px-1 ">
<div className="flex flex-row items-center gap-2 sm:gap-5">
Expand All @@ -87,12 +89,22 @@ export default function Header({ multicall, mintLords }: HeaderProps) {
<Button
size={"xs"}
variant={"outline"}
className="self-center xl:px-5"
className="self-center xl:px-5 hover:bg-terminal-green"
onClick={mintLords}
onMouseEnter={() => setShowLordsMint(true)}
onMouseLeave={() => setShowLordsMint(false)}
>
<span className="flex flex-row items-center justify-between w-full">
<Lords className="self-center sm:w-5 sm:h-5 h-3 w-3 fill-current mr-1" />
<p>{formatNumber(parseInt(lordsBalance.data?.formatted ?? "0"))}</p>
{!showLordsMint ? (
<>
<Lords className="self-center sm:w-5 sm:h-5 h-3 w-3 fill-current mr-1" />
<p>
{formatNumber(parseInt(lordsBalance.data?.formatted ?? "0"))}
</p>
</>
) : (
<p className="text-black">Mint Lords</p>
)}
</span>
</Button>
<Button
Expand Down
27 changes: 14 additions & 13 deletions ui/src/app/lib/burner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,20 @@ export const useBurner = () => {
]),
};

const { suggestedMaxFee: estimatedFee } = await mainAccount.estimateFee(
call
);
const transferLordsTx = {
contractAddress: lordsContract?.address ?? "",
entrypoint: "transfer",
calldata: CallData.compile([
masterAccountAddress,
lordsBalance ?? "0x0",
"0x0",
]),
};

const { suggestedMaxFee: estimatedFee } = await mainAccount.estimateFee([
call,
transferLordsTx,
]);

// Now we negate the fee from balance to withdraw (+10% for safety)

Expand All @@ -410,16 +421,6 @@ export const useBurner = () => {
]),
};

const transferLordsTx = {
contractAddress: lordsContract?.address ?? "",
entrypoint: "transfer",
calldata: CallData.compile([
masterAccountAddress,
lordsBalance ?? "0x0",
"0x0",
]),
};

// If they have Lords also withdraw
const calls =
lordsBalance > BigInt(0)
Expand Down

0 comments on commit e2437a0

Please sign in to comment.