Skip to content
Closed
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
73 changes: 60 additions & 13 deletions src/API/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @flow

import axios from 'axios';
import { BACKEND_URL } from '../manifestEnvs';
import { BACKEND_URL, BACKEND_URL_DAEDALUS } from '../manifestEnvs';

const backendUrl: string = BACKEND_URL;
const backendUrlAdapools: string = BACKEND_URL;
const backendUrlDaedalus: string = BACKEND_URL_DAEDALUS;

export type HistBPE = {|
+val: string,
Expand Down Expand Up @@ -50,6 +51,19 @@ export type Pool = {|
+saturation: number,
|};

// TODO: fix with right data
export type PoolDaedalusSimple = {|
+cost: string,
+margin: string,
+non_myopic_member_rewards: number,
+pledge: string,
+pool_id: string,
+pool_info: ?string,
+produced_blocks: number,
+relative_stake: string,
+saturation: string,
|};

export type World = {|
+epoch: string,
+slot: string,
Expand All @@ -65,33 +79,45 @@ export const Sorting = Object.freeze({
TICKER: 'ticker',
SCORE: 'score',
});
export const Provider = Object.freeze({
ADAPOOLS: 'adapools',
POOLTOOL: 'pooltool',
DAEDALUS_SIMPLE: 'daedalus_simple',
DAEDALUS_ADVANCED: 'daedalus_advanced',
});

export type SortingEnum = $Values<typeof Sorting>;
export type ProviderEnum = $Values<typeof Provider>;

export type SearchParams = {|
limit?: number,
search?: string,
sort?: SortingEnum
sort?: SortingEnum,
|};
export type SearchParamsDaedalus = {|
search?: string,
limit: ?number,
offset: ?number,
|};

export type ApiPoolsResponse = {|
world?: World,
pools?: {| [string]: Pool |},
|};
export type ApiPoolsDaedalusSimpleResponse = Array<PoolDaedalusSimple>;

const encodeForm = (data) => {
return (Object.keys(data): any)
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
.join('&');
};
export function getPools(body: SearchParams): Promise<ApiPoolsResponse> {
const requestBody = {
...{ search: '', sort: Sorting.SCORE, limit: 250 },
...body,
}
};

const encodeForm = (data) => {
return (Object.keys(data): any)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
.join('&');
}

return axios(`${backendUrl}`, {
return axios(`${backendUrlAdapools}`, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
method: 'post',
data: encodeForm(requestBody),
Expand All @@ -103,8 +129,29 @@ export function getPools(body: SearchParams): Promise<ApiPoolsResponse> {
.catch((error) => {
console.error('API::getPools Error: ', error);
return {
pools: {}
}
pools: {},
};
});
}

export function getPoolsByDaedalusSimple(
body: SearchParamsDaedalus,
): Promise<ApiPoolsDaedalusSimpleResponse> {
const requestBody = {
search: '',
limit: 250,
offset: 0,
...body,
};

return axios(backendUrlDaedalus, {
// TODO: fix when limit and offset works
method: 'get',
data: encodeForm(requestBody),
})
.then((response) => response.data)
.catch((error) => {
console.error(`API daedalus: getPoolsByDaedalusSimple Error: ${error}`);
});
}

Expand Down
Loading