-
Notifications
You must be signed in to change notification settings - Fork 6
replace recommended pool #204
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,15 @@ import axios from 'axios'; | |
| import seedrandom from 'seedrandom'; | ||
| import { BACKEND_URL } from '../manifestEnvs'; | ||
|
|
||
| const SATURATION = 76293289283071; | ||
|
|
||
| const backendUrl: string = BACKEND_URL; | ||
|
|
||
| const BIAS_POOL_IDS = [ | ||
| 'dbda39c8d064ff9801e376f8350efafe67c07e9e9244dd613aee5125', // EMURA | ||
| // '359d3f8e355c873b0b5cae1e18eb12e44dcfc2ad212706d93ac314ab', // EMURB | ||
| '8efb053977341471256685b1069d67f4aca7166bc3f94e27ebad217f', // EMUR7 | ||
| '0ef7aa564933ce75b695cdad66be4a39b43a22726de7c58908e0e033', // EMUR8 | ||
| // '0ef7aa564933ce75b695cdad66be4a39b43a22726de7c58908e0e033', // EMUR8 | ||
| '359d3f8e355c873b0b5cae1e18eb12e44dcfc2ad212706d93ac314ab', // EMURB | ||
| '2a8294ad7538b15353b9ffd81e26dafe846ffc3f6b9e331d4c1dc030', // YORO1 | ||
| 'b19f2d9498845652ae6eea5da77952b37e2bca9f59b2a98c56694cae', // YORO2 | ||
| ]; | ||
|
|
@@ -28,13 +30,13 @@ const brackets = [ | |
| { startIndex: 53, positionGap: 27 }, | ||
| ]; | ||
|
|
||
| export type HistBPE = {| | ||
| type HistBPE = {| | ||
| +val: string, | ||
| +time: string, | ||
| +e: number, | ||
| |}; | ||
|
|
||
| export type SocialMediaHandles = {| | ||
| type SocialMediaHandles = {| | ||
| tw: ?string, | ||
| tg: ?string, | ||
| fb: ?string, | ||
|
|
@@ -74,14 +76,7 @@ export type Pool = {| | |
| +saturation: number, | ||
| |}; | ||
|
|
||
| export type World = {| | ||
| +epoch: string, | ||
| +slot: string, | ||
| +stake: string, | ||
| +supply: number, | ||
| +pools: string, | ||
| +price: number, | ||
| +delegators: string, | ||
| type World = {| | ||
| +saturation: number, | ||
| |}; | ||
|
|
||
|
|
@@ -102,7 +97,7 @@ export const SortingDirections = Object.freeze({ | |
| }); | ||
|
|
||
| export type SortingEnum = $Values<typeof Sorting>; | ||
| export type SortingDirEnum = $Values<typeof SortingDirections>; | ||
| type SortingDirEnum = $Values<typeof SortingDirections>; | ||
|
|
||
| export type SearchParams = {| | ||
| limit?: number, | ||
|
|
@@ -111,38 +106,54 @@ export type SearchParams = {| | |
| sortDirection?: SortingDirEnum, | ||
| |}; | ||
|
|
||
| export type ApiPoolsResponse = {| | ||
| type ApiPoolsResponse = {| | ||
| world?: World, | ||
| pools?: {| [string]: Pool |}, | ||
| pools?: Array<Pool>, | ||
| |}; | ||
|
|
||
| const toPoolArray: (?{| [string]: Pool |}) => Array<Pool> = (pools) => { | ||
| if (pools == null) return []; | ||
| return Object.keys(pools) | ||
| .map((key) => pools[key]) | ||
| .filter((x) => x != null); | ||
| }; | ||
|
|
||
| export function getPools(body: SearchParams): Promise<ApiPoolsResponse> { | ||
| function transformData(poolsResponse) { | ||
| return { | ||
| world: { | ||
| saturation: SATURATION, | ||
| }, | ||
| pools: poolsResponse?.data?.data?.map((pool) => ( | ||
| { | ||
| id: pool.pool_id, | ||
| id_bech: pool.pool_id_hash_raw, | ||
| db_ticker: pool.pool_name.ticker, | ||
| db_name: pool.pool_name.name, | ||
| pledge: String(pool.pledged), | ||
| pledge_real: String(pool.pledged), | ||
| total_stake: String(pool.live_stake), | ||
| tax_fix: String(pool.pool_update.live.fixed_cost), | ||
| tax_ratio: String(pool.pool_update.live.margin), | ||
| blocks_epoch: pool.blocks.epoch, | ||
| roa: String(pool.stats.lifetime.roa), | ||
| handles: {}, | ||
| saturation: pool.live_stake / SATURATION, | ||
| } | ||
| )) ?? [], | ||
| }; | ||
| } | ||
|
|
||
| function getPools(network: 'mainnet' | 'preprod', body: SearchParams): Promise<ApiPoolsResponse> { | ||
| const requestBody = { | ||
| ...{ search: '', sort: Sorting.SCORE, limit: 250 }, | ||
| ...{ order: 'ranking', limit: 250}, | ||
| ...body, | ||
| //fixme | ||
| //network, | ||
| }; | ||
|
|
||
| const encodeForm = (data) => { | ||
| return (Object.keys(data): any) | ||
| .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`) | ||
| .join('&'); | ||
| }; | ||
| const searchParams = new URLSearchParams(); | ||
| Object.keys(requestBody).forEach((key) => { | ||
| searchParams.append(key, String(requestBody[key])); | ||
| }); | ||
|
|
||
| return axios(`${backendUrl}`, { | ||
| headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
| method: 'post', | ||
| data: encodeForm(requestBody), | ||
| }) | ||
| return axios(`${backendUrl}?${searchParams.toString()}`) | ||
| .then((response) => { | ||
| const poolsResponse: ApiPoolsResponse = response.data; | ||
| return poolsResponse; | ||
| return transformData(poolsResponse); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Empty Pools Break Runtime Array Operations Across APIThe error handler in getPools returns |
||
| }) | ||
| .catch((error) => { | ||
| console.error('API::getPools Error: ', error); | ||
|
|
@@ -181,11 +192,12 @@ export type ListBiasedPoolsResponse = {| | |
| |}; | ||
|
|
||
| export async function listBiasedPools( | ||
| network: 'mainnet' | 'preprod', | ||
| externalSeed: string, | ||
| searchParams: SearchParams, | ||
| ): Promise<ListBiasedPoolsResponse> { | ||
| const unbiasedPoolsResponse = await getPools(searchParams); | ||
| const originalPools = toPoolArray(unbiasedPoolsResponse.pools); | ||
| const unbiasedPoolsResponse = await getPools(network, searchParams); | ||
| const originalPools = unbiasedPoolsResponse.pools; | ||
|
|
||
| const saturationLimit = unbiasedPoolsResponse.world?.saturation; | ||
|
|
||
|
|
@@ -202,9 +214,9 @@ export async function listBiasedPools( | |
| const internalSeed = tail(p1?.id) + tail(p2?.id) + tail(p3?.id); | ||
|
|
||
| try { | ||
| const biasedPoolsResponse = await getPools({ search: BIAS_POOLS_SEARCH_QUERY }); | ||
| const biasedPoolsResponse = await getPools(network, { search: BIAS_POOLS_SEARCH_QUERY }); | ||
| if (!biasedPoolsResponse) return { pools: unbiasedPools, saturationLimit }; | ||
| const biasedPools = toPoolArray(biasedPoolsResponse.pools) | ||
| const biasedPools = biasedPoolsResponse.pools | ||
| .filter((x) => x.id && BIAS_POOL_IDS.indexOf(x.id) >= 0) | ||
| .sort((a, b) => { | ||
| // this sorting is to ensure that changes in the backend response order is not affecting the final ordering | ||
|
|
@@ -242,7 +254,3 @@ export async function listBiasedPools( | |
| return { pools: unbiasedPools, saturationLimit }; | ||
| } | ||
| } | ||
|
|
||
| export function listPools(): Promise<ApiPoolsResponse> { | ||
| return getPools(({}: any)); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // @flow | ||
|
|
||
| export type UrlParams = {| | ||
| chromeId: ?string, | ||
| mozId: ?string, | ||
| source: ?string, | ||
| selectedPoolIds: ?Array<string>, | ||
| lang: ?string, | ||
| totalAda: ?number, | ||
| layout: ?string, | ||
| bias: ?string, | ||
| theme: ?string, | ||
| network: 'mainnet' | 'preprod', | ||
| |}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing Pool Properties Break UI Sorting and UI
The transformData function creates Pool objects missing many required properties from the Pool type definition. Most critically, it's missing
total_size,score,pool_pic,fullname,tax_computed,hist_bpe,hist_roa,last_rewards,position, and thecolor_*properties. The missingtotal_sizeproperty will break the pool size sorting feature in HomeRevamp.js (lines 112-115) since sorting by undefined values will result in NaN comparisons. Other missing properties may cause issues elsewhere in the UI.