forked from thirdweb-example/play-to-earn-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
69 lines (60 loc) · 1.46 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import type { NextPage } from "next";
import styles from "../styles/Home.module.css";
import {
ConnectWallet,
useAddress,
useContract,
useOwnedNFTs,
} from "@thirdweb-dev/react";
import { CHARACTER_EDITION_ADDRESS } from "../const/contractAddresses";
import MintContainer from "../components/MintContainer";
import { useRouter } from "next/router";
const Home: NextPage = () => {
const { contract: editionDrop } = useContract(
CHARACTER_EDITION_ADDRESS,
"edition-drop"
);
const address = useAddress();
const router = useRouter();
const {
data: ownedNfts,
isLoading,
isError,
} = useOwnedNFTs(editionDrop, address);
// 0. Wallet Connect - required to check if they own an NFT
if (!address) {
return (
<div className={styles.container}>
<ConnectWallet theme="dark" />
</div>
);
}
// 1. Loading
if (isLoading) {
return <div>Loading...</div>;
}
// Something went wrong
if (!ownedNfts || isError) {
return <div>Error</div>;
}
// 2. No NFTs - mint page
if (ownedNfts.length === 0) {
return (
<div className={styles.container}>
<MintContainer />
</div>
);
}
// 3. Has NFT already - show button to take to game
return (
<div className={styles.container}>
<button
className={`${styles.mainButton} ${styles.spacerBottom}`}
onClick={() => router.push("/play")}
>
Play Game
</button>
</div>
);
};
export default Home;