Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/lum-776
Browse files Browse the repository at this point in the history
  • Loading branch information
greedyboi committed Aug 10, 2023
2 parents c44f51c + 81f8053 commit ebb13e9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/api/lumApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from 'utils';
import { ApiConstants } from 'constant';
import { DepositDropModel, LeaderboardItemModel, PrizeModel, PrizeStatsModel } from 'models';
import { DepositDropModel, LeaderboardItemModel, MarketDataModel, PrizeModel, PrizeStatsModel } from 'models';

class LumApi extends HttpClient {
private static instance?: LumApi;
Expand Down Expand Up @@ -32,6 +32,8 @@ class LumApi extends HttpClient {

fetchLeaderboardUserRank = async (poolId: string, address: string) =>
this.request<LeaderboardItemModel[]>({ url: `/millions/depositors/${poolId}/${address}`, method: 'GET' }, LeaderboardItemModel);

fetchMarketData = async (since: Date) => this.request<MarketDataModel[]>({ url: `/market/data/since?limit=1`, method: 'POST', data: { since } }, MarketDataModel);
}

export default LumApi.getInstance();
20 changes: 20 additions & 0 deletions src/models/MarketData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Expose, Type } from 'class-transformer';

class MarketData {
@Expose()
price!: number;

@Expose()
denom!: string;
}

class MarketDataModel {
@Expose({ name: 'market_data' })
@Type(() => MarketData)
marketData?: MarketData[];

@Expose()
id!: string;
}

export default MarketDataModel;
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as PrizeModel } from './Prize';
export { default as PrizeStatsModel } from './PrizeStats';
export { default as DepositDropModel } from './DepositDrop';
export { default as LeaderboardItemModel } from './LeaderboardItem';
export { default as MarketDataModel } from './MarketData';

export * from './wallets';
export * from './pools';
Expand Down
6 changes: 5 additions & 1 deletion src/models/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Prize } from '@lum-network/sdk-javascript/build/codec/lum/network/milli
import { BalanceModel, LeaderboardItemModel } from './index';
import { Draw } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/draw';

export interface DrawModel extends Draw {
usdTokenValue?: number;
}

export interface PoolInternalInfosModel {
rpc: string;
chainName: string;
Expand All @@ -18,7 +22,7 @@ export interface PoolInternalInfosModel {
export interface PoolModel extends Pool {
internalInfos?: PoolInternalInfosModel;
prizes?: Prize[];
draws?: Draw[];
draws?: DrawModel[];
nextDrawAt?: Date;
leaderboard: {
items: LeaderboardItemModel[];
Expand Down
4 changes: 3 additions & 1 deletion src/pages/PoolDetails/PoolDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,9 @@ const PoolDetails = () => {
{draw.totalWinCount.toString()}
</td>
<td data-label={drawHistoryHeaders[4]} className='text-end'>
<SmallerDecimal nb={numeral(NumbersUtils.convertUnitNumber(draw.totalWinAmount) * (prices[denom] || 1)).format('$0,0[.]00')} />
<SmallerDecimal
nb={numeral(NumbersUtils.convertUnitNumber(draw.totalWinAmount) * (draw.usdTokenValue || prices[denom] || 0)).format('$0,0[.]00')}
/>
<div className='draw-token'>
<SmallerDecimal nb={numeral(NumbersUtils.convertUnitNumber(draw.totalWinAmount)).format('0,0.000000')} />
&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import dayjs from 'dayjs';
import numeral from 'numeral';
import { Draw } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/draw';

import Assets from 'assets';
import { Button, Card, Modal, SmallerDecimal, Table } from 'components';
import { ModalHandlers } from 'components/Modal/Modal';
import { NavigationConstants } from 'constant';
import { DenomsUtils, I18n, NumbersUtils, StringsUtils } from 'utils';
import { DrawModel } from 'models';

import './DrawDetailsModal.scss';

const DrawDetails = ({ draw, poolDenom, prices, modalRef }: { draw: Draw | null; poolDenom: string; prices: { [key: string]: number }; modalRef: React.RefObject<ModalHandlers> }) => {
const DrawDetails = ({ draw, poolDenom, prices, modalRef }: { draw: DrawModel | null; poolDenom: string; prices: { [key: string]: number }; modalRef: React.RefObject<ModalHandlers> }) => {
const [view, setView] = useState<'winners' | 'redelegated'>('winners');
const [winnersPage, setWinnersPage] = useState(1);

Expand Down Expand Up @@ -86,7 +86,7 @@ const DrawDetails = ({ draw, poolDenom, prices, modalRef }: { draw: Draw | null;
<td className='text-md-end'>
<div className='d-flex flex-column justify-content-center tx-amount'>
<div className='amount text-nowrap'>
<SmallerDecimal nb={numeral(NumbersUtils.convertUnitNumber(winner.amount) * (prices[poolDenom] || 0)).format('$0,0[.]00')} />
<SmallerDecimal nb={numeral(NumbersUtils.convertUnitNumber(winner.amount) * (draw.usdTokenValue || prices[poolDenom] || 0)).format('$0,0[.]00')} />
</div>
<span className='usd-price'>
<SmallerDecimal nb={numeral(NumbersUtils.convertUnitNumber(winner.amount)).format('0,0.000000')} /> {poolDenom.toUpperCase()}
Expand All @@ -105,7 +105,8 @@ const DrawDetails = ({ draw, poolDenom, prices, modalRef }: { draw: Draw | null;
<div className='display-6 prize-remaining-amount'>
<SmallerDecimal
nb={numeral(
(NumbersUtils.convertUnitNumber(draw.prizePool?.amount || 0) - NumbersUtils.convertUnitNumber(draw.totalWinAmount)) * (prices[poolDenom] || 0),
(NumbersUtils.convertUnitNumber(draw.prizePool?.amount || 0) - NumbersUtils.convertUnitNumber(draw.totalWinAmount)) *
(draw.usdTokenValue || prices[poolDenom] || 0),
).format('$0,0[.]00')}
/>
</div>
Expand Down
17 changes: 13 additions & 4 deletions src/redux/models/pools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Long from 'long';
import { createModel } from '@rematch/core';
import { ApiConstants, PoolsConstants } from 'constant';
import { PoolModel } from 'models';
import { DrawModel, PoolModel } from 'models';
import { DenomsUtils, LumClient, NumbersUtils, WalletClient } from 'utils';
import { RootModel } from '.';
import dayjs from 'dayjs';
Expand Down Expand Up @@ -63,7 +63,7 @@ export const pools = createModel<RootModel>()({
continue;
}

const draws = await dispatch.pools.getPoolDraws(pool.poolId);
const draws = await dispatch.pools.getPoolDraws({ poolId: pool.poolId, nativeDenom: pool.nativeDenom });
const leaderboard = await dispatch.pools.getLeaderboard({ poolId: pool.poolId, limit: 15 });

const nextDrawAt = dayjs(pool.lastDrawCreatedAt || pool.drawSchedule?.initialDrawAt)
Expand Down Expand Up @@ -182,12 +182,21 @@ export const pools = createModel<RootModel>()({

dispatch.pools.setMutexAdditionalInfos(false);
},
async getPoolDraws(poolId: Long) {
async getPoolDraws({ poolId, nativeDenom }: { poolId: Long; nativeDenom: string }) {
try {
const res = await LumClient.getPoolDraws(poolId);
const draws: DrawModel[] = [];

if (res) {
return res;
for (const draw of res) {
const [marketData] = await LumApi.fetchMarketData(draw.createdAt || new Date());

if (marketData && marketData.length) {
draws.push({ ...draw, usdTokenValue: marketData[0].marketData?.find((data) => data.denom === DenomsUtils.getNormalDenom(nativeDenom))?.price || undefined });
}
}

return draws;
}
} catch {}
},
Expand Down

0 comments on commit ebb13e9

Please sign in to comment.