Skip to content

Commit

Permalink
Added supported chains endpoint in Census3
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Sep 12, 2023
1 parent d162ccb commit b2bb670
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Census3 supported chains information.

## [0.2.0] - 2023-09-04

### Fixed
Expand Down
1 change: 1 addition & 0 deletions src/api/census3/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './census';
export * from './strategy';
export * from './service';
export * from './token';
export * from './errors';
35 changes: 35 additions & 0 deletions src/api/census3/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import axios from 'axios';
import { Census3API } from './api';

enum Census3ServiceAPIMethods {
INFO = '/info',
}

export interface ICensus3ServiceInfoResponse {
/**
* The list of supported chains
*/
chainIDs: Array<number>;
}

export abstract class Census3ServiceAPI extends Census3API {
/**
* Cannot be constructed.
*/
private constructor() {
super();
}

/**
* Fetches supported chains from the service
*
* @param {string} url API endpoint URL
* @returns {Promise<ICensus3ServiceInfoResponse>}
*/
public static info(url: string): Promise<ICensus3ServiceInfoResponse> {
return axios
.get<ICensus3ServiceInfoResponse>(url + Census3ServiceAPIMethods.INFO)
.then((response) => response.data)
.catch(this.isApiError);
}
}
10 changes: 10 additions & 0 deletions src/census3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CENSUS3_URL } from './util/constants';
import { ClientOptions } from './client';
import {
Census3CensusAPI,
Census3ServiceAPI,
Census3StrategyAPI,
Census3TokenAPI,
ICensus3CensusResponse,
Expand Down Expand Up @@ -43,6 +44,15 @@ export class VocdoniCensus3Client {
return Census3TokenAPI.list(this.url).then((list) => list.tokens ?? []);
}

/**
* Returns a list of supported chain identifiers
*
* @returns {Promise<number[]>} Supported chain list
*/
getSupportedChains(): Promise<number[]> {
return Census3ServiceAPI.info(this.url).then((info) => info.chainIDs ?? []);
}

/**
* Returns a list of supported tokens type
*
Expand Down

0 comments on commit b2bb670

Please sign in to comment.