Browse Source

index: Improvements for the block and signalling text

refactor
Hampus Sjöberg 4 years ago
parent
commit
21cfe36a50
  1. 37
      frontend/pages/index.tsx
  2. 25
      frontend/state/index.ts

37
frontend/pages/index.tsx

@ -11,6 +11,8 @@ import SiteTitle from "../components/SiteTitle.tsx";
import SiteMenu from "../components/SiteMenu.tsx"; import SiteMenu from "../components/SiteMenu.tsx";
import { useStoreState } from "../state/index.ts"; import { useStoreState } from "../state/index.ts";
const forkName = config.fork.name;
const DescriptionBlock = styled.div` const DescriptionBlock = styled.div`
max-width: 600px; max-width: 600px;
margin: auto; margin: auto;
@ -38,6 +40,7 @@ const CurrentPeriod = styled.h2`
const LockinInfo = styled.h2` const LockinInfo = styled.h2`
font-size: 16px; font-size: 16px;
text-align: right;
margin-bottom: 10px; margin-bottom: 10px;
color: #ff9b20; color: #ff9b20;
text-shadow: #000 2px 2px 0px; text-shadow: #000 2px 2px 0px;
@ -51,9 +54,8 @@ const BootstrappingInProgress = styled.p`
export default function Blocks() { export default function Blocks() {
const blocks = useStoreState((store) => store.blocks); const blocks = useStoreState((store) => store.blocks);
const forkName = config.fork.name;
const treshhold = config.fork.threshold; const treshhold = config.fork.threshold;
const currentNumberOfBlocks = blocks.reduce((prev, currentBlock) => prev + +(currentBlock.signals !== undefined), 0);
const currentNumberOfSignallingBlocks = blocks.reduce( const currentNumberOfSignallingBlocks = blocks.reduce(
(prev, currentBlock) => prev + +(currentBlock.signals ?? false), (prev, currentBlock) => prev + +(currentBlock.signals ?? false),
0 0
@ -63,6 +65,14 @@ export default function Blocks() {
const blocksLeftInThisPeriod = blocks.reduce((prev, currentBlock) => prev + +(currentBlock.signals === undefined), 0); const blocksLeftInThisPeriod = blocks.reduce((prev, currentBlock) => prev + +(currentBlock.signals === undefined), 0);
const currentPeriodFailed = blocksLeftForActivation > blocksLeftInThisPeriod; const currentPeriodFailed = blocksLeftForActivation > blocksLeftInThisPeriod;
const currentSignallingRatio = currentNumberOfSignallingBlocks / currentNumberOfBlocks;
const currentSignallingPercentage = (currentSignallingRatio * 100).toFixed(2);
let willProbablyActivate: boolean | undefined = undefined;
if (currentNumberOfBlocks >= 144) {
const estimatedSignallingBlocksLeft = Math.floor(currentSignallingRatio * blocksLeftInThisPeriod);
willProbablyActivate = estimatedSignallingBlocksLeft <= blocksLeftInThisPeriod && currentSignallingRatio >= 0.9;
}
return ( return (
<Container> <Container>
<head> <head>
@ -78,22 +88,33 @@ export default function Blocks() {
</DescriptionBlock> </DescriptionBlock>
<TopSection> <TopSection>
<CurrentPeriod>Current signalling period of 2016 blocks</CurrentPeriod> <CurrentPeriod>Current signalling period of 2016 blocks</CurrentPeriod>
{/* <LockinInfo>90% of blocks within the period has to signal.</LockinInfo> */}
<LockinInfo> <LockinInfo>
{lockedIn && <>{forkName.toUpperCase()} IS LOCKED IN FOR DEPLOYMENT!</>}
{!lockedIn && ( {!lockedIn && (
<> <>
{blocksLeftForActivation} {forkName} blocks left until softfork is locked in. {!currentPeriodFailed && (
<br /> <>
{!currentPeriodFailed && <>90% of the blocks within the period has to signal.</>} {blocksLeftForActivation} {forkName} blocks left until softfork is locked in.
<br />
{willProbablyActivate && (
<>Taproot will lock in with the current signalling ratio ({currentSignallingPercentage}%)!</>
)}
{!willProbablyActivate && (
<>Taproot will not lock in with the current signalling ratio ({currentSignallingPercentage}%)</>
)}
</>
)}
{currentPeriodFailed && ( {currentPeriodFailed && (
<> <>
{forkName} cannot be locked in within this period {forkName} cannot be locked in within this period.
<br /> <br />
(90% of the blocks has to signal). {blocksLeftForActivation} more blocks required to reach 90%, only {blocksLeftInThisPeriod} blocks
left.
</> </>
)} )}
</> </>
)} )}
{lockedIn && <>{forkName.toUpperCase()} IS LOCKED IN FOR DEPLOYMENT!</>}
</LockinInfo> </LockinInfo>
</TopSection> </TopSection>
<BlockContainer> <BlockContainer>

25
frontend/state/index.ts

@ -18,22 +18,31 @@ export const model: IStoreModel = {
actions.setBlocks(json); actions.setBlocks(json);
} else { } else {
const start = 0; const start = 0;
const end = 1800; const end = 1500;
const blocks: IBlock[] = []; const blocks: IBlock[] = [];
for (let i = start; i < 2016; i++) { for (let i = start; i < 2016; i++) {
if (i < end) { if (i < end) {
blocks.push({ if (Math.floor(Math.random() * 100 + 1) > 20) {
height: i, blocks.push({
signals: Math.floor(Math.random() * 100 + 1) > 35, height: i,
coinbase: undefined, signals: true,
miner: undefined, miner: "abc",
}); minerWebsite: undefined,
});
} else {
blocks.push({
height: i,
signals: false,
miner: "def",
minerWebsite: undefined,
});
}
} else { } else {
blocks.push({ blocks.push({
height: i, height: i,
signals: undefined, signals: undefined,
coinbase: undefined,
miner: undefined, miner: undefined,
minerWebsite: undefined,
}); });
} }
} }

Loading…
Cancel
Save