Skip to content

Commit

Permalink
feat(page): final hook up
Browse files Browse the repository at this point in the history
  • Loading branch information
fakenickels committed Dec 5, 2021
1 parent 8c031d0 commit 8ca53e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 2 additions & 5 deletions pages/kittens-hd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,8 @@ export default function KittensHD() {
})
.catch((e) => {
toast.dismiss();
toast.error(
`Error claiming ${Number(
rkittenClaim.getLeaf().amount
)} kittens: ${e.message}`
);
console.log(e);
toast.error(`${e.data?.message || e.message}`);
});
}}
disabled={!Boolean(rkittenClaim.getLeaf())}
Expand Down
12 changes: 8 additions & 4 deletions src/utils/useKittensHdMinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export const useKittenHDMinterMethods = () => {
const wallet = useWallet();

const claimKittens = async (quantity: number | string) => {
return contract.current.claim(quantity).send({
from: wallet?.account as string,
value: getCostPerKittenByQuantity(Number(quantity)).mul(quantity),
});
return contract.current
.claim(quantity, {
from: wallet?.account as string,
value: getCostPerKittenByQuantity(Number(quantity)).mul(quantity),
})
.then((res: any) => {
return res.wait();
});
};

return {
Expand Down
14 changes: 8 additions & 6 deletions src/utils/useRKittenClaim.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { useWallet } from "use-wallet";
import * as ethers from "ethers";
import KittensHDMinter from "../../artifacts/contracts/KittensHDPublicMinter.sol/KittensHDPublicMinter.json";
import rKittenMerkleRootSnaptshot from "../../airdrop/kittens-hd-rkitten-airdrop/merkle-root.json";
import MerkleDistributor from "../../artifacts/contracts/KittenHDRKittenMerkleDistributor.sol/KittenHDRKittenMerkleDistributor.json";

export const useWeb3 = () => {
const provider: React.MutableRefObject<
Expand All @@ -15,7 +15,7 @@ export const useWeb3 = () => {
const signer = provider.current.getSigner();
contract.current = new ethers.Contract(
process.env.NEXT_PUBLIC_KITTENS_MERKLE_DISTRIBUTOR_ADDRESS as string,
KittensHDMinter.abi as any,
MerkleDistributor.abi as any,
signer
);
});
Expand All @@ -29,14 +29,16 @@ export const useRKittenClaim = () => {
const wallet = useWallet();

const claimKittens = async () => {
const proof: {
const leaf: {
index: number;
amount: string;
proof: string[];
} = (rKittenMerkleRootSnaptshot as any).claims[wallet?.account as string];
return contract.current.claim(Number(proof.amount), {
from: wallet?.account as string,
});
return contract.current
.claim(leaf.index, Number(leaf.amount), leaf.proof)
.then((res: any) => {
return res.wait();
});
};

// check if wallet.address is in the rKittenMerkleRootSnaptshot
Expand Down

0 comments on commit 8ca53e9

Please sign in to comment.