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 2f9c2db
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/ncw-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ export class NcwApiClient implements NcwSdk {

constructor(private readonly apiClient: ApiClient) { }

public normalizePath(baseUrl: string, params: string): string {
return params ? `${baseUrl}?${params.toString()}` : baseUrl;
}

public async getSupportedAssets({ pageCursor, pageSize, onlyBaseAssets }: NCW.GetSupportedAssetsPayload): Promise<Web3PagedResponse<NCW.WalletAssetResponse>> {
const params = new URLSearchParams({
...(pageCursor && { pageCursor }),
...(pageSize && { pageSize: pageSize.toString() }),
...(onlyBaseAssets !== undefined && { onlyBaseAssets: String(onlyBaseAssets) }),
});

return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}/supported_assets?${params.toString()}`);
const url = this.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 +82,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}?${params.toString()}`);
const url = this.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 +97,8 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(
`${this.NCW_BASE_PATH}/${walletId}/accounts?${params.toString()}`);
const url = this.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 +117,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 = this.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 @@ -132,9 +138,8 @@ export class NcwApiClient implements NcwSdk {
...(sort && { sort }),
...(order && { order }),
});

return await this.apiClient.issueGetRequest(
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`);
const url = this.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 2f9c2db

Please sign in to comment.