Skip to content

Commit

Permalink
feat: replace public api to private api
Browse files Browse the repository at this point in the history
  • Loading branch information
BATMAH69 committed Jan 16, 2024
1 parent 70c61d1 commit 47948c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 2 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -126,6 +127,7 @@ export default {
subgraphMainnet,
subgraphGoerli,
subgraphHolesky,
operatorsWidgetBackendUrl,
},
publicRuntimeConfig: {
defaultChain,
Expand Down
43 changes: 21 additions & 22 deletions pages/api/node-operators/keys-info.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -32,22 +33,32 @@ 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}`,
)
return data.json()
}

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(
Expand All @@ -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()

Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 47948c8

Please sign in to comment.