-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: show metanodes earning * feat: add internal api rewards-last-week * fix: wrong redirect to / (should be /explorer)
- Loading branch information
1 parent
6985d53
commit 6fd44b7
Showing
9 changed files
with
128 additions
and
41 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
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
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,56 @@ | ||
import { SkybridgeBridge } from '@swingby-protocol/sdk'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
import { corsMiddleware, getParam } from '../../../modules/api'; | ||
import { fetcher } from '../../../modules/fetch'; | ||
import { skypoolsEnabled, ENDPOINT_SKYBRIDGE_EXCHANGE, mode } from '../../../modules/env'; | ||
|
||
const isBridgeEnabled = (bridge: SkybridgeBridge): boolean => { | ||
switch (bridge) { | ||
case 'btc_skypool': { | ||
return skypoolsEnabled; | ||
} | ||
default: | ||
return skypoolsEnabled; | ||
} | ||
}; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<{ currency: string; total: number; totalSbBtc: number; e?: string }>, | ||
) { | ||
await corsMiddleware({ req, res }); | ||
const bridge = getParam({ req, name: 'bridge' }) as SkybridgeBridge; | ||
let reward = { | ||
currency: 'USD', | ||
total: 0, | ||
totalSbBtc: 0, | ||
}; | ||
|
||
if (!isBridgeEnabled(bridge)) { | ||
return res.status(200).json(reward); | ||
} | ||
|
||
try { | ||
const sbBtcPriceUrl = `${ENDPOINT_SKYBRIDGE_EXCHANGE}/${mode}/${bridge}/sbBTC/price`; | ||
|
||
const results = await Promise.all([ | ||
fetcher<{ price: number; usdtPrice: number }>(sbBtcPriceUrl), | ||
fetcher<{ result: { rows: { Amount: number }[] } }>( | ||
`https://api.dune.com/api/v1/query/2364511/results?api_key=${process.env.DUNE_API_KEY}`, | ||
), | ||
]); | ||
|
||
const sbBtcUsdtPrice = results[0].usdtPrice; | ||
const currentReward = results[1].result.rows.find((row) => row.Amount > 0); | ||
if (currentReward) { | ||
reward.totalSbBtc = currentReward.Amount; | ||
reward.total = currentReward.Amount * sbBtcUsdtPrice; | ||
} | ||
|
||
res.status(200).json(reward); | ||
} catch (e) { | ||
console.log(e); | ||
res.status(500).json({ ...reward, e: e.message }); | ||
} | ||
} |
6fd44b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
new-explorer-mainnet – ./
new-explorer-mainnet-git-master-swingby.vercel.app
new-explorer-mainnet.vercel.app
app.swingby.network
skybridge.info
new-explorer-mainnet-swingby.vercel.app