Skip to content

Commit 074c16e

Browse files
authored
feat: Add getHeightWithHeaders to Utility Module (#464)
- get Fn swallows response headers and only returns data - Added new get Fn that will return headers as well. Headers will be used for geo restriction
1 parent 5fc63f3 commit 074c16e

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

v4-client-js/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v4-client-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dydxprotocol/v4-client-js",
3-
"version": "1.3.17",
3+
"version": "3.2.1",
44
"description": "General client library for the new dYdX system (v4 decentralized)",
55
"main": "build/cjs/src/index.js",
66
"module": "build/esm/src/index.js",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import type { AxiosResponseHeaders } from 'axios';
2+
13
export enum RequestMethod {
24
POST = 'POST',
35
PUT = 'PUT',
46
GET = 'GET',
57
DELETE = 'DELETE',
68
}
9+
10+
export interface AxiosResponseWithGeoHeaders<Data> {
11+
data: Data;
12+
headers: AxiosResponseHeaders;
13+
}

v4-client-js/src/clients/modules/rest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ export default class RestClient {
2828
return response.data;
2929
}
3030

31+
async getWithResponseHeaders(requestPath: string, params: {} = {}): Promise<Data> {
32+
const url = `${this.host}${generateQueryPath(requestPath, params)}`;
33+
const response = await this.axiosInstance.get(url);
34+
35+
return {
36+
data: response.data,
37+
headers: response.headers,
38+
};
39+
}
40+
3141
async post(
3242
requestPath: string,
3343
params: {} = {},

v4-client-js/src/clients/modules/utility.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
ComplianceResponse,
33
ComplianceV2Response,
44
HeightResponse,
5+
HeightResponseWithHeaders,
56
TimeResponse,
67
} from '../types';
78
import RestClient from './rest';
@@ -25,6 +26,15 @@ export default class UtilityClient extends RestClient {
2526
return this.get(uri);
2627
}
2728

29+
/**
30+
* @description Get the block height of the most recent block processed by the Indexer
31+
* @returns {HeightResponse} block height and time
32+
*/
33+
async getHeightWithHeaders(): Promise<HeightResponseWithHeaders> {
34+
const uri = '/v4/height';
35+
return this.getWithResponseHeaders(uri);
36+
}
37+
2838
/**
2939
* @description Screen an address to see if it is restricted
3040
* @param {string} address evm or dydx address

v4-client-js/src/clients/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { PerpetualMarketType } from '@dydxprotocol/v4-proto/src/codegen/dydxprot
99
import BigNumber from 'bignumber.js';
1010
import Long from 'long';
1111

12+
import { AxiosResponseWithGeoHeaders } from './lib/axios/types';
13+
1214
export type Integer = BigNumber;
1315

1416
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -119,6 +121,8 @@ export interface HeightResponse {
119121
time: string;
120122
}
121123

124+
export type HeightResponseWithHeaders = AxiosResponseWithGeoHeaders<HeightResponse>;
125+
122126
export interface ComplianceResponse {
123127
restricted: boolean;
124128
reason?: string;

0 commit comments

Comments
 (0)