From 47948c87ba6e929fcc8097995be98339e23cc706 Mon Sep 17 00:00:00 2001 From: Evgenii Date: Fri, 29 Dec 2023 16:48:01 +0700 Subject: [PATCH] feat: replace public api to private api --- .env.sample | 1 + next.config.mjs | 2 ++ pages/api/node-operators/keys-info.ts | 43 +++++++++++++-------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.env.sample b/.env.sample index 42e3fcea..e052c941 100644 --- a/.env.sample +++ b/.env.sample @@ -24,3 +24,4 @@ SUBGRAPH_GOERLI=https://api.thegraph.com/subgraphs/name/lidofinance/lido-testnet SUBGRAPH_HOLESKY=https://api.thegraph.com/subgraphs/name/lidofinance/lido-testnet WALLETCONNECT_PROJECT_ID= +OPERATORS_WIDGET_BACKEND_URL= diff --git a/next.config.mjs b/next.config.mjs index 55b7f079..ff931d34 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -32,6 +32,7 @@ const subgraphGoerli = process.env.SUBGRAPH_GOERLI const subgraphHolesky = process.env.SUBGRAPH_HOLESKY const walletconnectProjectId = process.env.WALLETCONNECT_PROJECT_ID +const operatorsWidgetBackendUrl = process.env.OPERATORS_WIDGET_BACKEND_URL export default { basePath, @@ -126,6 +127,7 @@ export default { subgraphMainnet, subgraphGoerli, subgraphHolesky, + operatorsWidgetBackendUrl, }, publicRuntimeConfig: { defaultChain, diff --git a/pages/api/node-operators/keys-info.ts b/pages/api/node-operators/keys-info.ts index 576d9557..ec1b39c3 100644 --- a/pages/api/node-operators/keys-info.ts +++ b/pages/api/node-operators/keys-info.ts @@ -1,3 +1,4 @@ +import getConfig from 'next/config' import { createNextConnect } from 'modules/shared/utils/createNextConnect' import { parseChainId } from 'modules/blockChain/chains' import { fetch } from '@lido-sdk/fetch' @@ -32,7 +33,10 @@ export type KeysInfoNew = { } } -const requestTestnetOperators = async (chainId: number) => { +const { serverRuntimeConfig } = getConfig() +const { operatorsWidgetBackendUrl } = serverRuntimeConfig + +const requestGoerliOperators = async (chainId: number) => { const data = await fetch( `https://operators.testnet.fi/api/operators?chainId=${chainId}`, ) @@ -40,14 +44,21 @@ const requestTestnetOperators = async (chainId: number) => { } const requestOperators = async ( - api: - | 'https://operators-holesky.testnet.fi/api' - | 'https://operators.lido.fi/api', chainId: number, moduleAddress: string, walletAddress: string, ) => { - const modulesResp = await fetch(`${api}/modules?chainId=${chainId}`) + const status = await fetch(`${operatorsWidgetBackendUrl}/v1/status`).then( + (resp: any) => resp.json(), + ) + + if (status.chainId !== chainId) { + throw new Error( + `The server chain does not match the application chain ${status.chainId} !== ${chainId}`, + ) + } + + const modulesResp = await fetch(`${operatorsWidgetBackendUrl}/v1/modules`) const modules: Module[] = await modulesResp.json() const module = modules.find( @@ -60,7 +71,7 @@ const requestOperators = async ( return result } const moduleStatisticsResp = await fetch( - `${api}/moduleStatistics?moduleId=${module.id}&chainId=${chainId}`, + `${operatorsWidgetBackendUrl}/v1/module-statistics/${module.id}`, ) const moduleStatistics: KeysInfoNew = await moduleStatisticsResp.json() @@ -73,7 +84,7 @@ const requestOperators = async ( } const operatorStatisticsResp = await fetch( - `${api}/operatorStatistics?moduleId=${module.id}&operatorId=${operator.id}&chainId=${chainId}`, + `${operatorsWidgetBackendUrl}/v1/operator/${module.id}/${operator.id}`, ) const operatorStatistics: KeysInfoOperatorNew = await operatorStatisticsResp.json() @@ -104,22 +115,10 @@ export default createNextConnect().get(async (req, res) => { const moduleAddress = String(req.query.moduleAddress) let result - if (chainId === CHAINS.Mainnet) { - result = await requestOperators( - 'https://operators.lido.fi/api', - chainId, - moduleAddress, - walletAddress, - ) - } else if (chainId === CHAINS.Holesky) { - result = await requestOperators( - 'https://operators-holesky.testnet.fi/api', - chainId, - moduleAddress, - walletAddress, - ) + if (chainId === CHAINS.Goerli) { + result = await requestGoerliOperators(chainId) } else { - result = await requestTestnetOperators(chainId) + result = await requestOperators(chainId, moduleAddress, walletAddress) } res.json(result)