Skip to content
Open
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
9 changes: 6 additions & 3 deletions wallets/rn_cli_wallet/src/services/BalanceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ async function fetchBalanceForChain(
return [];
}

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.
url.searchParams.set('projectId', projectId);
url.searchParams.set('currency', 'usd');
url.searchParams.set('chainId', chainId);
url.searchParams.set('st', 'walletkit');
url.searchParams.set('sv', '1.0.0');

const response = await fetch(url.toString(), {
headers: {
Expand Down
Loading