Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Census3 supported chains #262

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading