Skip to content

Commit

Permalink
Route CLE rewards request through server
Browse files Browse the repository at this point in the history
  • Loading branch information
piekczyk committed Oct 3, 2024
1 parent 28f12f1 commit 3c92ba6
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 21 deletions.
4 changes: 1 addition & 3 deletions blockchain/better-calls/sky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ export const skyUsdsWalletStakeCleDetails = async ({ ownerAddress }: { ownerAddr
return new BigNumber(ethers.utils.formatUnits(tokensStaked, 18))
},
),
fetch(
`https://info-sky.blockanalitica.com/api/v1/farms/${mainnetContracts.sky.stakingCle.address}/wallets/${ownerAddress}/?format=json`,
)
fetch(`/api/sky/cle?walletAddress=${ownerAddress}`)
.then((resp) => resp.json())
.catch((error) => {
console.error('Failed to fetch earned CLE rewards:', error)
Expand Down
23 changes: 23 additions & 0 deletions handlers/sky/get.ts
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' })
}
}
14 changes: 14 additions & 0 deletions pages/api/sky/cle.ts
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)
2 changes: 1 addition & 1 deletion theme/icons/cle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
export const cle = {
path: (
<>
<g clip-path="url(#clip0_15346_4406)">
<g clipPath="url(#clip0_15346_4406)">
<path
d="M16 29C23.1797 29 29 23.1797 29 16C29 8.8203 23.1797 3 16 3C8.8203 3 3 8.8203 3 16C3 23.1797 8.8203 29 16 29Z"
fill="#2FD05B"
Expand Down
14 changes: 7 additions & 7 deletions theme/icons/cseth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import React from 'react'
export const cseth = {
path: (
<>
<g clip-path="url(#clip0_14480_4437)">
<g clipPath="url(#clip0_14480_4437)">
<path
d="M28.1875 16C28.1875 22.731 22.731 28.1875 16 28.1875C9.26903 28.1875 3.8125 22.731 3.8125 16C3.8125 9.26903 9.26903 3.8125 16 3.8125C22.731 3.8125 28.1875 9.26903 28.1875 16Z"
fill="#130E19"
/>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M16 4.625C9.71776 4.625 4.625 9.71776 4.625 16C4.625 22.2822 9.71776 27.375 16 27.375C22.2822 27.375 27.375 22.2822 27.375 16C27.375 9.71776 22.2822 4.625 16 4.625ZM3 16C3 8.8203 8.8203 3 16 3C23.1797 3 29 8.8203 29 16C29 23.1797 23.1797 29 16 29C8.8203 29 3 23.1797 3 16Z"
fill="url(#paint0_linear_14480_4437)"
/>
<path
d="M15.9998 7.33325V13.7406L21.4152 16.1606L15.9998 7.33325Z"
fill="white"
fill-opacity="0.602"
fillOpacity="0.602"
/>
<path d="M15.9996 7.33325L10.5833 16.1606L15.9996 13.7406V7.33325Z" fill="white" />
<path
d="M15.9998 20.3129V24.6667L21.4188 17.1692L15.9998 20.3129Z"
fill="white"
fill-opacity="0.602"
fillOpacity="0.602"
/>
<path d="M15.9996 24.6667V20.3123L10.5833 17.1692L15.9996 24.6667Z" fill="white" />
<path
d="M15.9998 19.3052L21.4152 16.1607L15.9998 13.7422V19.3052Z"
fill="white"
fill-opacity="0.2"
fillOpacity="0.2"
/>
<path
d="M10.5833 16.1607L15.9996 19.3052V13.7422L10.5833 16.1607Z"
fill="white"
fill-opacity="0.602"
fillOpacity="0.602"
/>
</g>
<defs>
Expand Down
6 changes: 3 additions & 3 deletions theme/icons/ldo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react'
export const ldo = {
path: (
<>
<g clip-path="url(#clip0_14079_7236)">
<g clipPath="url(#clip0_14079_7236)">
<path
d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z"
fill="black"
/>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M12.0046 4.92969L15.5124 10.4076L12.0044 12.4471L8.49683 10.4075L12.0046 4.92969ZM9.57062 10.1485L12.0046 6.34754L14.4385 10.1485L12.0044 11.5637L9.57062 10.1485Z"
fill="white"
/>
Expand Down
6 changes: 3 additions & 3 deletions theme/icons/ldo_circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react'
export const ldo_circle = {
path: (
<>
<g clip-path="url(#clip0_14079_5412)">
<g clipPath="url(#clip0_14079_5412)">
<path
d="M16 29C23.1797 29 29 23.1797 29 16C29 8.8203 23.1797 3 16 3C8.8203 3 3 8.8203 3 16C3 23.1797 8.8203 29 16 29Z"
fill="#F69988"
/>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M16.0061 6.80859L20.5663 13.9299L16.0059 16.5812L11.446 13.9297L16.0061 6.80859ZM12.842 13.593L16.0061 8.6518L19.1703 13.593L16.0059 15.4328L12.842 13.593Z"
fill="white"
/>
Expand Down
6 changes: 3 additions & 3 deletions theme/icons/susd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react'
export const susd = {
path: (
<>
<g clip-path="url(#clip0_14079_7258)">
<g clipPath="url(#clip0_14079_7258)">
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22ZM11.9999 20.6666C16.7864 20.6666 20.6666 16.7864 20.6666 11.9999C20.6666 7.21345 16.7864 3.33325 11.9999 3.33325C7.21345 3.33325 3.33325 7.21345 3.33325 11.9999C3.33325 16.7864 7.21345 20.6666 11.9999 20.6666ZM19.6666 11.9999C19.6666 16.2341 16.2341 19.6666 11.9999 19.6666C7.76574 19.6666 4.33325 16.2341 4.33325 11.9999C4.33325 7.76574 7.76574 4.33325 11.9999 4.33325C16.2341 4.33325 19.6666 7.76574 19.6666 11.9999Z"
fill="#06061B"
/>
Expand Down
2 changes: 1 addition & 1 deletion theme/icons/susd_circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
export const susd_circle = {
path: (
<>
<g clip-path="url(#clip0_14079_6971)">
<g clipPath="url(#clip0_14079_6971)">
<mask id="mask0_14079_6971" maskUnits="userSpaceOnUse" x="3" y="3" width="26" height="26">
<path d="M3 3H29V29H3V3Z" fill="white" />
</mask>
Expand Down

0 comments on commit 3c92ba6

Please sign in to comment.