aboutsummaryrefslogtreecommitdiffstats
path: root/app/containers/App/Console.js
diff options
context:
space:
mode:
authorHsuan Lee <boczeratul@gmail.com>2019-04-08 22:18:34 +0800
committerHsuan Lee <boczeratul@gmail.com>2019-04-08 22:18:34 +0800
commitb9c0c169ce805124cb6b3fb84c7db8df9a76151e (patch)
tree88d4b5a09267a9cc9e4d56ccadeebe588dc36284 /app/containers/App/Console.js
parent336162ac78ad3d5c787c5ecfe735b98d423c4053 (diff)
downloaddexon-lottery-b9c0c169ce805124cb6b3fb84c7db8df9a76151e.tar.gz
dexon-lottery-b9c0c169ce805124cb6b3fb84c7db8df9a76151e.tar.zst
dexon-lottery-b9c0c169ce805124cb6b3fb84c7db8df9a76151e.zip
Complete webapp
Diffstat (limited to 'app/containers/App/Console.js')
-rw-r--r--app/containers/App/Console.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/containers/App/Console.js b/app/containers/App/Console.js
new file mode 100644
index 0000000..ba8f6fc
--- /dev/null
+++ b/app/containers/App/Console.js
@@ -0,0 +1,65 @@
+import React, { PureComponent } from 'react';
+import styled from 'styled-components';
+import { Container, Header } from '@/components/Mux';
+import LotteryContract from '@/services/Lottery';
+import LotteryItem from './LotteryItem';
+
+const StretchedContainer = styled(Container)`
+ flex: 1 1 auto;
+`;
+
+const Body = styled.div`
+ overflow: auto;
+ position: absolute;
+ height: calc(100% - 30px);
+ width: calc(100% - 40px);
+ display: flex;
+ flex-direction: column;
+ justify-content: flex-end;
+`;
+
+// eslint-disable-next-line react/prefer-stateless-function
+class Console extends PureComponent {
+ state = {
+ list: [],
+ };
+
+ componentDidMount() {
+ this.updateList();
+ setInterval(this.updateList, 10000);
+ }
+
+ updateList = () => {
+ LotteryContract.getPastEvents('NumberRevealed', {
+ fromBlock: 0,
+ toBlock: 'latest',
+ })
+ .then(events => this.setState({ list: events }));
+ }
+
+ render() {
+ const { list } = this.state;
+
+ return (
+ <StretchedContainer>
+ <Header>
+ Lottery History
+ </Header>
+
+ <Body>
+ {list.map(event => (
+ <LotteryItem
+ key={event.transactionHash}
+ hash={event.transactionHash}
+ timestamp={event.returnValues[0]}
+ number={`00${event.returnValues[1]}`.slice(-3)}
+ rawValue={event.returnValues[2]}
+ />
+ ))}
+ </Body>
+ </StretchedContainer>
+ );
+ }
+}
+
+export default Console;