-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route CLE rewards request through server
- Loading branch information
Showing
9 changed files
with
56 additions
and
21 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
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,23 @@ | ||
import { mainnetContracts } from 'blockchain/contracts/mainnet' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
import * as z from 'zod' | ||
|
||
const paramsSchema = z.object({ | ||
walletAddress: z.string(), | ||
}) | ||
|
||
export async function getCleRewards(req: NextApiRequest, res: NextApiResponse) { | ||
const { walletAddress } = paramsSchema.parse(req.query) | ||
|
||
try { | ||
const response = await fetch( | ||
`https://info-sky.blockanalitica.com/api/v1/farms/${mainnetContracts.sky.stakingCle.address}/wallets/${walletAddress}/?format=json`, | ||
).then((resp) => resp.json()) | ||
|
||
return res.status(200).json(response) | ||
} catch (error) { | ||
console.error('Failed to fetch earned CLE rewards:', error) | ||
|
||
return res.status(400).json({ error: `${error}`, reward_balance: '0' }) | ||
} | ||
} |
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,14 @@ | ||
import { getCleRewards } from 'handlers/sky/get' | ||
import { withPreflightHandler } from 'helpers/api/withPreflightHandler' | ||
import type { NextApiHandler } from 'next' | ||
|
||
const handler: NextApiHandler = async (req, res) => { | ||
switch (req.method) { | ||
case 'GET': | ||
return await getCleRewards(req, res) | ||
default: | ||
return res.status(405).end() | ||
} | ||
} | ||
|
||
export default withPreflightHandler(handler) |
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
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