Skip to content

Commit

Permalink
Merge pull request #62 from GenerationSoftware/vault-api
Browse files Browse the repository at this point in the history
Added `/api/vault`
  • Loading branch information
Ncookiez authored Jun 21, 2024
2 parents 2e1d530 + 0b1c945 commit c7081bf
Show file tree
Hide file tree
Showing 5 changed files with 503 additions and 8 deletions.
39 changes: 39 additions & 0 deletions apps/app/src/app/api/vault/[chainId]/[vaultAddress]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NextRequest, NextResponse } from 'next/server'
import {
getChainIdFromParams,
getPrizePool,
getVault,
getVaultAddressFromParams,
getVaultData
} from './utils'

export interface VaultApiParams {
chainId: string
vaultAddress: string
}

export async function GET(
_req: NextRequest,
ctx: { params: VaultApiParams }
): Promise<NextResponse> {
const chainId = getChainIdFromParams(ctx.params)
const vaultAddress = getVaultAddressFromParams(ctx.params)

if (!chainId) {
return NextResponse.json({ message: 'Invalid network' }, { status: 400 })
}

if (!vaultAddress) {
return NextResponse.json({ message: 'Invalid vault address' }, { status: 400 })
}

try {
const vault = getVault(chainId, vaultAddress)
const prizePool = getPrizePool(vault)
const vaultData = await getVaultData(vault, prizePool)

return NextResponse.json(vaultData, { status: 200 })
} catch {
return NextResponse.json({ message: 'Could not fetch vault data' }, { status: 500 })
}
}
Loading

0 comments on commit c7081bf

Please sign in to comment.