Skip to content

Commit

Permalink
added interface for IHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 28, 2023
1 parent 8386735 commit 684cc22
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions packages/protocol-sdk/src/apis/http-api-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ export const retries = async <T>(
throw err;
}
};

export interface IHttpClient {
get: typeof get;
post: typeof post;
retries: typeof retries;
}

export const httpClient: IHttpClient = {
get,
post,
retries,
};
8 changes: 4 additions & 4 deletions packages/protocol-sdk/src/mint/mint-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as httpClientBase from "../apis/http-api-base";
import { httpClient as defaultHttpClient, IHttpClient } from "../apis/http-api-base";
import { paths } from "../apis/generated/discover-api-types";
import { ZORA_API_BASE } from "../constants";
import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
Expand All @@ -25,11 +25,11 @@ export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
};

export class MintAPIClient {
httpClient: typeof httpClientBase;
httpClient: IHttpClient;
networkConfig: NetworkConfig;

constructor(chainId: number, httpClient?: typeof httpClientBase) {
this.httpClient = httpClient || httpClientBase;
constructor(chainId: number, httpClient?: IHttpClient) {
this.httpClient = httpClient || defaultHttpClient;
this.networkConfig = getApiNetworkConfigForChain(chainId);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-sdk/src/mint/mint-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
zeroAddress,
http,
} from "viem";
import * as httpClientBase from "../apis/http-api-base";
import { IHttpClient } from "../apis/http-api-base";
import { MintAPIClient, MintableGetTokenResponse } from "./mint-api-client";
import { SimulateContractParameters } from "viem";
import {
Expand Down Expand Up @@ -44,7 +44,7 @@ class MintClient {
constructor(
chain: Chain,
publicClient?: PublicClient,
httpClient?: typeof httpClientBase,
httpClient?: IHttpClient,
) {
this.apiClient = new MintAPIClient(chain.id, httpClient);
this.publicClient =
Expand Down Expand Up @@ -141,7 +141,7 @@ export function createMintClient({
}: {
chain: Chain;
publicClient?: PublicClient;
httpClient?: typeof httpClientBase;
httpClient?: IHttpClient;
}) {
return new MintClient(chain, publicClient, httpClient);
}
Expand Down

0 comments on commit 684cc22

Please sign in to comment.