Skip to content

Commit

Permalink
add lords mint to spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
starknetdev committed Oct 9, 2023
1 parent e2437a0 commit ed23a13
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
14 changes: 13 additions & 1 deletion ui/src/app/components/start/CreateAdventurer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ export interface CreateAdventurerProps {
isActive: boolean;
onEscape: () => void;
spawn: (...args: any[]) => any;
lordsBalance?: bigint;
mintLords: (...args: any[]) => any;
}

export const CreateAdventurer = ({
isActive,
onEscape,
spawn,
lordsBalance,
mintLords,
}: CreateAdventurerProps) => {
const [formData, setFormData] = useState<FormData>({
startingWeapon: "",
Expand Down Expand Up @@ -87,7 +91,15 @@ export const CreateAdventurer = ({
/>
);
} else if (step === 3) {
return <Spawn formData={formData} spawn={spawn} handleBack={handleBack} />;
return (
<Spawn
formData={formData}
spawn={spawn}
handleBack={handleBack}
lordsBalance={lordsBalance}
mintLords={mintLords}
/>
);
} else {
return null;
}
Expand Down
48 changes: 34 additions & 14 deletions ui/src/app/components/start/Spawn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ export interface SpawnProps {
formData: FormData;
spawn: (...args: any[]) => any;
handleBack: () => void;
lordsBalance?: bigint;
mintLords: (...args: any[]) => any;
}

export const Spawn = ({ formData, spawn, handleBack }: SpawnProps) => {
export const Spawn = ({
formData,
spawn,
handleBack,
lordsBalance,
mintLords,
}: SpawnProps) => {
const [showWalletTutorial, setShowWalletTutorial] = useState(false);
const [formFilled, setFormFilled] = useState(false);
const isWrongNetwork = useUIStore((state) => state.isWrongNetwork);
Expand Down Expand Up @@ -49,6 +57,8 @@ export const Spawn = ({ formData, spawn, handleBack }: SpawnProps) => {
await spawn(formData);
};

const checkEnoughLords = lordsBalance! >= BigInt(25000000000000000000);

return (
<div className="flex flex-col w-full h-full justify-center">
{showWalletTutorial && (
Expand Down Expand Up @@ -116,19 +126,29 @@ export const Spawn = ({ formData, spawn, handleBack }: SpawnProps) => {
}
}}
>
<Button
type="submit"
size={"xl"}
disabled={
!formFilled ||
!account ||
isWrongNetwork ||
loading ||
estimatingFee
}
>
{formFilled ? "Start Game!!" : "Fill details"}
</Button>
<div className="flex flex-col gap-2">
<Button
type="submit"
size={"xl"}
disabled={
!formFilled ||
!account ||
isWrongNetwork ||
loading ||
estimatingFee ||
!checkEnoughLords
}
>
{checkEnoughLords
? formFilled
? "Start Game!!"
: "Fill details"
: "Not enough Lords"}
</Button>
{!checkEnoughLords && (
<Button onClick={mintLords}>Mint Lords</Button>
)}
</div>
</form>
)}
</div>
Expand Down
6 changes: 6 additions & 0 deletions ui/src/app/containers/AdventurerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import useUIStore from "../hooks/useUIStore";
interface AdventurerScreenProps {
spawn: (...args: any[]) => any;
handleSwitchAdventurer: (...args: any[]) => any;
lordsBalance?: bigint;
mintLords: (...args: any[]) => any;
}

/**
Expand All @@ -22,6 +24,8 @@ interface AdventurerScreenProps {
export default function AdventurerScreen({
spawn,
handleSwitchAdventurer,
lordsBalance,
mintLords,
}: AdventurerScreenProps) {
const [activeMenu, setActiveMenu] = useState(0);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -85,6 +89,8 @@ export default function AdventurerScreen({
isActive={activeMenu == 1}
onEscape={() => setActiveMenu(0)}
spawn={spawn}
lordsBalance={lordsBalance}
mintLords={mintLords}
/>
</div>
)}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/lib/utils/syscalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ export function syscalls({
account
);

console.log(balanceEmpty);

if (!balanceEmpty) {
startLoading(
"Create",
Expand Down
3 changes: 2 additions & 1 deletion ui/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export default function Home() {
const setStartOption = useUIStore((state) => state.setStartOption);

const arcadeConnectors = getArcadeConnectors(available);
console.log(arcadeConnectors);
const lordsBalance = useBalance({
token: lordsContract?.address,
address,
Expand Down Expand Up @@ -439,6 +438,8 @@ export default function Home() {
<AdventurerScreen
spawn={spawn}
handleSwitchAdventurer={handleSwitchAdventurer}
lordsBalance={lordsBalance.data?.value}
mintLords={async () => await mintLords()}
/>
)}
{screen === "play" && (
Expand Down

0 comments on commit ed23a13

Please sign in to comment.