@snapshot-labs/snapshot.js 0.14.5 → 0.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -812,6 +812,7 @@ declare const _default: {
812
812
  utils: {
813
813
  call: typeof import("./utils").call;
814
814
  multicall: typeof import("./multicall").multicall;
815
+ fetch: typeof import("./utils").fetch;
815
816
  subgraphRequest: typeof import("./utils").subgraphRequest;
816
817
  ipfsGet: typeof import("./utils").ipfsGet;
817
818
  getUrl: typeof import("./utils").getUrl;
@@ -16,6 +16,41 @@ interface Strategy {
16
16
  export declare function call(provider: any, abi: any[], call: any[], options?: any): Promise<any>;
17
17
  export declare function subgraphRequest(url: string, query: any, options?: any): Promise<any>;
18
18
  export declare function getUrl(uri: any, gateway?: string): any;
19
+ interface FetchOptions extends RequestInit {
20
+ timeout?: number;
21
+ }
22
+ /**
23
+ * Enhanced fetch with timeout support - drop-in replacement for native fetch
24
+ *
25
+ * @param url - The URL to fetch
26
+ * @param options - Fetch options with optional timeout
27
+ * @param options.timeout - Request timeout in milliseconds (default: 30000ms). Set to 0 to disable timeout.
28
+ *
29
+ * @returns Promise that resolves to the Response object
30
+ *
31
+ * @throws {Error} Throws timeout error if request exceeds the specified timeout duration
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Uses default 30s timeout
36
+ * const response = await fetch('https://api.example.com/data');
37
+ *
38
+ * // Custom 5s timeout
39
+ * const response = await fetch('https://api.example.com/data', { timeout: 5000 });
40
+ *
41
+ * // Disable timeout
42
+ * const response = await fetch('https://api.example.com/data', { timeout: 0 });
43
+ *
44
+ * // With additional fetch options
45
+ * const response = await fetch('https://api.example.com/data', {
46
+ * timeout: 10000,
47
+ * method: 'POST',
48
+ * headers: { 'Content-Type': 'application/json' },
49
+ * body: JSON.stringify({ key: 'value' })
50
+ * });
51
+ * ```
52
+ */
53
+ export declare function fetch(url: string, options?: FetchOptions): Promise<Response>;
19
54
  export declare function getJSON(uri: any, options?: any): Promise<any>;
20
55
  export declare function ipfsGet(gateway: string, ipfsHash: string, protocolType?: string): Promise<any>;
21
56
  export declare function sendTransaction(web3: any, contractAddress: string, abi: any[], action: string, params: any[], overrides?: {}): Promise<any>;
@@ -43,6 +78,7 @@ export { getDelegatesBySpace, SNAPSHOT_SUBGRAPH_URL };
43
78
  declare const _default: {
44
79
  call: typeof call;
45
80
  multicall: typeof multicall;
81
+ fetch: typeof fetch;
46
82
  subgraphRequest: typeof subgraphRequest;
47
83
  ipfsGet: typeof ipfsGet;
48
84
  getUrl: typeof getUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapshot-labs/snapshot.js",
3
- "version": "0.14.5",
3
+ "version": "0.14.7",
4
4
  "repository": "snapshot-labs/snapshot.js",
5
5
  "license": "MIT",
6
6
  "main": "dist/snapshot.cjs.js",
package/src/networks.json CHANGED
@@ -408,6 +408,20 @@
408
408
  "start": 1290,
409
409
  "logo": "ipfs://bafkreib4xhbgbhrwkmizp4d4nz3wzbpyhdm6wpz2v2pbkk7jxsgg3hdt74"
410
410
  },
411
+ "151": {
412
+ "key": "151",
413
+ "name": "Redbelly",
414
+ "shortName": "mainnet",
415
+ "chainId": 151,
416
+ "network": "mainnet",
417
+ "multicall": "0xEe43BBcC6340038130681F98d855E416F7F728e9",
418
+ "rpc": [],
419
+ "explorer": {
420
+ "url": "https://redbelly.routescan.io"
421
+ },
422
+ "start": 1908395,
423
+ "logo": "ipfs://bafkreie5mdk5shaebcec6zs5dc4722u2tn7oxvkksjy62kkjdzgnvmad7q"
424
+ },
411
425
  "157": {
412
426
  "key": "157",
413
427
  "name": "Shibarium Puppynet Testnet",
package/src/sign/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import fetch from 'cross-fetch';
1
+ import { fetch } from '../utils';
2
2
  import { Web3Provider } from '@ethersproject/providers';
3
3
  import { Wallet } from '@ethersproject/wallet';
4
4
  import {
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import fetch from 'cross-fetch';
1
+ import crossFetch from 'cross-fetch';
2
2
  import { Contract } from '@ethersproject/contracts';
3
3
  import { getAddress, isAddress } from '@ethersproject/address';
4
4
  import { parseUnits } from '@ethersproject/units';
@@ -314,9 +314,76 @@ export function getUrl(uri, gateway = gateways[0]) {
314
314
  return uri;
315
315
  }
316
316
 
317
+ interface FetchOptions extends RequestInit {
318
+ timeout?: number;
319
+ }
320
+
321
+ /**
322
+ * Enhanced fetch with timeout support - drop-in replacement for native fetch
323
+ *
324
+ * @param url - The URL to fetch
325
+ * @param options - Fetch options with optional timeout
326
+ * @param options.timeout - Request timeout in milliseconds (default: 30000ms). Set to 0 to disable timeout.
327
+ *
328
+ * @returns Promise that resolves to the Response object
329
+ *
330
+ * @throws {Error} Throws timeout error if request exceeds the specified timeout duration
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * // Uses default 30s timeout
335
+ * const response = await fetch('https://api.example.com/data');
336
+ *
337
+ * // Custom 5s timeout
338
+ * const response = await fetch('https://api.example.com/data', { timeout: 5000 });
339
+ *
340
+ * // Disable timeout
341
+ * const response = await fetch('https://api.example.com/data', { timeout: 0 });
342
+ *
343
+ * // With additional fetch options
344
+ * const response = await fetch('https://api.example.com/data', {
345
+ * timeout: 10000,
346
+ * method: 'POST',
347
+ * headers: { 'Content-Type': 'application/json' },
348
+ * body: JSON.stringify({ key: 'value' })
349
+ * });
350
+ * ```
351
+ */
352
+ export async function fetch(
353
+ url: string,
354
+ options: FetchOptions = {}
355
+ ): Promise<Response> {
356
+ const { timeout = 30000, ...fetchOptions } = options;
357
+
358
+ if (timeout > 0) {
359
+ const controller = new AbortController();
360
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
361
+
362
+ try {
363
+ const response = await crossFetch(url, {
364
+ ...fetchOptions,
365
+ signal: controller.signal
366
+ });
367
+ return response;
368
+ } catch (error) {
369
+ if (error instanceof Error && error.name === 'AbortError') {
370
+ throw new Error(`Request timeout after ${timeout}ms`);
371
+ }
372
+ throw error;
373
+ } finally {
374
+ clearTimeout(timeoutId);
375
+ }
376
+ }
377
+
378
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
379
+ const { signal, ...cleanFetchOptions } = fetchOptions;
380
+ return crossFetch(url, cleanFetchOptions);
381
+ }
382
+
317
383
  export async function getJSON(uri, options: any = {}) {
318
384
  const url = getUrl(uri, options.gateways);
319
- return fetch(url).then((res) => res.json());
385
+ const response = await fetch(url, options);
386
+ return response.json();
320
387
  }
321
388
 
322
389
  export async function ipfsGet(
@@ -823,6 +890,7 @@ export { getDelegatesBySpace, SNAPSHOT_SUBGRAPH_URL };
823
890
  export default {
824
891
  call,
825
892
  multicall,
893
+ fetch,
826
894
  subgraphRequest,
827
895
  ipfsGet,
828
896
  getUrl,
@@ -143,7 +143,7 @@ export default class RankedChoiceVoting {
143
143
  this.strategies.map((strategy, sI) => {
144
144
  return finalRound
145
145
  .filter((res) => Number(res[0]) === i + 1)
146
- .reduce((a, b) => a + b[1][1][sI], 0);
146
+ .reduce((a, b) => a + b[1][1][sI] || 0, 0);
147
147
  })
148
148
  );
149
149
  }