From 2e4bc019c9e41149a14546c83e9d258296ccd1f7 Mon Sep 17 00:00:00 2001 From: Thibault Jaillard Date: Wed, 28 Feb 2024 14:38:33 -0500 Subject: [PATCH] Fixes about prices and luckiest winners --- src/api/lumApi.ts | 2 -- src/models/PrizeStats.ts | 4 ++-- src/pages/PoolDetails/PoolDetails.tsx | 13 ++++--------- .../LatestWinnersTable/LatestWinnersTable.tsx | 13 +++++++++++-- src/redux/models/app.ts | 8 +------- src/redux/models/prizes.ts | 16 ---------------- 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/api/lumApi.ts b/src/api/lumApi.ts index 701139cc..7fb47084 100644 --- a/src/api/lumApi.ts +++ b/src/api/lumApi.ts @@ -17,8 +17,6 @@ class LumApi extends HttpClient { return this.instance; } - fetchBiggestPrizes = async () => this.request({ url: '/millions/prizes/biggest?limit=4', method: 'GET' }, PrizeModel); - fetchBiggestAprPrizes = async () => this.request({ url: '/millions/prizes/biggest-apr?limit=30', method: 'GET' }, BiggestAprPrizeModel); fetchPrizes = async (page = 0) => this.request({ url: `/millions/prizes?limit=5&page=${page}`, method: 'GET' }, PrizeModel); diff --git a/src/models/PrizeStats.ts b/src/models/PrizeStats.ts index 2193c38a..bb1d22de 100644 --- a/src/models/PrizeStats.ts +++ b/src/models/PrizeStats.ts @@ -7,8 +7,8 @@ class PrizeStatsModel { @Expose({ name: 'total_pool_prizes' }) totalPoolPrizes!: number; - @Expose({ name: 'total_prizes_usd_amount' }) - totalPrizesUsdAmount!: number; + @Expose({ name: 'total_prizes_amount' }) + totalPrizesAmount!: number; } export default PrizeStatsModel; diff --git a/src/pages/PoolDetails/PoolDetails.tsx b/src/pages/PoolDetails/PoolDetails.tsx index 94132f5e..b4ec4506 100644 --- a/src/pages/PoolDetails/PoolDetails.tsx +++ b/src/pages/PoolDetails/PoolDetails.tsx @@ -95,7 +95,7 @@ const PoolDetails = () => { const usersDepositsAmount = NumbersUtils.convertUnitNumber(pool.tvlAmount || '0') - sponsorshipAmount; const userDeposits = lumWallet?.deposits.find((deposit) => (poolId ? Number(deposit.poolId) === Number(poolId) : deposit.amount?.denom === 'u' + denom)); - const avgDeposit = (usersDepositsAmount / Number(pool.depositorsCount)) * prices[denom] || 0; + const avgDeposit = (usersDepositsAmount / Number(pool.depositorsCount)) * (prices[denom] ?? 0); return (
@@ -416,7 +416,7 @@ const PoolDetails = () => {
{I18n.t('poolDetails.winners.totalPrizes')} -
{numeral(prizesStats.totalPrizesUsdAmount).format('$0,0')}
+
{numeral(prizesStats.totalPrizesAmount).format('$0,0')}
{I18n.t('poolDetails.winners.totalPoolPrizes')} @@ -425,13 +425,8 @@ const PoolDetails = () => {
{I18n.t('poolDetails.winners.bestPrizeWon')}
- $ - {numeral( - NumbersUtils.convertUnitNumber( - biggestPrizes && biggestPrizes.length && biggestPrizes[0].usdTokenValue ? biggestPrizes[0].amount.amount * biggestPrizes[0].usdTokenValue : 0, - ), - ) - .format('0,0') + {numeral(NumbersUtils.convertUnitNumber(prizesStats.biggestPrizeAmount) * (prices[denom] ?? 0)) + .format('$0,0.00') .toUpperCase()}
diff --git a/src/pages/Winners/components/LatestWinnersTable/LatestWinnersTable.tsx b/src/pages/Winners/components/LatestWinnersTable/LatestWinnersTable.tsx index f599d990..e523376f 100644 --- a/src/pages/Winners/components/LatestWinnersTable/LatestWinnersTable.tsx +++ b/src/pages/Winners/components/LatestWinnersTable/LatestWinnersTable.tsx @@ -1,12 +1,15 @@ import React from 'react'; + import dayjs from 'dayjs'; import numeral from 'numeral'; +import { useSelector } from 'react-redux'; import { Pagination, SmallerDecimal, Table } from 'components'; import { Breakpoints } from 'constant'; import { useWindowSize } from 'hooks'; import { DenomsUtils, I18n, NumbersUtils, StringsUtils } from 'utils'; import { MetadataModel, PrizeModel } from 'models'; +import { RootState } from 'redux/store'; import './LatestWinnersTable.scss'; @@ -21,6 +24,8 @@ interface IProps { const LatestWinnersTable = ({ prizes, metadata, visibleItem, onPageChange, onItemChange }: IProps) => { const winSizes = useWindowSize(); + const prices = useSelector((state: RootState) => state.stats.prices); + const headers = I18n.t('luckiestWinners.winnersHeaders', { returnObjects: true }); const renderRow = (prize: PrizeModel) => { @@ -43,7 +48,9 @@ const LatestWinnersTable = ({ prizes, metadata, visibleItem, onPageChange, onIte {' '} {DenomsUtils.getNormalDenom(prize.amount.denom).toUpperCase()}
- ${numeral(NumbersUtils.convertUnitNumber(prize.amount.amount) * (prize.usdTokenValue || 0)).format('0,0.00')} + + {numeral(NumbersUtils.convertUnitNumber(prize.amount.amount) * (prices[DenomsUtils.getNormalDenom(prize.amount.denom)] ?? 0)).format('$0,0.00')} +
@@ -89,7 +96,9 @@ const LatestWinnersTable = ({ prizes, metadata, visibleItem, onPageChange, onIte {' '} {DenomsUtils.getNormalDenom(prize.amount.denom).toUpperCase()} - ${numeral(NumbersUtils.convertUnitNumber(prize.amount.amount) * (prize.usdTokenValue || 0)).format('0,0.00')} + + {numeral(NumbersUtils.convertUnitNumber(prize.amount.amount) * (prices[DenomsUtils.getNormalDenom(prize.amount.denom)] ?? 0)).format('$0,0.00')} + diff --git a/src/redux/models/app.ts b/src/redux/models/app.ts index 98eb7c69..30a0c529 100644 --- a/src/redux/models/app.ts +++ b/src/redux/models/app.ts @@ -37,13 +37,7 @@ export const app = createModel()({ await LumClient.connect(); try { - await Promise.allSettled([ - dispatch.stats.fetchStats(), - dispatch.pools.fetchPools(null), - dispatch.pools.getDepositDelta(), - dispatch.prizes.fetchBiggestPrizes(), - dispatch.prizes.fetchBiggestAprPrizes(), - ]); + await Promise.allSettled([dispatch.stats.fetchStats(), dispatch.pools.fetchPools(null), dispatch.pools.getDepositDelta(), dispatch.prizes.fetchBiggestAprPrizes()]); } catch (e) { console.error(e); dispatch.app.SET_INIT_MUTEX(false); diff --git a/src/redux/models/prizes.ts b/src/redux/models/prizes.ts index 365ca47f..0f00fee0 100644 --- a/src/redux/models/prizes.ts +++ b/src/redux/models/prizes.ts @@ -4,7 +4,6 @@ import { createModel } from '@rematch/core'; import { LumApi } from 'api'; interface PrizesState { - biggestPrizes: PrizeModel[]; biggestAprPrizes: BiggestAprPrizeModel[]; prizes: PrizeModel[]; metadata?: MetadataModel; @@ -15,19 +14,12 @@ interface PrizesState { export const prizes = createModel()({ name: 'prizes', state: { - biggestPrizes: [], biggestAprPrizes: [], prizes: [], stats: null, alreadySeenConfetti: false, } as PrizesState, reducers: { - setBiggestPrizes: (state: PrizesState, biggestPrizes: PrizeModel[]): PrizesState => { - return { - ...state, - biggestPrizes, - }; - }, setBiggestAprPrizes: (state: PrizesState, biggestAprPrizes: BiggestAprPrizeModel[]): PrizesState => { return { ...state, @@ -68,14 +60,6 @@ export const prizes = createModel()({ }, }, effects: (dispatch) => ({ - fetchBiggestPrizes: async () => { - try { - const [biggestPrizes] = await LumApi.fetchBiggestPrizes(); - - dispatch.prizes.setBiggestPrizes(biggestPrizes); - } catch {} - }, - fetchBiggestAprPrizes: async () => { const [biggestAprPrizes] = await LumApi.fetchBiggestAprPrizes();