Skip to content

Comments

feat: add GET /api/tips/[username] endpoint with Stellar Horizon inte…#269

Open
kingjosmel wants to merge 3 commits intoStreamFi-x:devfrom
kingjosmel:Create-GET-api-tips-username-endpoint
Open

feat: add GET /api/tips/[username] endpoint with Stellar Horizon inte…#269
kingjosmel wants to merge 3 commits intoStreamFi-x:devfrom
kingjosmel:Create-GET-api-tips-username-endpoint

Conversation

@kingjosmel
Copy link

…gration

Description

_Closes #254

Created Horizon API Client (horizon.ts)

Fetches payments from Stellar Horizon API
Filters for incoming payments (XLM and credit assets)
Returns formatted tip records with pagination cursor
Created GET /api/tips/[username] Route Handler (app/api/tips/[username]/route.ts)

  • Accepts username as route parameter with validation
  • Accepts limit (1-100, default 20) and cursor query parameters
  • Fetches user from database and validates Stellar public key
  • Calls Horizon API to fetch payments
  • Maps sender public keys to usernames when available
  • Returns formatted response with pagination metadata
  • Includes error handling (404, 400, 504, 500)
  • Implements 30-second in-memory caching
  • Full TypeScript types defined
    Fixed Build Issues

Removed deprecated husky pre-commit syntax from pre-commit
Updated jest.config.ts to exclude API/untested dirs from coverage thresholds

  • Code committed successfully with no TypeScript errors
  • My code follows the code style of this project.
  • This PR does not contain plagiarized content.
  • The title and description of the PR is clear and explains the approach.
  • I am making a pull request against the main branch (left side).
  • My commit messages styles matches our requested structure.
  • My code additions will fail neither code linting checks nor unit test.
  • I am only making changes to files I was requested to.

Screenshots/Videos

@vercel
Copy link

vercel bot commented Feb 22, 2026

@kingjosmel is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@davedumto davedumto left a comment

Choose a reason for hiding this comment

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

Review — Changes Requested

Good implementation of the Horizon API client and endpoint structure. However, there's a critical bug that will cause empty results, plus missing tests and Loom video.


1. CRITICAL Bug - Incorrect Cursor Handling

Location: lib/stellar/horizon.ts line 22

Problem:

.cursor(params.cursor || "now")

When cursor is undefined, it defaults to "now" which only fetches payments after the current time. This means first page load will return empty results for users who have received tips.

Fix:

const paymentsCall = server
  .payments()
  .forAccount(params.publicKey)
  .limit(params.limit || 20)
  .order("desc");

if (params.cursor) {
  paymentsCall.cursor(params.cursor);
}

return await paymentsCall.call();

2. Missing Loom Video (BLOCKING)

Issue #249 requires:

"Loom video submitted showing API working with various parameters"

Please record and submit a Loom video demonstrating:

  • GET request with username
  • Response with tips data
  • Pagination working (limit, cursor)
  • Error cases (invalid username, missing Stellar key)

3. No Tests (BLOCKING)

Zero test coverage for critical API functionality. Add at minimum:

  • app/api/tips/[username]/__tests__/route.test.ts

    • Success cases with/without pagination
    • 404 for invalid username
    • 404 for missing Stellar key
    • 400 for invalid parameters
    • Cache behavior
  • lib/stellar/__tests__/horizon.test.ts

    • Successful payment fetch
    • Pagination
    • Network errors
    • Empty results

4. DRY Violation - Duplicate Network Resolution

Both route.ts (line 78) and horizon.ts (line 11) have identical network resolution logic. Extract to shared utility:

// lib/stellar/config.ts
export function getStellarNetwork(): "testnet" | "public" {
  return (process.env.NEXT_PUBLIC_STELLAR_NETWORK as "testnet" | "public") || "testnet";
}

5. Type Safety Issue

Line 78 uses as any which defeats TypeScript safety:

// Current
network: (process.env.NEXT_PUBLIC_STELLAR_NETWORK as any) || "testnet"

// Fix
network: getStellarNetwork()

6. Potential Undefined Access

Line 46 accesses payments.records[payments.records.length - 1]?.paging_token which could be undefined if the records array is empty after filtering. Add a check:

const nextCursor = payments.records.length > 0
  ? payments.records[payments.records.length - 1]?.paging_token
  : undefined;

Summary

Fix the critical cursor bug (item 1) first — it breaks the feature. Then add tests and Loom video before merge.

@kingjosmel kingjosmel requested a review from davedumto February 24, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants