-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the `gauges` and `smart-router` packages, particularly enhancing API calls to fetch gauge data and improving the handling of asynchronous operations. It also introduces new functions for retrieving gauges by chain. ### Detailed summary - Deleted `prod.ts` and `index.ts` files from `packages/gauges/src/constants/config`. - Added `GAUGES_API` constant in `endpoint.ts` for API endpoint. - Exported `getGaugesByChain` and `safeGetGaugesByChain` functions in `getGaugesByChain.ts`. - Updated `getAllGauges.ts` to use `getGauges` instead of `CONFIG_PROD`. - Modified various functions to await asynchronous operations for fetching data. - Refactored `getPairCombinations` to support async behavior. - Updated tests to reflect changes in gauge configuration fetching. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> --------- Co-authored-by: memoyil <[email protected]> Co-authored-by: chefjackson <[email protected]>
- Loading branch information
1 parent
6929583
commit 3e83a9c
Showing
22 changed files
with
227 additions
and
5,731 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@pancakeswap/gauges': major | ||
'@pancakeswap/smart-router': patch | ||
--- | ||
|
||
Read gauge list from remote endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const GAUGES_API = 'https://configs.pancakeswap.com/api/data/cached/gauges' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { GaugeConfig } from '../../types' | ||
import { GAUGES_API } from './endpoint' | ||
|
||
function createGaugeConfigFetcher() { | ||
let gauges: GaugeConfig[] | undefined | ||
let fetchRequest: Promise<GaugeConfig[]> | undefined | ||
|
||
return async function getGaugeConfig() { | ||
if (fetchRequest) return fetchRequest | ||
const fetchGaugeConfig = async () => { | ||
if (gauges) { | ||
return gauges | ||
} | ||
try { | ||
const response = await fetch(GAUGES_API, { | ||
signal: AbortSignal.timeout(3000), | ||
}) | ||
if (response.ok) { | ||
gauges = await response.json() | ||
if (!gauges) { | ||
throw new Error(`Unexpected empty gauges fetched from remote ${gauges}`) | ||
} | ||
return gauges | ||
} | ||
throw new Error(`Fetch failed with status: ${response.status}`) | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
throw new Error(`Fetch failed: ${e.message}`) | ||
} else { | ||
throw new Error(`Fetch failed: ${e}`) | ||
} | ||
} finally { | ||
fetchRequest = undefined | ||
} | ||
} | ||
fetchRequest = fetchGaugeConfig() | ||
return fetchRequest | ||
} | ||
} | ||
|
||
export const getGauges = createGaugeConfigFetcher() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.