forked from markovicmarco/packs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
119 lines (104 loc) · 3.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
useAddress,
useDisconnect,
useMetamask,
usePack,
useOwnedNFTs,
ThirdwebNftMedia,
} from "@thirdweb-dev/react";
import { PackRewardsOutput } from "@thirdweb-dev/sdk/dist/src/schema";
import type { NextPage } from "next";
import { useState } from "react";
import ERC1155RewardBox from "../components/ERC1155RewardBox";
import ERC20RewardBox from "../components/ERC20RewardBox";
import styles from "../styles/Home.module.css";
const Home: NextPage = () => {
const address = useAddress();
const connectWithMetamask = useMetamask();
const disconnectWallet = useDisconnect();
const [rewards, setRewards] = useState<PackRewardsOutput>();
const pack = usePack("0x0Aee160411473f63be2DfF2865E81A1D59636C97");
const { data: nfts, isLoading } = useOwnedNFTs(pack, address);
async function open() {
pack?.interceptor.overrideNextTransaction(() => ({
gasLimit: 500000,
}));
const openedRewards = await pack?.open(0, 1); // 0 is tokenId here
setRewards(openedRewards as PackRewardsOutput);
console.log(openedRewards);
}
return (
<div className={styles.container}>
{address ? (
<>
<a onClick={disconnectWallet} className={styles.secondaryButton}>
Disconnect Wallet
</a>
<p>Your address: {address}</p>
<div className={styles.container} style={{ marginTop: 0 }}>
<div className={styles.collectionContainer}>
{!isLoading ? (
<div className={styles.nftBoxGrid}>
{nfts?.map((nft) => (
<div
className={styles.nftBox}
key={nft.metadata.id.toString()}
>
<ThirdwebNftMedia
// @ts-ignore
metadata={{
...nft.metadata,
// I messed up the metadata for the NFT, so need to remove trailing .png (You don't need this)
image: nft?.metadata?.image?.slice(0, -4),
}}
className={styles.nftMedia}
/>
<h3>{nft.metadata.name}</h3>
{/* @ts-ignore */}
<p>Quantity: {nft.supply.toNumber()}</p>
<button
className={`${styles.mainButton} ${styles.spacerBottom}`}
onClick={() => open()}
>
Open
</button>
</div>
))}
</div>
) : (
<p>Loading...</p>
)}
</div>
<hr className={styles.divider} />
<h2>Opened Rewards</h2>
{rewards && Object.entries(rewards.erc20Rewards)?.length > 0 && (
<>
<h3>ERC-20 Tokens</h3>
<div className={styles.nftBoxGrid}>
{rewards.erc20Rewards.map((reward, i) => (
<ERC20RewardBox reward={reward} key={i} />
))}
</div>
</>
)}
{rewards && Object.entries(rewards.erc1155Rewards)?.length && (
<>
<h3>ERC-1155 Tokens</h3>
<div className={styles.nftBoxGrid}>
{rewards.erc1155Rewards.map((reward, i) => (
<ERC1155RewardBox reward={reward} key={i} />
))}
</div>
</>
)}
</div>
</>
) : (
<button onClick={connectWithMetamask} className={styles.mainButton}>
Connect Wallet
</button>
)}
</div>
);
};
export default Home;