You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.4 KiB

4 years ago
import React, { useEffect, useState } from "https://esm.sh/react@17.0.2";
import styled from "https://esm.sh/styled-components";
import config from "../back/config/config.ts";
import { IBlock } from "../back/blocks/index.ts";
4 years ago
import { Container } from "../components/Container.ts";
import { Content } from "../components/Content.ts";
4 years ago
import { BlockContainer, Block } from "../components/Block.tsx";
import { Donation } from "../components/Donation.tsx";
4 years ago
const Title = styled.h1`
4 years ago
margin-top: 40px;
4 years ago
font-size: 42px;
text-align: center;
color: #d97b08;
text-shadow: #000 3px 3px 0px;
`;
const DescriptionBlock = styled.div`
max-width: 600px;
margin: auto;
`;
const Text = styled.p`
color: #f7f7f7;
/* text-shadow: #000 2px 2px 0px; */
font-size: 16px;
text-align: center;
`;
4 years ago
const TopSection = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
`;
const CurrentPeriod = styled.h2`
4 years ago
font-size: 24px;
margin-bottom: 10px;
color: #ff9b20;
text-shadow: #000 2px 2px 0px;
4 years ago
`;
4 years ago
const LockinInfo = styled.h2`
font-size: 16px;
margin-bottom: 10px;
color: #ff9b20;
text-shadow: #000 2px 2px 0px;
4 years ago
`;
4 years ago
export default function Blocks() {
4 years ago
const [blocks, setBlocks] = useState<IBlock[] | undefined>(undefined);
4 years ago
useEffect(() => {
(async () => {
const result = await fetch("/blocks");
const json = (await result.json()) as IBlock[];
console.log(json);
setBlocks(json);
})();
}, []);
if (blocks === undefined) {
return <></>;
}
4 years ago
const forkName = config.fork.name;
const treshhold = config.fork.threshold;
4 years ago
const currentNumberOfSignallingBlocks = blocks.reduce(
(prev, currentBlock) => prev + +(currentBlock.signals ?? false),
0
);
const blocksLeftForActivation = treshhold - currentNumberOfSignallingBlocks;
const lockedIn = currentNumberOfSignallingBlocks >= treshhold;
const blocksLeftInThisPeriod = blocks.reduce((prev, currentBlock) => prev + +(currentBlock.signals === undefined), 0);
const currentPeriodFailed = blocksLeftForActivation > blocksLeftInThisPeriod;
4 years ago
return (
<Container>
<head>
4 years ago
<title>{forkName} activation</title>
4 years ago
</head>
<Content>
4 years ago
<Title>{forkName} activation</Title>
4 years ago
<DescriptionBlock>
{config.fork.info.map((text, index) => (
<Text key={index}>{text}</Text>
))}
</DescriptionBlock>
4 years ago
<TopSection>
<CurrentPeriod>Current signalling period of 2016 blocks</CurrentPeriod>
<LockinInfo>
{!lockedIn && (
<>
{blocksLeftForActivation} {forkName} blocks left until softfork is locked in.
<br />
{!currentPeriodFailed && <>90% of the blocks within the period has to signal.</>}
{currentPeriodFailed && (
<>
{forkName} cannot be locked in within this period
<br />
(90% of the blocks has to signal).
</>
)}
</>
)}
{lockedIn && <>{forkName.toUpperCase()} IS LOCKED IN FOR DEPLOYMENT!</>}
</LockinInfo>
</TopSection>
4 years ago
<BlockContainer>
{blocks.map((block, i) => (
<Block key={i} height={block.height} signals={block.signals} />
))}
</BlockContainer>
{config.donation && <Donation />}
4 years ago
</Content>
</Container>
);
}