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 747a9e5
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/ncw-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,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 +77,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 +92,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 +112,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 +134,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 All @@ -148,3 +149,9 @@ export class NcwApiClient implements NcwSdk {
{});
}
}

// This function allows backward compatibility with previous functions of axois that did not omit ? for
// Urls with no params. This function will make sure we are omitting the ? before signing it
function normalizePath(rawPath: string) {
return rawPath.replace(/\?$/, "");
}

0 comments on commit 747a9e5

Please sign in to comment.