Skip to content

Commit

Permalink
Uses enums for constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgingras committed Sep 4, 2024
1 parent 141e4c4 commit 96eada6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
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 };
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
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",
}
9 changes: 6 additions & 3 deletions src/scripts/claims/scroll/processCSVToDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PrismaClient, DaoSlug } from "@prisma/client";
import path from "path";
import dotenv from "dotenv";
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { CLAIM_STATUS, CLAIM_IDENTIFIER } from "@/app/claim/types";

// To run: run this command from the root of the project
// npx ts-node --compiler-options {\"module\":\"CommonJS\"} src/scripts/claims/scroll/processCSVToDB.ts
Expand Down Expand Up @@ -70,8 +71,10 @@ const createSoftClaimRecord = async (row: CSVRow) => {
data: {
dao_slug: DaoSlug.SCROLL,
amount: row.claim_total_amount,
claim_type: !!row.soft_claim_email_address ? "EMAIL" : "GITHUB",
claim_status: "UNCLAIMED",
claim_type: !!row.soft_claim_email_address
? CLAIM_IDENTIFIER.EMAIL
: CLAIM_IDENTIFIER.GITHUB,
claim_status: CLAIM_STATUS.UNCLAIMED,
claim_identifier:
row.soft_claim_github_global_node_id || row.soft_claim_email_address,
},
Expand Down Expand Up @@ -100,7 +103,7 @@ const createHardClaimRecord = async (row: CSVRow) => {
data: {
dao_slug: DaoSlug.SCROLL,
amount: row.claim_total_amount,
claim_status: "UNCLAIMED",
claim_status: CLAIM_STATUS.UNCLAIMED,
recipient: recipient,
proof: proof,
// replace with actual criteria
Expand Down

0 comments on commit 96eada6

Please sign in to comment.