Skip to content

Commit

Permalink
get mining stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Dat-TG committed Jul 15, 2024
1 parent a8358a1 commit c65dba3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
8 changes: 8 additions & 0 deletions src/api/blockchain/apiBlockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ export const isValidatorRegistered = async (privateKey: string) => {
const response = await AxiosClient.get(`/blocks/registered/${privateKey}`);
return response.data.stake as number;
};

export const getMiningStats = async (address: string) => {
const response = await AxiosClient.get(`/blocks/mining-stats/${address}`);
return response.data as {
minedBlocks: number;
rewards: number;
};
};
35 changes: 14 additions & 21 deletions src/pages/Explore/ExplorePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
Button,
} from '@mui/material';
import Meta from '@/components/Meta';
import { isValidatorRegistered, registerValidator } from '@/api/blockchain/apiBlockchain';
import {
getMiningStats,
isValidatorRegistered,
registerValidator,
} from '@/api/blockchain/apiBlockchain';
import { useRecoilState } from 'recoil';
import WalletState from '@/store/wallet';
import useNotifications from '@/store/notifications';
Expand All @@ -27,9 +31,8 @@ interface Transaction {
}

interface MiningStats {
totalBlocks: number;
totalRewards: number;
hashRate: number;
minedBlocks: number;
rewards: number;
}

const fetchTransactionPool = async (): Promise<Transaction[]> => {
Expand All @@ -41,13 +44,9 @@ const fetchTransactionPool = async (): Promise<Transaction[]> => {
];
};

const fetchMiningStats = async (): Promise<MiningStats> => {
// Simulate fetching mining statistics
return {
totalBlocks: 1200,
totalRewards: 15000,
hashRate: 3000,
};
const fetchMiningStats = async (address: string): Promise<MiningStats> => {
const stats = await getMiningStats(address);
return stats;
};

const ExplorePage: React.FC = () => {
Expand All @@ -74,11 +73,11 @@ const ExplorePage: React.FC = () => {
const fetchData = async () => {
const transactions = await fetchTransactionPool();
setTransactionPool(transactions);
const stats = await fetchMiningStats();
const stats = await fetchMiningStats(wallet.publicKey);
setMiningStats(stats);
};
fetchData();
}, []);
}, [wallet.publicKey]);

useEffect(() => {
isValidatorRegistered(wallet.privateKey).then((stake) => {
Expand Down Expand Up @@ -170,17 +169,11 @@ const ExplorePage: React.FC = () => {
{miningStats ? (
<>
<Typography variant="body2" color="textSecondary" component="p">
Total Blocks Mined: {miningStats.totalBlocks}
Total Blocks Mined: {miningStats.minedBlocks}
</Typography>
<Typography variant="body2" color="textSecondary" component="p">
Total Rewards Earned: {miningStats.totalRewards} LCD
Total Rewards Earned: {miningStats.rewards} LCD
</Typography>
<Typography variant="body2" color="textSecondary" component="p">
Hash Rate: {miningStats.hashRate} H/s
</Typography>
<Button variant="contained" color="primary" style={{ marginTop: 16 }}>
Start Mining
</Button>
</>
) : (
<Typography variant="body2" color="textSecondary" component="p">
Expand Down

0 comments on commit c65dba3

Please sign in to comment.