Skip to content

Commit

Permalink
feat: allow pass a ordersVersion for orders queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrvk committed Feb 13, 2025
1 parent 4674215 commit f877bc3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/api/fusion-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
OrderStatusResponse,
OrdersByMakerResponse
} from './orders'
import {Version} from './version'
import {OrdersVersion} from './ordersVersion'
import {AxiosProviderConnector} from '../connector'

export class FusionApi {
Expand Down Expand Up @@ -78,9 +78,9 @@ export class FusionApi {

getActiveOrders(
params: ActiveOrdersRequest = ActiveOrdersRequest.new(),
version = Version._2_1
ordersVersion = OrdersVersion._2_1
): Promise<ActiveOrdersResponse> {
return this.ordersApi.getActiveOrders(params, version)
return this.ordersApi.getActiveOrders(params, ordersVersion)
}

getOrderStatus(params: OrderStatusRequest): Promise<OrderStatusResponse> {
Expand All @@ -89,9 +89,9 @@ export class FusionApi {

getOrdersByMaker(
params: OrdersByMakerRequest,
version = Version._2_1
ordersVersion = OrdersVersion._2_1
): Promise<OrdersByMakerResponse> {
return this.ordersApi.getOrdersByMaker(params, version)
return this.ordersApi.getOrdersByMaker(params, ordersVersion)
}

submitOrder(params: RelayerRequest): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './orders/index'
export * from './fusion-api'
export * from './pagination'
export * from './types'
export * from './ordersVersion'
2 changes: 1 addition & 1 deletion src/api/orders/order-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe(__filename, () => {

expect(response).toEqual(expected)
expect(httpProvider.get).toHaveBeenLastCalledWith(
`${url}/orders/v2.0/1/order/status/${orderHash}?version=2.1`
`${url}/orders/v2.0/1/order/status/${orderHash}`
)
})

Expand Down
12 changes: 6 additions & 6 deletions src/api/orders/orders.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './types'
import {AxiosProviderConnector, HttpProviderConnector} from '../../connector'
import {concatQueryParams} from '../params'
import {Version, VERSION} from '../version'
import {OrdersVersion} from '../ordersVersion'

export class OrdersApi {
private static Version = 'v2.0'
Expand All @@ -32,15 +32,15 @@ export class OrdersApi {

async getActiveOrders(
params: ActiveOrdersRequest,
version: Version
ordersVersion: OrdersVersion
): Promise<ActiveOrdersResponse> {
const err = params.validate()

if (err) {
throw new Error(err)
}

const queryParams = concatQueryParams(params.build(), version)
const queryParams = concatQueryParams(params.build(), ordersVersion)
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/active/${queryParams}`

return this.httpClient.get<ActiveOrdersResponse>(url)
Expand All @@ -55,22 +55,22 @@ export class OrdersApi {
throw new Error(err)
}

const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/status/${params.orderHash}?version=${VERSION}`
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/status/${params.orderHash}`

return this.httpClient.get<OrderStatusResponse>(url)
}

async getOrdersByMaker(
params: OrdersByMakerRequest,
version: Version
ordersVersion: OrdersVersion
): Promise<OrdersByMakerResponse> {
const err = params.validate()

if (err) {
throw new Error(err)
}

const qp = concatQueryParams(params.buildQueryParams(), version)
const qp = concatQueryParams(params.buildQueryParams(), ordersVersion)
const url = `${this.config.url}/${OrdersApi.Version}/${this.config.network}/order/maker/${params.address}/${qp}`

return this.httpClient.get(url)
Expand Down
3 changes: 1 addition & 2 deletions src/api/version.ts → src/api/ordersVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const VERSION = '2.1'
export enum Version {
export enum OrdersVersion {
all = 'all',
_2_1 = '2.1',
_2_0 = '2.0'
Expand Down
4 changes: 2 additions & 2 deletions src/api/params.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Version} from './version'
import {OrdersVersion} from './ordersVersion'

/**
* Concat all params to query encoded string. if `addVersion` is true, then `version` param is added to this string
*/
export function concatQueryParams<
T extends Record<string | number, string | string[] | number | boolean>
>(params: T, version: false | Version = false): string {
>(params: T, version: false | OrdersVersion = false): string {
if (!params) {
return version ? `?version=${version}` : ''
}
Expand Down

0 comments on commit f877bc3

Please sign in to comment.