Skip to content
Open
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
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"react-social-icons": "^6.25.0",
"recharts": "^2.15.4",
"sonner": "^1.7.4",
"swiper": "^12.0.3",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.9",
Expand Down
3 changes: 3 additions & 0 deletions src/app/(app)/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { OneTimeTasksSection } from "@/components/dashboard/OneTimeTasksSection"
import { SBTGatingModal } from "@/components/modals/SBTGatingModal"
import { TransactionFeedbackModal } from "@/components/modals/TransactionFeedbackModal"
import { ReferralModal } from "@/components/modals/ReferralModal"
import { EcosystemSetCarousel } from "@/components/dashboard/EcosystemSetsCarousel"

import type { TaskName } from "@/hooks/use-dashboard-tasks"

Expand Down Expand Up @@ -204,6 +205,8 @@ const DashboardContent = () => {
</div>
</div>

<EcosystemSetCarousel />

<OneTimeTasksAccordion
tasks={dashboardTasks.oneTimeTasks}
hasInitialized={userOnboarding.hasInitialized}
Expand Down
99 changes: 99 additions & 0 deletions src/app/api/user-community-activity/[wallet_address]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import "server-only"
import { NextRequest, NextResponse } from "next/server"
import { pool } from "@/lib/fast-db"

function isValidWalletAddress(address: string): boolean {
return /^0x[a-fA-F0-9]{40}$/.test(address)
}

async function getValidatedWalletAddress(
params: Promise<{ wallet_address: string }>
): Promise<{ address: string } | { error: NextResponse }> {
const { wallet_address } = await params

if (!wallet_address) {
return {
error: NextResponse.json({ error: "Wallet address is required" }, { status: 400 }),
}
}

if (!isValidWalletAddress(wallet_address)) {
return {
error: NextResponse.json({ error: "Invalid wallet address format" }, { status: 400 }),
}
}

return { address: wallet_address.toLowerCase() }
}

/**
* GET /api/user-community-activity/[wallet_address]
* Returns the latest activity per entity for the user (e.g. ecosystem set verifications).
*/
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ wallet_address: string }> }
) {
try {
const result = await getValidatedWalletAddress(params)
if ("error" in result) return result.error

const { rows } = await pool.query(
`SELECT entity, activity
FROM (
SELECT entity, activity,
ROW_NUMBER() OVER (PARTITION BY entity ORDER BY created_at DESC) AS rn
FROM user_activity
WHERE user_address = $1
) sub
WHERE rn = 1`,
[result.address]
)

const activities: Record<string, boolean> = {}
for (const row of rows) {
activities[row.entity] = row.activity === true
}

return NextResponse.json({ activities })
} catch (err) {
console.error("Error fetching user community activity:", err)
return NextResponse.json({ error: "Database query failed" }, { status: 500 })
}
}

/**
* POST /api/user-community-activity/[wallet_address]
* Save or update one entity's activity. Body: { entity: string, activity: boolean }
*/
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ wallet_address: string }> }
) {
try {
const result = await getValidatedWalletAddress(params)
if ("error" in result) return result.error

const body = await request.json()
const entity = typeof body?.entity === "string" ? body.entity.trim() : null
const activity = body?.activity === true || body?.activity === "true"

if (!entity) {
return NextResponse.json(
{ error: "entity is required and must be a non-empty string" },
{ status: 400 }
)
}

await pool.query(
`INSERT INTO user_activity (user_address, entity, activity)
VALUES ($1, $2, $3)`,
[result.address, entity, activity]
)

return NextResponse.json({ ok: true, entity, activity }, { status: 201 })
} catch (err) {
console.error("Error saving user community activity:", err)
return NextResponse.json({ error: "Database operation failed" }, { status: 500 })
}
}
Loading
Loading