Skip to content

Commit

Permalink
feat(scan): add total reward
Browse files Browse the repository at this point in the history
  • Loading branch information
quanpt239 committed Oct 18, 2024
1 parent b77cc63 commit 1e381c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/LuckyDraw/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
z-index: 10;
width: 100%;
display: flex;
flex-direction: column-reverse;
flex-direction: column;

align-items: center;
flex-wrap: wrap;
Expand Down
32 changes: 25 additions & 7 deletions src/components/LuckyDraw/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ import {
SPIN_ID_KEY,
REWARD_ENUM
} from './constants';
import { getDataLogByKey, sendMultiple, useGetListSpinResult, useLuckyDrawConfig } from './useLuckyDraw';
import {
getDataLogByKey,
sendMultiple,
useGetListSpinResult,
useGetTotalWonReward,
useLuckyDrawConfig
} from './useLuckyDraw';
import styles from './index.module.scss';

const cx = cn.bind(styles);
Expand Down Expand Up @@ -92,6 +98,12 @@ const LuckyDraw: FC<{}> = () => {

// const { spinResult } = useGetSpinResult({ id: spinId });
const { spinResult, isDone } = useGetListSpinResult({ spinIdList });
const { totalRewarded, isLoading, refetchTotalRewarded } = useGetTotalWonReward();

useEffect(() => {
const intervalGetReward = setInterval(refetchTotalRewarded, 5e3);
return () => clearInterval(intervalGetReward);
}, []);

useEffect(() => {
if (spinIdList.length && isDone && myLuckyRef?.current) {
Expand Down Expand Up @@ -188,6 +200,18 @@ const LuckyDraw: FC<{}> = () => {
>
<div className={cx('wheel')}>
<div className={cx('info')}>
<span>
Total rewarded:&nbsp;
<span className={cx('balance')}>
{isLoading ? 'loading' : `${toDisplay(totalRewarded)} ${feeToken?.name || 'ORAI'}`}
</span>
</span>
<span>
Balance:&nbsp;
<span className={cx('balance')}>
{toDisplay(balance)} {feeToken?.name || 'ORAI'}
</span>
</span>
<div className={cx('detail')}>
<div className={cx('rangeWrapper')}>
<span className={cx('title')}>Select Spin: </span>
Expand All @@ -209,12 +233,6 @@ const LuckyDraw: FC<{}> = () => {
/>
</div>
</div>
<span>
Balance:&nbsp;
<span className={cx('balance')}>
{toDisplay(balance)} {feeToken?.name || 'ORAI'}
</span>
</span>
</div>

{loaded && (
Expand Down
12 changes: 11 additions & 1 deletion src/components/LuckyDraw/useLuckyDraw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ORAIX_CONTRACT } from '@oraichain/oraidex-common';
import { useQuery } from '@tanstack/react-query';
import { MulticallQueryClient } from '@oraichain/common-contracts-sdk';
import { network } from 'config/networks';
Expand Down Expand Up @@ -124,6 +123,17 @@ export const useGetSpinResult = ({ id }: { id: number }) => {
};
};

export const useGetTotalWonReward = () => {
const getState = async () => {
const contractClient = new LuckyWheelContractQueryClient(window.client, LUCKY_DRAW_CONTRACT);
const res = await contractClient.state();
return res.total_prize_won;
};

const { data, isLoading, refetch } = useQuery(['getState'], () => getState(), {});
return { totalRewarded: data, isLoading, refetchTotalRewarded: refetch };
};

export const useGetListSpinResult = ({ spinIdList }: { spinIdList: number[] }) => {
const getListSpinResults = async () => {
const multicall = new MulticallQueryClient(window.client, network.multicall);
Expand Down

0 comments on commit 1e381c0

Please sign in to comment.