Browse Source

miners: Fix buggy percentage calculation

refactor
Hampus Sjöberg 4 years ago
parent
commit
87ed56ed54
  1. 11
      frontend/pages/miners.tsx

11
frontend/pages/miners.tsx

@ -8,14 +8,14 @@ import { Content } from "../components/Content.ts";
import SiteTitle from "../components/SiteTitle.tsx"; import SiteTitle from "../components/SiteTitle.tsx";
import { useStoreState } from "../state/index.ts"; import { useStoreState } from "../state/index.ts";
import SiteMenu from "../components/SiteMenu.tsx"; import SiteMenu from "../components/SiteMenu.tsx";
import { Donation } from "../components/Donation.tsx";
const Table = styled.table` const Table = styled.table`
width: 100%; width: 100%;
max-width: 1000px; max-width: 1000px;
box-shadow: #000 3px 3px 14px; box-shadow: #000 3px 3px 14px;
border-radius: 6px; border-radius: 6px;
margin: 0 auto 100px; margin: 0 auto 30px;
border: 0; border: 0;
border-collapse: collapse; border-collapse: collapse;
border-radius: 8px; border-radius: 8px;
@ -72,8 +72,8 @@ interface IMinerData {
export default function Miners() { export default function Miners() {
const blocks = useStoreState((store) => store.blocks); const blocks = useStoreState((store) => store.blocks);
const forkName = config.fork.name; const forkName = config.fork.name;
const currentNumberOfBlocks = blocks.reduce((prev, currentBlock) => prev + +(currentBlock.signals !== undefined), 0);
const miners = useMemo(() => { const miners = useMemo(() => {
// We have to reverse the array as we have to check // We have to reverse the array as we have to check
@ -94,6 +94,7 @@ export default function Miners() {
website: currBlock.minerWebsite, website: currBlock.minerWebsite,
numBlocks: 1, numBlocks: 1,
}; };
return prev;
} }
prev[currBlock.miner].numBlocks++; prev[currBlock.miner].numBlocks++;
return prev; return prev;
@ -119,7 +120,6 @@ export default function Miners() {
<TableBody> <TableBody>
{Object.entries(miners).map(([_, miner]) => { {Object.entries(miners).map(([_, miner]) => {
console.log(miner.numBlocks / 2016);
return ( return (
<TableRow> <TableRow>
<Cell> <Cell>
@ -130,7 +130,7 @@ export default function Miners() {
)} )}
{!miner.website && miner.name} {!miner.website && miner.name}
</Cell> </Cell>
<Cell>{((miner.numBlocks / 2016) * 100).toFixed(1)}%</Cell> <Cell>{((miner.numBlocks / currentNumberOfBlocks) * 100).toFixed(1)}%</Cell>
<SignallingCell> <SignallingCell>
{miner.signals && <></>} {miner.signals && <></>}
{!miner.signals && <>🚫</>} {!miner.signals && <>🚫</>}
@ -140,6 +140,7 @@ export default function Miners() {
})} })}
</TableBody> </TableBody>
</Table> </Table>
{config.donation && <Donation />}
</Content> </Content>
</Container> </Container>
); );

Loading…
Cancel
Save