Skip to content

Commit

Permalink
feat: added no funds modal
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhkeshan committed Dec 18, 2024
1 parent d5a0f5e commit 0af0bb0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
36 changes: 34 additions & 2 deletions frontend/src/components/NewPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BoxCentered, Button } from "@fuel-ui/react";
import { BoxCentered, Button, Link } from "@fuel-ui/react";
import { useWallet } from "@fuels/react";
import { useState } from "react";
import { useEffect, useState } from "react";
import type { Dispatch, SetStateAction } from "react";
import type { Modals } from "../constants";

Expand All @@ -27,10 +27,28 @@ export default function NewPlayer({
setModal,
}: NewPlayerProps) {
const [status, setStatus] = useState<"error" | "loading" | "retrying" | "none">("none");
const [hasFunds, setHasFunds] = useState<boolean>(false);

const { wallet } = useWallet();
const paymaster = usePaymaster();
const isGaslessSupported = useGaslessWalletSupported();

useEffect(() => {
getBalance();
}, [wallet]);

async function getBalance() {
const thisWallet = wallet ?? contract?.account;
console.log(wallet, "wallet");
const baseAssetId = thisWallet?.provider.getBaseAssetId();
const balance = await thisWallet!.getBalance(baseAssetId);
const balanceNum = balance?.toNumber();

if (balanceNum) {
setHasFunds(balanceNum > 0);
}
}

async function createPlayerWithoutGasStation() {
if (!wallet || !contract) throw new Error("Wallet or contract not found");

Expand Down Expand Up @@ -140,6 +158,19 @@ export default function NewPlayer({
Make A New Player
</Button>
)}
{status === "none" && !hasFunds && (
<BoxCentered css={styles.container}>
You need some ETH to play:
<Link isExternal href={`https://app.fuel.network/bridge`}>
<Button css={styles.link} variant="link">
Go to Bridge
</Button>
</Link>
<Button css={buttonStyle} onPress={getBalance}>
Recheck balance
</Button>
</BoxCentered>
)}
{status === "loading" && (
<BoxCentered>
<Loading />
Expand Down Expand Up @@ -175,6 +206,7 @@ const styles = {
fontFamily: "pressStart2P",
fontSize: "14px",
gap: "20px",
display: "none",
}),
link: cssObj({
fontFamily: "pressStart2P",
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/modals/BuySeeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { buttonStyle, FoodTypeInput } from "../../constants";
import type { FarmContract } from "../../sway-api/contracts/FarmContract";
import {
useWallet,
useIsConnected,
useNetwork,
useBalance,
} from "@fuels/react";
import { usePaymaster } from "../../hooks/usePaymaster";

Expand Down

0 comments on commit 0af0bb0

Please sign in to comment.