Skip to content

Commit

Permalink
fix: top trader is own wallet and daily points
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonLin authored Apr 13, 2023
1 parent 060c945 commit e2ab5b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/src/components/common/TradingLeaderboardTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ const TradingLeaderboardTable = ({ traders, onClick, onBoostClick, pageSize, ...
return null
}

const sortedRows = rows.sort((a, b) => b.dailyRewards - a.dailyRewards)
const sortedRows = accountIsTopWallet
? [rows[0], ...rows.slice(1).sort((a, b) => b.dailyRewards - a.dailyRewards)]
: rows.sort((a, b) => b.dailyRewards - a.dailyRewards)
return (
<Table
data={sortedRows}
Expand Down
14 changes: 11 additions & 3 deletions app/src/hooks/leaderboard/useLeaderboardPageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { useCallback } from 'react'
import { FetchId } from '@/app/constants/fetch'
import fetchENSNames from '@/app/utils/fetchENSNames'
import getLyraSDK from '@/app/utils/getLyraSDK'
import fetchTradingLeaderboard, { TradingRewardToken } from '@/app/utils/rewards/fetchTradingLeaderboard'
import fetchTradingLeaderboard, {
TradingRewardsLeaderboard,
TradingRewardToken,
} from '@/app/utils/rewards/fetchTradingLeaderboard'

import useNetwork from '../account/useNetwork'
import useWallet from '../account/useWallet'
Expand Down Expand Up @@ -32,7 +35,7 @@ export const fetchLeaderboardPageData = async (
network: Network,
walletAddress: string | null
): Promise<LeaderboardPageData> => {
const [globalRewardEpochs, accountRewardEpochs, tradingLeaderboard] = await Promise.all([
const [globalRewardEpochs, accountRewardEpochs, tradingLeaderboards] = await Promise.all([
getLyraSDK(network).globalRewardEpochs(),
walletAddress ? getLyraSDK(network).accountRewardEpochs(walletAddress) : [],
fetchTradingLeaderboard(network),
Expand All @@ -51,6 +54,8 @@ export const fetchLeaderboardPageData = async (
const latestAccountRewardEpoch = accountRewardEpochs.find(
e => e.globalEpoch.startTimestamp === latestGlobalRewardEpoch.startTimestamp
)
const epochNumber = network === Network.Arbitrum ? latestGlobalRewardEpoch.id - 5 : latestGlobalRewardEpoch.id - 18
const tradingLeaderboard: TradingRewardsLeaderboard = tradingLeaderboards ? tradingLeaderboards[epochNumber] : {}

const leaderboard = []
const traders: TradingRewardsTraders = []
Expand All @@ -72,7 +77,10 @@ export const fetchLeaderboardPageData = async (
)
const latestDaily = dailyRewards[0]
const boost = Math.max(latestDaily.referralBoost, latestDaily.stakingBoost, latestDaily.tradingBoost)
const dailyReward = totalPoints > 0 ? (latestDaily.points / totalPoints) * totalRewards.amount : 0
const dailyReward =
totalPoints > 0 && latestDaily.points > 0
? (Math.sqrt(latestDaily.points) / totalPoints) * totalRewards.amount
: 0
leaderboard.push({
trader: trader,
traderEns: traderENSMap[trader],
Expand Down
4 changes: 2 additions & 2 deletions app/src/utils/rewards/fetchTradingLeaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type TradingRewardsLeaderboard = {
}
}

const fetchTradingLeaderboard = async (network: Network): Promise<TradingRewardsLeaderboard | null> => {
const fetchTradingLeaderboard = async (network: Network): Promise<TradingRewardsLeaderboard[] | null> => {
const res = await fetch(`${process.env.REACT_APP_API_URL}/rewards/tradingLeaderboard?network=${network}`, {
method: 'GET',
mode: 'cors',
Expand All @@ -51,7 +51,7 @@ const fetchTradingLeaderboard = async (network: Network): Promise<TradingRewards
return null
}
const data: TradingRewardsLeaderboard[] = await res.json()
return data[0]
return data
}

export default fetchTradingLeaderboard

0 comments on commit e2ab5b8

Please sign in to comment.