Skip to content

Commit

Permalink
Merge branch 'michael/scroll-token-claim' of https://github.com/votea…
Browse files Browse the repository at this point in the history
…gora/agora-next into michael/scroll-token-claim
  • Loading branch information
andreitr committed Sep 4, 2024
2 parents b2fcad8 + 96eada6 commit 771776d
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 9,159 deletions.
6 changes: 2 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1292,11 +1292,9 @@ model SoftClaim {
claim_status String
verification_code String?
verified_at DateTime?
// dao_slug, claim_type, claim_identifier should be unique
airdrop_recipient AirdropRecipient? @relation(fields: [dao_slug, recipient], references: [dao_slug, address])
@@unique([dao_slug, claim_type, claim_identifier])
@@map("soft_claim")
@@schema("alltenant")
}
Expand All @@ -1309,11 +1307,11 @@ model HardClaim {
claim_status String
claimed_at DateTime?
transaction_hash String?
proof String[]
// obviously going to change these column names
eligibility_amount_crit_1 String
eligibility_amount_crit_2 String
eligibility_amount_crit_3 String
airdrop_recipient AirdropRecipient @relation(fields: [dao_slug, recipient], references: [dao_slug, address])
@@map("hard_claim")
Expand Down
9,007 changes: 0 additions & 9,007 deletions public/merkle-trees/scroll-test.json

This file was deleted.

9 changes: 5 additions & 4 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SOFT_CLAIM_SEARCH_PARAM_VERIFIED_VALUE_FALSE,
SOFT_CLAIM_SEARCH_PARAM_ERROR_KEY,
SOFT_CLAIM_SEARCH_PARAM_ERROR_VALUE_NO_ADDRESS,
CLAIM_STATUS,
CLAIM_IDENTIFIER,
} from "@/app/claim/types";

declare module "next-auth" {
Expand All @@ -30,9 +32,9 @@ async function markGithubSoftClaimAsClaimed(
) {
const githubSoftClaim = await prisma.softClaim.findFirst({
where: {
claim_type: "GITHUB",
claim_type: CLAIM_IDENTIFIER.GITHUB,
claim_identifier: githubNodeId,
claim_status: "UNCLAIMED",
claim_status: CLAIM_STATUS.UNCLAIMED,
},
});

Expand All @@ -42,7 +44,7 @@ async function markGithubSoftClaimAsClaimed(
id: githubSoftClaim.id,
},
data: {
claim_status: "CLAIMED",
claim_status: CLAIM_STATUS.CLAIMED,
recipient: address,
verified_at: new Date(),
},
Expand Down Expand Up @@ -125,4 +127,3 @@ const handler = NextAuth({
});

export const { GET, POST } = handler.handlers;
// export { handler as GET, handler as POST };
66 changes: 0 additions & 66 deletions src/app/api/claim/merkle-tree/route.ts

This file was deleted.

23 changes: 12 additions & 11 deletions src/app/claim/dialogs/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import prisma from "@/app/lib/prisma";
import { Octokit } from "@octokit/rest";
import { renderHtml } from "../mail/VerificationCode";
import { DaoSlug } from "@prisma/client";
import { CLAIM_STATUS, CLAIM_IDENTIFIER } from "@/app/claim/types";

export async function getHardClaimForAddress(address: `0x${string}`) {
return await prisma.hardClaim.findFirst({
Expand All @@ -18,7 +19,7 @@ export async function getSoftClaimsForAddress(address: `0x${string}`) {
const softClaims = await prisma.softClaim.findMany({
where: {
recipient: address,
claim_status: "CLAIMED",
claim_status: CLAIM_STATUS.CLAIMED,
},
select: {
amount: true,
Expand Down Expand Up @@ -77,12 +78,12 @@ function generateVerificationCode(): string {
export async function checkIfGithubHasClaim(githubNodeId: string) {
const githubSoftClaim = await prisma.softClaim.findFirst({
where: {
claim_type: "GITHUB",
claim_type: CLAIM_IDENTIFIER.GITHUB,
claim_identifier: githubNodeId,
// do we want to do this?
// It will prevent us from sending an email if the user has already tried to claim (pending state)
// or if they have already claimed
claim_status: "UNCLAIMED",
claim_status: CLAIM_STATUS.UNCLAIMED,
},
});

Expand All @@ -101,12 +102,12 @@ export async function checkIfGithubHasClaim(githubNodeId: string) {
export async function checkIfEmailHasClaim(email: string) {
const emailSoftClaim = await prisma.softClaim.findFirst({
where: {
claim_type: "EMAIL",
claim_type: CLAIM_IDENTIFIER.EMAIL,
claim_identifier: email,
// do we want to do this?
// It will prevent us from sending an email if the user has already tried to claim (pending state)
// or if they have already claimed
claim_status: "UNCLAIMED",
claim_status: CLAIM_STATUS.UNCLAIMED,
},
});

Expand All @@ -132,7 +133,7 @@ export async function checkAndSendVerificationEmail(email: string) {
id: claim.id,
},
data: {
claim_status: "SENT_CODE",
claim_status: CLAIM_STATUS.SENT_CODE,
verification_code: code,
},
});
Expand All @@ -141,7 +142,7 @@ export async function checkAndSendVerificationEmail(email: string) {
to: email,
from: "[email protected]",
subject: "Verify your email",
text: `Your verification code is: ${code}. This code will expire in 10 minutes.`,
text: `Your verification code is: ${code}.`,
html: await renderHtml(code),
});

Expand Down Expand Up @@ -188,9 +189,9 @@ export async function verifyEmail(
) {
const emailSoftClaim = await prisma.softClaim.findFirst({
where: {
claim_type: "EMAIL",
claim_type: CLAIM_IDENTIFIER.EMAIL,
claim_identifier: email,
claim_status: "SENT_CODE",
claim_status: CLAIM_STATUS.SENT_CODE,
verification_code: code,
},
});
Expand All @@ -201,7 +202,7 @@ export async function verifyEmail(
id: emailSoftClaim.id,
},
data: {
claim_status: "CLAIMED",
claim_status: CLAIM_STATUS.CLAIMED,
recipient: address,
verified_at: new Date(),
},
Expand All @@ -228,7 +229,7 @@ export const saveHardClaim = async (
id: hardClaimId,
},
data: {
claim_status: "CLAIMED",
claim_status: CLAIM_STATUS.CLAIMED,
transaction_hash: transactionHash,
claimed_at: new Date(),
},
Expand Down
17 changes: 8 additions & 9 deletions src/app/claim/stages/Claim.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import Image from "next/image";
import { Button } from "../../../components/ui/button";
import { useMerkleTree } from "@/hooks/useMerkleTree";
import {
useContractRead,
useAccount,
Expand Down Expand Up @@ -54,10 +53,6 @@ const ClaimStage = ({ onSuccess }: { onSuccess: () => void }) => {
const { address } = useAccount();
const { token, ui, contracts } = Tenant.current();
const { data: blockNumber } = useBlockNumber();
const { data: merkleTreeData, isFetching } = useMerkleTree({
address: address!,
tree: "scroll-test",
});

const { data: claimEnd } = useContractRead({
address: contracts.tokenDistributor?.address as `0x${string}`,
Expand All @@ -78,7 +73,11 @@ const ClaimStage = ({ onSuccess }: { onSuccess: () => void }) => {
functionName: "claim",
});

const { data: hardClaim } = useHardClaim(address as `0x${string}`);
const {
data: hardClaim,
isFetching,
isFetched,
} = useHardClaim(address as `0x${string}`);

if (blockNumber && claimEnd && blockNumber > claimEnd) {
return <div>Claim has ended.</div>;
Expand All @@ -100,7 +99,7 @@ const ClaimStage = ({ onSuccess }: { onSuccess: () => void }) => {
<span className="h-12 w-20 bg-tertiary/50 animate-pulse rounded"></span>
) : (
<span className="text-5xl">
{formatNumber(merkleTreeData?.value || 0, token.decimals)}
{formatNumber(hardClaim?.amount || 0, token.decimals)}
</span>
)}
<Image
Expand All @@ -127,8 +126,8 @@ const ClaimStage = ({ onSuccess }: { onSuccess: () => void }) => {
const data = await writeAsync({
args: [
address as `0x${string}`,
merkleTreeData?.value as bigint,
merkleTreeData?.proof,
BigInt(hardClaim.amount),
hardClaim.proof,
],
});

Expand Down
26 changes: 9 additions & 17 deletions src/app/claim/stages/Delegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
import { useMerkleTree } from "@/hooks/useMerkleTree";
import Tenant from "@/lib/tenant/tenant";
import { useOpenDialog } from "@/components/Dialogs/DialogProvider/DialogProvider";
import { useAccount, useContractWrite } from "wagmi";
Expand All @@ -17,6 +16,7 @@ import { DelegateChunk } from "@/app/api/common/delegates/delegate";
import { DelegateCardList } from "@/app/claim/components/DelegateCardList";
import { DelegateSelectedCard } from "@/app/claim/components/DelegateSelectedCard";
import { subscribeToDelegateActivity } from "../dialogs/actions";
import { useHardClaim } from "../hooks/useHardClaim";

// should read this from contract
const DENOMINATOR = 10000;
Expand Down Expand Up @@ -66,15 +66,6 @@ function distributeProportion(length: number) {

const MOCK_CLAIM_AMOUNT = 4455;

const getPercentage = (count: number, total: number) => {
const percent = count / total;
if (Number.isInteger(percent)) {
return percent.toFixed(0);
} else {
return percent.toFixed(2);
}
};

interface Props {
delegates: PaginatedResult<DelegateChunk[]>;
fetchDelegates: (
Expand All @@ -100,11 +91,6 @@ const DelegationStage = ({
const { address } = useAccount();
const openDialog = useOpenDialog();

const { data, isFetching } = useMerkleTree({
address: address!,
tree: "scroll-test",
});

const [selectedDelegates, setSelectedDelegates] = useState<string[]>([]);
const isSelectedDelegate = (address: string) =>
selectedDelegates.includes(address);
Expand All @@ -127,6 +113,12 @@ const DelegationStage = ({
functionName: "delegate",
});

const {
data: hardClaim,
isFetching,
isFetched,
} = useHardClaim(address as `0x${string}`);

return (
<main className="grid grid-cols-8 gap-10 mt-12">
<section className="col-span-5">
Expand Down Expand Up @@ -214,9 +206,9 @@ const DelegationStage = ({
<span className="h-6 w-10 bg-tertiary/50 animate-pulse rounded"></span>
) : (
<>
{data?.value ? (
{hardClaim?.amount ? (
<span className="font-medium text-2xl text-primary">
{formatNumber(data?.value, token.decimals)}
{formatNumber(hardClaim.amount, token.decimals)}
</span>
) : (
"No value..."
Expand Down
11 changes: 11 additions & 0 deletions src/app/claim/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ export const SOFT_CLAIM_SEARCH_PARAM_VERIFIED_VALUE_TRUE = "true";
export const SOFT_CLAIM_SEARCH_PARAM_VERIFIED_VALUE_FALSE = "false";
export const SOFT_CLAIM_SEARCH_PARAM_ERROR_KEY = "error";
export const SOFT_CLAIM_SEARCH_PARAM_ERROR_VALUE_NO_ADDRESS = "error";

export enum CLAIM_STATUS {
UNCLAIMED = "UNCLAIMED",
SENT_CODE = "SENT_CODE",
CLAIMED = "CLAIMED",
}

export enum CLAIM_IDENTIFIER {
EMAIL = "EMAIL",
GITHUB = "GITHUB",
}
32 changes: 0 additions & 32 deletions src/hooks/useMerkleTree.ts

This file was deleted.

Loading

0 comments on commit 771776d

Please sign in to comment.