Skip to content

Commit

Permalink
Add fetcher option to proxy to override the fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
lcswillems committed Nov 13, 2024
1 parent 1f4e18c commit 6fce3e3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions xsuite/src/proxy/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ import {

export class Proxy {
proxyUrl: string;
headers: HeadersInit;
explorerUrl: string;
headers: HeadersInit;
fetcher: Fetcher;
blockNonce?: number;
// TODO-MvX: remove this when blockchain fixed
pauseAfterSend?: number;
pauseAfterSend?: number; // TODO-MvX: remove this when blockchain fixed

constructor(params: ProxyParams) {
params = typeof params === "string" ? { proxyUrl: params } : params;
this.proxyUrl = params.proxyUrl;
this.headers = params.headers ?? {};
this.explorerUrl = params.explorerUrl ?? "";
this.headers = params.headers ?? {};
this.fetcher = params.fetcher ?? fetch;
this.blockNonce = params.blockNonce;
this.pauseAfterSend = params.pauseAfterSend;
}
Expand Down Expand Up @@ -74,7 +75,7 @@ export class Proxy {
init.method = "POST";
init.body = JSON.stringify(data);
}
return fetch(
return this.fetcher(
this.proxyUrl + makePath(path, { blockNonce: this.blockNonce }),
init,
).then((r) => r.json());
Expand Down Expand Up @@ -731,13 +732,15 @@ type ProxyParams = Prettify<

type ProxyNewRealnetParams = {
proxyUrl?: string;
headers?: HeadersInit;
explorerUrl?: string;
headers?: HeadersInit;
fetcher?: Fetcher;
blockNonce?: number;
// TODO-MvX: remove this when blockchain fixed
pauseAfterSend?: number;
pauseAfterSend?: number; // TODO-MvX: remove this when blockchain fixed
};

type Fetcher = (input: string, init?: RequestInit) => Promise<Response>;

type BroadTx = Tx | RawTx;

export type Tx = {
Expand Down

0 comments on commit 6fce3e3

Please sign in to comment.