Skip to content

Commit

Permalink
set up max tx history page size
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Jun 20, 2024
1 parent 9ced280 commit 74c976e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/src/routes/getTransactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { fromCursorHash, toCursorHash } from '@/utils/pagination'

import { addressRegex } from '.'

const MAX_PAGE_SIZE = 20

function getCursorQuery(cursor?: string): Parameters<typeof and> {
const [transferId, timestamp] = fromCursorHash(cursor)

Expand All @@ -21,8 +23,8 @@ function getCursorQuery(cursor?: string): Parameters<typeof and> {
}

interface TransactionHistoryQuery {
address: string
first: string
address?: string
first?: string
after?: string
}

Expand All @@ -32,14 +34,14 @@ export function getTransactionHistory(fastify: FastifyInstance) {

async (request, reply) => {
const { address, first: firstStr, after } = request.query as TransactionHistoryQuery
const first = Number(firstStr)
const first = Number(firstStr ?? MAX_PAGE_SIZE)

if (!address) {
return reply.status(400).send({ error: 'Address is required.' })
}

if (!first) {
return reply.status(400).send({ error: 'First is required.' })
if (first > MAX_PAGE_SIZE) {
return reply.status(400).send({ error: `First cannot exceed ${MAX_PAGE_SIZE}.` })
}

// Validate address format
Expand Down

0 comments on commit 74c976e

Please sign in to comment.