@@ -8,7 +8,7 @@ import { ftch, jsonrpc, replayable } from 'micro-ftch';
88
99let enabled = false;
1010const net = ftch(fetch, {
11- killswitch : () => enabled,
11+ isValidRequest : () => enabled,
1212 log: (url, options) => console.log(url, options),
1313 timeout: 5000,
1414 concurrencyLimit: 10,
@@ -147,10 +147,9 @@ const getRequestInfo = (req: UnPromise<ReturnType<FetchFn>>) => ({
147147 */
148148export function ftch ( fetchFunction : FetchFn , opts : FtchOpts = { } ) : FetchFn {
149149 const ks = opts . isValidRequest || opts . killswitch ;
150- if ( ks && typeof ks !== 'function' ) throw new Error ( 'opts.killswitch must be a function' ) ;
150+ if ( ks && typeof ks !== 'function' ) throw new Error ( 'opts.isValidRequest must be a function' ) ;
151151 const noNetwork = ( url : string ) => ks && ! ks ( url ) ;
152152 const wrappedFetch : FetchFn = async ( url , reqOpts = { } ) => {
153- if ( opts . log ) opts . log ( url , reqOpts ) ;
154153 const abort = new AbortController ( ) ;
155154 let timeout = undefined ;
156155 if ( opts . timeout !== undefined || reqOpts . timeout !== undefined ) {
@@ -171,6 +170,7 @@ export function ftch(fetchFunction: FetchFn, opts: FtchOpts = {}): FetchFn {
171170 h . forEach ( ( v , k ) => headers . set ( k , v ) ) ;
172171 }
173172 if ( noNetwork ( url ) ) throw new Error ( 'network disabled' ) ;
173+ if ( opts . log ) opts . log ( url , reqOpts ) ;
174174 const res = await fetchFunction ( url , {
175175 referrerPolicy : 'no-referrer' , // avoid sending referrer by default
176176 ...reqOpts ,
@@ -237,13 +237,13 @@ export class JsonrpcProvider implements JsonrpcInterface {
237237 private batchSize : number ;
238238 private headers : Record < string , string > ;
239239 private queue : ( { method : string ; params : RpcParams } & PromiseCb < any > ) [ ] = [ ] ;
240- constructor (
241- private fetchFunction : FetchFn ,
242- readonly rpcUrl : string ,
243- options : NetworkOpts = { }
244- ) {
240+ private fetchFunction : FetchFn ;
241+ readonly rpcUrl : string ;
242+ constructor ( fetchFunction : FetchFn , rpcUrl : string , options : NetworkOpts = { } ) {
245243 if ( typeof fetchFunction !== 'function' ) throw new Error ( 'fetchFunction is required' ) ;
246244 if ( typeof rpcUrl !== 'string' ) throw new Error ( 'rpcUrl is required' ) ;
245+ this . fetchFunction = fetchFunction ;
246+ this . rpcUrl = rpcUrl ;
247247 this . batchSize = options . batchSize === undefined ? 1 : options . batchSize ;
248248 this . headers = options . headers || { } ;
249249 if ( typeof this . headers !== 'object' ) throw new Error ( 'invalid headers: expected object' ) ;
0 commit comments