Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/app/api/transactions/history/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export async function GET(req: NextRequest) {

const supabase = createServerClient()
const { searchParams } = new URL(req.url)
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 100)
const rawLimit = parseInt(searchParams.get('limit') || '50')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flash Review

🐛 Bugs: The previous parseInt could result in NaN if the limit parameter was not a valid number (e.g., limit=abc), which would then propagate to Math.min(NaN, 100) resulting in NaN. This change correctly handles NaN values and enforces a minimum limit of 1, improving robustness and preventing invalid database queries. This is a good improvement.

const limit = isNaN(rawLimit) || rawLimit < 1 ? 50 : Math.min(rawLimit, 100)

// 1. Fetch Sent Transactions (where customer_wallet = walletAddress)
const { data: sentTransactions, error: sentError } = await supabase
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/transactions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function GET(req: NextRequest) {
const supabase = createServerClient()
const { searchParams } = new URL(req.url)
const paymentLinkId = searchParams.get('payment_link_id')
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 100)
const rawLimit = parseInt(searchParams.get('limit') || '50')
const limit = isNaN(rawLimit) || rawLimit < 1 ? 50 : Math.min(rawLimit, 100)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let query = (supabase.from('transactions') as any)
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/v1/payment-links/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ export async function GET(req: NextRequest) {
}

const { searchParams } = new URL(req.url)
const limit = Math.min(parseInt(searchParams.get('limit') || '10'), 100)
const offset = parseInt(searchParams.get('offset') || '0')
const rawLimit = parseInt(searchParams.get('limit') || '10')
const limit = isNaN(rawLimit) || rawLimit < 1 ? 10 : Math.min(rawLimit, 100)
const rawOffset = parseInt(searchParams.get('offset') || '0')
const offset = isNaN(rawOffset) || rawOffset < 0 ? 0 : rawOffset

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const supabase = createServerClient() as any
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/v1/transactions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export async function GET(req: NextRequest) {
}

const { searchParams } = new URL(req.url)
const limit = Math.min(parseInt(searchParams.get('limit') || '10'), 100)
const offset = parseInt(searchParams.get('offset') || '0')
const rawLimit = parseInt(searchParams.get('limit') || '10')
const limit = isNaN(rawLimit) || rawLimit < 1 ? 10 : Math.min(rawLimit, 100)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flash Review

🐛 Bug: The previous parseInt for limit and offset could result in NaN if the query parameters were non-numeric (e.g., limit=abc). Passing NaN to Supabase queries for pagination can lead to unexpected errors or incorrect results.

Fix: Explicitly checking isNaN and providing default values, along with range validation (rawLimit < 1, rawOffset < 0), significantly improves the robustness of the API. This prevents potential query failures and ensures valid pagination parameters are always used.

const rawOffset = parseInt(searchParams.get('offset') || '0')
const offset = isNaN(rawOffset) || rawOffset < 0 ? 0 : rawOffset
const status = searchParams.get('status')
const paymentLinkId = searchParams.get('payment_link_id')

Expand Down
Loading