-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathCurrentGear.tsx
90 lines (81 loc) · 2.71 KB
/
CurrentGear.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
import { ThirdwebNftMedia, useAddress, useNFT } from "@thirdweb-dev/react";
import { EditionDrop, NFT, SmartContract } from "@thirdweb-dev/sdk";
import React, { useEffect, useState } from "react";
import ContractMappingResponse from "../types/ContractMappingResponse";
import GameplayAnimation from "./GameplayAnimation";
import styles from "../styles/Home.module.css";
import Image from "next/image";
type Props = {
miningContract: SmartContract<any>;
characterContract: EditionDrop;
pickaxeContract: EditionDrop;
};
/**
* This component shows the:
* - Currently equipped miner character (right now there is just one (token ID 0))
* - Currently equipped character's pickaxe
*/
export default function CurrentGear({
miningContract,
characterContract,
pickaxeContract,
}: Props) {
const address = useAddress();
const { data: playerNft } = useNFT(characterContract, 0);
const [pickaxe, setPickaxe] = useState<NFT>();
useEffect(() => {
(async () => {
if (!address) return;
const p = (await miningContract.call("playerPickaxe", [
address,
])) as ContractMappingResponse;
// Now we have the tokenId of the equipped pickaxe, if there is one, fetch the metadata for it
if (p.isData) {
const pickaxeMetadata = await pickaxeContract.get(p.value);
setPickaxe(pickaxeMetadata);
}
})();
}, [address, miningContract, pickaxeContract]);
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<h2 className={`${styles.noGapTop} `}>Equipped Items</h2>
<div
style={{
display: "flex",
alignItems: "center",
flexDirection: "row",
justifyContent: "center",
}}
>
{/* Currently equipped player */}
<div style={{ outline: "1px solid grey", borderRadius: 16 }}>
{playerNft && (
<ThirdwebNftMedia metadata={playerNft?.metadata} height={"64"} />
)}
</div>
{/* Currently equipped pickaxe */}
<div
style={{ outline: "1px solid grey", borderRadius: 16, marginLeft: 8 }}
>
{pickaxe && (
// @ts-ignore
<ThirdwebNftMedia metadata={pickaxe.metadata} height={"64"} />
)}
</div>
</div>
{/* Gameplay Animation */}
<div
style={{
display: "flex",
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
marginTop: 24,
}}
>
<Image src="/mine.gif" height={64} width={64} alt="character-mining" />
<GameplayAnimation pickaxe={pickaxe} />
</div>
</div>
);
}