Skip to content

Conversation

@ignaciosantise
Copy link
Collaborator

Summary

  • Use the URL API and searchParams for constructing query parameters instead of manual string concatenation
  • Ensures all parameters, including chainId, are properly encoded according to standards
  • Improves code readability and maintainability

Changes

Updated BalanceService to use the standard URL constructor and searchParams API when building the balance API URL. This replaces the previous approach of manually concatenating query parameters, which only applied encodeURIComponent to the projectId.

Fixes potential encoding issues with special characters in query parameters.

Replace manual URL concatenation with the URL API and searchParams for more reliable and standards-compliant query parameter encoding, especially for the chainId parameter.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 30, 2026 19:13
@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-examples Ready Ready Preview, Comment Jan 30, 2026 7:15pm

Request Review

@claude
Copy link

claude bot commented Jan 30, 2026

Claude finished @ignaciosantise's task in 40s —— View job


Code Review Complete

  • Read changed file for full context
  • Run automated checks
  • Perform code quality review
  • Post findings

✅ No issues found

Review Summary:

  • PR Size: 1 file, 9 lines changed - appropriate scope
  • Code Quality: Proper use of URL API for query parameter encoding
  • Security: Improves security by ensuring all parameters are properly encoded
  • Type Safety: Maintained with correct types
  • Best Practices: Follows modern web API standards, more maintainable than string concatenation

The change correctly replaces manual string concatenation with the standard URL API, which automatically handles proper encoding of all query parameters including special characters in chainId (CAIP-2 format like "eip155:1").

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the URL construction in BalanceService to use the URL API and searchParams instead of manual string concatenation. The goal is to ensure proper encoding of query parameters and improve code maintainability.

Changes:

  • Replaced manual string concatenation with URL constructor and searchParams API for building the balance API endpoint
  • All query parameters (projectId, currency, chainId, st, sv) now use searchParams.set() for proper encoding

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const url = `${baseUrl}${BALANCE_API_PATH}/${address}/balance?projectId=${encodeURIComponent(
projectId,
)}&currency=usd&chainId=${chainId}&st=walletkit&sv=1.0.0`;
const url = new URL(`${BALANCE_API_PATH}/${address}/balance`, baseUrl);
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Potential breaking change in URL construction. When BALANCE_API_PATH starts with / (which it does: '/v1/account'), it's treated as an absolute path from the origin when used with the URL constructor. This means:

  • Old behavior: ${baseUrl}${BALANCE_API_PATH} - simple concatenation
  • New behavior: The leading / in BALANCE_API_PATH makes it resolve from the origin

If ENV_BLOCKCHAIN_API_URL is something like https://example.com/api, the old code would produce https://example.com/api/v1/account/..., but the new code will produce https://example.com/v1/account/... (dropping the /api path component).

To maintain backward compatibility while using the URL API, either:

  1. Remove the leading / from BALANCE_API_PATH and ensure baseUrl ends with /, or
  2. Construct the full path first without the leading /: new URL(\${BALANCE_API_PATH.slice(1)}/${address}/balance`, baseUrl)`, or
  3. If baseUrl is always just an origin without path components, document this requirement clearly.
Suggested change
const url = new URL(`${BALANCE_API_PATH}/${address}/balance`, baseUrl);
const url = new URL(`${BALANCE_API_PATH.slice(1)}/${address}/balance`, baseUrl);

Copilot uses AI. Check for mistakes.
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