Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database staging #380

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ This guide will help you set up your local environment for running and contribut
1. Clone the repository to your local machine. Ensure you have Git installed. [Git installation guide](https://git-scm.com/docs).

```bash
git clone https://github.com/poidh/poidh-app.git
```

Or, if you have the [GitHub CLI](https://cli.github.com) installed:

```bash
gh repo clone picsoritdidnthappen/poidh-app
git clone https://github.com/picsoritdidnthappen/poidh-app
```

2. Navigate into the project directory.
Expand Down Expand Up @@ -66,6 +60,28 @@ POIDH uses **pnpm** as a package manager and requires **Node.js v18.12 or higher

---

### Indexer Setup

Before starting, make sure to clone the **Indexer** repository:

```bash
git clone https://github.com/yukigesho/poidh-indexer.git
```

Next, follow the setup instructions in the **Indexer** repository's README. Don't forget to configure the `.env` file with your PostgreSQL database connection URL:

```plaintext
DATABASE_URL="postgresql://<username>:<password>@<host>:<port>/<database>"
```

Ensure the database is properly set up before proceeding.

<div align="right">
<a href="#quick-start-guide">↑ Back to Overview</a>
</div>

---

### Installing Dependencies

1. In the project root directory, install all required dependencies:
Expand Down
163 changes: 48 additions & 115 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,133 +7,66 @@ datasource db {
url = env("DATABASE_URL")
}

model Bounty {
id Decimal @id @db.Decimal(78, 0)
primaryId Decimal @db.Decimal(78, 0)
chainId Decimal @db.Decimal(78, 0)
title String
description String
amount String
issuer String
createdAt Decimal @db.Decimal(78, 0)
inProgress Int
isCanceled Int?
isBanned Int
isMultiplayer Int?
deadline Int?
user User? @relation(fields: [issuer], references: [id])
isVoting Int?
claims Claim[]
participants ParticipantBounty[]

@@index([chainId], map: "Bounty_chainIdIndex")
@@index([primaryId], map: "Bounty_primaryIdIndex")
model Bounties {
id Int
chain_id Int
title String
description String
amount String
issuer String
in_progress Boolean? @default(true)
is_joined_bounty Boolean? @default(false)
is_canceled Boolean? @default(false)
is_banned Boolean? @default(false)
is_multiplayer Boolean?
is_voting Boolean? @default(false)
deadline Int?

claims Claims[]
participations ParticipationsBounties[]
issuerUser Users? @relation(fields: [issuer], references: [address])

@@id([id, chain_id])
}

model Claim {
id Decimal @id @db.Decimal(78, 0)
primaryId Decimal @db.Decimal(78, 0)
chainId Decimal @db.Decimal(78, 0)
model Claims {
id Int
chain_id Int
title String
url String
description String
createdAt Decimal @db.Decimal(78, 0)
isBanned Int
ownerId String
accepted Int
bountyId Decimal @db.Decimal(78, 0)
issuerId String
issuer User @relation(fields: [issuerId], references: [id])
bounty Bounty @relation(fields: [bountyId], references: [id])
}

model ParticipantBounty {
id Decimal @id @db.Decimal(78, 0)
amount String
userId String
bountyId Decimal @db.Decimal(78, 0)
user User @relation(fields: [userId], references: [id])
bounty Bounty @relation(fields: [bountyId], references: [id])
}

model User {
id String @id
ens String?
degenName String?
participations ParticipantBounty[]
bounties Bounty[]
claims Claim[]
}
url String
issuer String
is_banned Boolean?
is_accepted Boolean?
bounty_id Int
owner String

model ponder_meta {
key String @id
value Json?
bounty Bounties? @relation(fields: [bounty_id, chain_id], references: [id, chain_id])
issuerUser Users? @relation(fields: [issuer], references: [address])

@@map("_ponder_meta")
@@id([id, chain_id])
}

model ponder_reorg__Bounty {
id Decimal @db.Decimal(78, 0)
primaryId Decimal? @db.Decimal(78, 0)
chainId Decimal? @db.Decimal(78, 0)
title String?
description String?
amount String?
issuer String?
createdAt Decimal? @db.Decimal(78, 0)
inProgress Int?
isCanceled Int?
isBanned Int?
isMultiplayer Int?
yes Decimal? @db.Decimal(78, 0)
no Decimal? @db.Decimal(78, 0)
deadline Decimal? @db.Decimal(78, 0)
operation_id Int @id @default(autoincrement())
checkpoint String @db.VarChar(75)
operation Int

@@map("_ponder_reorg__Bounty")
}
model ParticipationsBounties {
user_address String
bounty_id Int
chain_id Int
amount String

model ponder_reorg__Claim {
id Decimal @db.Decimal(78, 0)
primaryId Decimal? @db.Decimal(78, 0)
chainId Decimal? @db.Decimal(78, 0)
title String?
url String?
description String?
createdAt Decimal? @db.Decimal(78, 0)
isBanned Int?
ownerId String?
accepted Int?
bountyId Decimal? @db.Decimal(78, 0)
issuerId String?
operation_id Int @id @default(autoincrement())
checkpoint String @db.VarChar(75)
operation Int
bounty Bounties? @relation(fields: [bounty_id, chain_id], references: [id, chain_id])
user Users? @relation(fields: [user_address], references: [address])

@@map("_ponder_reorg__Claim")
@@id([user_address, bounty_id, chain_id])
}

model ponder_reorg__ParticipantBounty {
id Decimal @db.Decimal(78, 0)
amount String?
userId String?
bountyId Decimal? @db.Decimal(78, 0)
operation_id Int @id @default(autoincrement())
checkpoint String @db.VarChar(75)
operation Int

@@map("_ponder_reorg__ParticipantBounty")
}
model Users {
address String
ens String?
degen_name String?

model ponder_reorg__User {
id String
ens String?
degenName String?
operation_id Int @id @default(autoincrement())
checkpoint String @db.VarChar(75)
operation Int
participations ParticipationsBounties[]
claims Claims[]
bounties Bounties[]

@@map("_ponder_reorg__User")
@@id([address])
}
6 changes: 3 additions & 3 deletions src/app/[netname]/bounty/[id]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {

const bounty =
id !== 'null'
? await prisma.bounty.findFirst({
? await prisma.bounties.findFirst({
where: {
primaryId: id,
chainId: chain.id,
id: Number(id),
chain_id: chain.id,
},
})
: null;
Expand Down
21 changes: 11 additions & 10 deletions src/components/account/AccountInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function AccountInfo({ address }: { address: string }) {
const bounties = trpc.userBounties.useQuery(
{
address,
chainId: chain.id.toString(),
chainId: chain.id,
},
{
enabled: !!address,
Expand All @@ -26,7 +26,7 @@ export default function AccountInfo({ address }: { address: string }) {
const claims = trpc.userClaims.useQuery(
{
address,
chainId: chain.id.toString(),
chainId: chain.id,
},
{
enabled: !!address,
Expand All @@ -35,7 +35,7 @@ export default function AccountInfo({ address }: { address: string }) {
const NFTs = trpc.userNFTs.useQuery(
{
address,
chainId: chain.id.toString(),
chainId: chain.id,
},
{
enabled: !!address,
Expand Down Expand Up @@ -69,8 +69,8 @@ export default function AccountInfo({ address }: { address: string }) {
useEffect(() => {
const totalAmount =
claims.data
?.filter((claim) => claim.accepted)
.flatMap((claim) => claim.bounty.amount)
?.filter((claim) => claim.is_accepted)
.flatMap((claim) => claim.bounty!.amount)
.reduce((prev, curr) => BigInt(prev) + BigInt(curr), BigInt(0)) ||
BigInt(0);
setTotalETHEarn(formatEther(totalAmount));
Expand Down Expand Up @@ -118,7 +118,8 @@ export default function AccountInfo({ address }: { address: string }) {
<div>
completed claims:{' '}
<span className='font-bold'>
{claims.data?.filter((claim) => claim.accepted).length ?? 0}
{claims.data?.filter((claim) => claim.is_accepted).length ??
0}
</span>
</div>
<div>
Expand Down Expand Up @@ -171,12 +172,12 @@ export default function AccountInfo({ address }: { address: string }) {
claims={
claims.data?.map((claim) => {
return {
id: claim.primaryId.toString(),
id: claim.id.toString(),
title: claim.title,
description: claim.description,
issuer: claim.issuer.id,
bountyId: claim.bounty.primaryId.toString(),
accepted: Boolean(claim.accepted),
issuer: claim.issuer,
bountyId: claim.bounty!.id.toString(),
accepted: claim.is_accepted || false,
url: claim.url,
};
}) ?? []
Expand Down
32 changes: 15 additions & 17 deletions src/components/bounty/BountyClaims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ export default function BountyClaims({ bountyId }: { bountyId: string }) {

const claims = trpc.bountyClaims.useInfiniteQuery(
{
bountyId,
chainId: chain.id.toString(),
bountyId: Number(bountyId),
chainId: chain.id,
limit: PAGE_SIZE,
},
{
getNextPageParam: (lastPage) => lastPage.nextCursor?.toString(),
getNextPageParam: (lastPage) => lastPage.nextCursor,
enabled: !!bountyId,
}
);

const { data: votingClaim } = trpc.claim.useQuery(
{
claimId: votingClaimId?.toString() ?? '',
chainId: chain.id.toString(),
claimId: Number(votingClaimId),
chainId: chain.id,
},
{
enabled: !!votingClaimId,
Expand All @@ -47,8 +47,8 @@ export default function BountyClaims({ bountyId }: { bountyId: string }) {

const { data: bounty } = trpc.bounty.useQuery(
{
id: bountyId,
chainId: chain.id.toString(),
id: Number(bountyId),
chainId: chain.id,
},
{
enabled: !!bountyId,
Expand Down Expand Up @@ -80,22 +80,20 @@ export default function BountyClaims({ bountyId }: { bountyId: string }) {
votingClaim
? {
...votingClaim,
accepted: Boolean(votingClaim?.accepted),
id: votingClaim?.primaryId.toString(),
bountyId: votingClaim?.bountyId.toString(),
createdAt: BigInt(votingClaim?.createdAt.toString()),
issuer: votingClaim?.issuer.id,
accepted: votingClaim.is_accepted || false,
id: votingClaim.id.toString(),
bountyId: votingClaim.bounty_id.toString(),
issuer: votingClaim.issuer,
}
: null
}
claims={claims.data.pages.flatMap((page) => {
return page.items.map((item) => ({
...item,
accepted: Boolean(item.accepted),
id: item.primaryId.toString(),
issuer: item.issuer.id,
bountyId: item.bountyId.toString(),
createdAt: BigInt(item.createdAt.toString()),
accepted: item.is_accepted || false,
id: item.id.toString(),
issuer: item.issuer,
bountyId: item.bounty_id.toString(),
}));
})}
/>
Expand Down
Loading
Loading