Skip to content

Commit

Permalink
fixing COR-44075 - After the latest axios upgrade from 0.27.2 to 1.6.…
Browse files Browse the repository at this point in the history
…0 n urls with ? but not params the ? character is omitted and we get are reaching a siguration that we are signing https://path/to/somwehere? but sending the request with https://path/to/somewhere
  • Loading branch information
AlonFireblocks committed Dec 11, 2023
1 parent ce6269a commit 052233e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/ncw-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
} from "./types";
import { NcwSdk } from "./ncw-sdk";

function normalizePath(rawPath: string) {
return rawPath.replace(/\?$/, "");
}
export class NcwApiClient implements NcwSdk {
private readonly NCW_BASE_PATH = "/v1/ncw/wallets";

Expand All @@ -17,8 +20,8 @@ export class NcwApiClient implements NcwSdk {
...(pageSize && { pageSize: pageSize.toString() }),
...(onlyBaseAssets !== undefined && { onlyBaseAssets: String(onlyBaseAssets) }),
});

return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}/supported_assets?${params.toString()}`);
const url = normalizePath(`${this.NCW_BASE_PATH}/supported_assets?${params.toString()}`);
return await this.apiClient.issueGetRequest(url);
}

public async createWallet(): Promise<{ walletId: string; enabled: boolean; }> {
Expand Down Expand Up @@ -77,7 +80,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}?${params.toString()}`);
const url = normalizePath(`${this.NCW_BASE_PATH}?${params.toString()}`);
return await this.apiClient.issueGetRequest(url);
}

public async getWalletAccounts(walletId: string, { pageCursor, pageSize, sort, order }: NCW.GetWalletsPayload = {}): Promise<Web3PagedResponse<{
Expand All @@ -91,8 +95,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(
`${this.NCW_BASE_PATH}/${walletId}/accounts?${params.toString()}`);
const url = normalizePath(`${this.NCW_BASE_PATH}/${walletId}/accounts?${params.toString()}`);
return await this.apiClient.issueGetRequest(url);
}

public async getWalletAccount(walletId: string, accountId: number): Promise<{
Expand All @@ -111,8 +115,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets?${params.toString()}`);
const url = normalizePath(`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets?${params.toString()}`);
return await this.apiClient.issueGetRequest(url);
}

public async getWalletAsset(walletId: string, accountId: number, assetId: string): Promise<NCW.WalletAssetResponse> {
Expand All @@ -133,8 +137,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`);
const url = normalizePath(`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`);
return await this.apiClient.issueGetRequest(url);
}

public async getWalletAssetBalance(walletId: string, accountId: number, assetId: string): Promise<AssetResponse> {
Expand Down

0 comments on commit 052233e

Please sign in to comment.