Hampus Sjöberg
4 years ago
5 changed files with 98 additions and 25 deletions
@ -0,0 +1,16 @@ |
|||
import React from "https://esm.sh/react@17.0.2"; |
|||
import styled from "https://esm.sh/styled-components"; |
|||
|
|||
import config from "../back/config/config.ts"; |
|||
|
|||
const Title = styled.h1` |
|||
margin-top: 40px; |
|||
font-size: 42px; |
|||
text-align: center; |
|||
color: #d97b08; |
|||
text-shadow: #000 3px 3px 0px; |
|||
`;
|
|||
|
|||
const TitleComponent = () => <Title>{config.fork.name} activation</Title>; |
|||
|
|||
export default TitleComponent; |
@ -0,0 +1,54 @@ |
|||
import { action, Action, createStore, createTypedHooks, thunk, Thunk } from "https://esm.sh/easy-peasy"; |
|||
|
|||
import { IBlock } from "../back/blocks/index.ts"; |
|||
import config from "../back/config/config.ts"; |
|||
|
|||
export interface IStoreModel { |
|||
getBlocks: Thunk<IStoreModel>; |
|||
setBlocks: Action<IStoreModel, IBlock[]>; |
|||
blocks: IBlock[]; |
|||
} |
|||
|
|||
export const model: IStoreModel = { |
|||
getBlocks: thunk(async (actions) => { |
|||
if (config.mode === "real") { |
|||
const result = await fetch("/blocks"); |
|||
const json = (await result.json()) as IBlock[]; |
|||
console.log(json); |
|||
actions.setBlocks(json); |
|||
} else { |
|||
const start = 0; |
|||
const end = 1800; |
|||
const blocks: IBlock[] = []; |
|||
for (let i = start; i < 2016; i++) { |
|||
if (i < end) { |
|||
blocks.push({ |
|||
height: i, |
|||
signals: Math.floor(Math.random() * 100 + 1) > 35, |
|||
coinbase: undefined, |
|||
miner: undefined, |
|||
}); |
|||
} else { |
|||
blocks.push({ |
|||
height: i, |
|||
signals: undefined, |
|||
coinbase: undefined, |
|||
miner: undefined, |
|||
}); |
|||
} |
|||
} |
|||
actions.setBlocks(blocks); |
|||
} |
|||
}), |
|||
|
|||
setBlocks: action((state, payload) => { |
|||
state.blocks = payload; |
|||
}), |
|||
|
|||
blocks: [], |
|||
}; |
|||
|
|||
const { useStoreActions, useStoreState } = createTypedHooks<IStoreModel>(); |
|||
export { useStoreActions, useStoreState }; |
|||
|
|||
export default createStore(model); |
Loading…
Reference in new issue