-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ClaimBtn.js
37 lines (34 loc) 路 1.1 KB
/
ClaimBtn.js
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
import {
useContractWrite,
usePrepareContractWrite,
useContractRead,
} from "wagmi";
import contractInfo from "../contract/index";
export default function ClaimBtn({}) {
const {
data: creatorsCount,
isError: countErr,
isLoading: countLoading,
} = useContractRead({
...contractInfo,
functionName: "creatorsCount",
});
const { config } = usePrepareContractWrite({
...contractInfo,
functionName: "addCreator",
});
const { data, isLoading, isSuccess, write } = useContractWrite(config);
return (
<>
<button
onClick={() => write()}
type="button"
className="inline-flex items-center justify-center w-full px-4 py-3 text-base font-bold leading-6 text-white bg-slate-800 border border-transparent rounded-lg md:w-auto hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-800"
>
Be the #{creatorsCount ? creatorsCount.toString() : "?"} creator on sponsor.cat
</button>
{isLoading && <div>Check Wallet</div>}
{isSuccess && <div>Transaction: {JSON.stringify(data)}</div>}
</>
);
}