-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from GenerationSoftware/vault-api
Added `/api/vault`
- Loading branch information
Showing
5 changed files
with
503 additions
and
8 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
apps/app/src/app/api/vault/[chainId]/[vaultAddress]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | ||
} | ||
} |
Oops, something went wrong.