forked from thirdweb-example/play-to-earn-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRewards.tsx
74 lines (66 loc) · 1.95 KB
/
Rewards.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
import React from "react";
import {
ThirdwebNftMedia,
useAddress,
useContractRead,
useMetadata,
useTokenBalance,
Web3Button,
} from "@thirdweb-dev/react";
import { SmartContract, Token } from "@thirdweb-dev/sdk";
import { ethers } from "ethers";
import styles from "../styles/Home.module.css";
import ApproxRewards from "./ApproxRewards";
import { MINING_CONTRACT_ADDRESS } from "../const/contractAddresses";
type Props = {
miningContract: SmartContract<any>;
tokenContract: Token;
};
/**
* This component shows the:
* - Metadata of the token itself (mainly care about image)
* - The amount this wallet holds of this wallet
* - The amount this user can claim from the mining contract
*/
export default function Rewards({ miningContract, tokenContract }: Props) {
const address = useAddress();
const { data: tokenMetadata } = useMetadata(tokenContract);
const { data: currentBalance } = useTokenBalance(tokenContract, address);
const { data: unclaimedAmount } = useContractRead(
miningContract,
"calculateRewards",
address
);
return (
<div
style={{ display: "flex", flexDirection: "column", alignItems: "center" }}
>
<p>
Your <b>Gold Gems</b>
</p>
{tokenMetadata && (
<ThirdwebNftMedia
// @ts-ignore
metadata={tokenMetadata}
height={"48"}
/>
)}
<p className={styles.noGapBottom}>
Balance: <b>{currentBalance?.displayValue}</b>
</p>
<p>
Unclaimed:{" "}
<b>{unclaimedAmount && ethers.utils.formatUnits(unclaimedAmount)}</b>
</p>
<ApproxRewards miningContract={miningContract} />
<div className={styles.smallMargin}>
<Web3Button
contractAddress={MINING_CONTRACT_ADDRESS}
action={(contract) => contract.call("claim")}
>
Claim
</Web3Button>
</div>
</div>
);
}