diff options
author | Hsuan Lee <boczeratul@gmail.com> | 2019-04-11 19:33:56 +0800 |
---|---|---|
committer | Hsuan Lee <boczeratul@gmail.com> | 2019-04-11 19:33:56 +0800 |
commit | 9028b5e4179d63ff91d61c1da4a5144a16e0c136 (patch) | |
tree | 0793c1ffb1984d2f12bcc5f806c440b2c1665746 | |
parent | 49cb2ee8f8aceb96fd594d8db1d96df817d1f62c (diff) | |
download | dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar.gz dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar.bz2 dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar.lz dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar.xz dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.tar.zst dexon-lottery-9028b5e4179d63ff91d61c1da4a5144a16e0c136.zip |
Add timer for next lucky draw
-rw-r--r-- | app/containers/App/LastItem.js | 2 | ||||
-rw-r--r-- | app/containers/App/LotteryItem.js | 2 | ||||
-rw-r--r-- | app/containers/App/Timer.js | 64 | ||||
-rw-r--r-- | app/services/Lottery/constants.js | 1 | ||||
-rw-r--r-- | app/services/Lottery/index.js | 5 | ||||
-rw-r--r-- | constants.js | 65 | ||||
-rw-r--r-- | runTimer.js | 69 |
7 files changed, 124 insertions, 84 deletions
diff --git a/app/containers/App/LastItem.js b/app/containers/App/LastItem.js index 26485ef..1f072b3 100644 --- a/app/containers/App/LastItem.js +++ b/app/containers/App/LastItem.js @@ -21,7 +21,7 @@ const Marker = styled.span` const Item = styled.a` min-height: min-content; margin-top: 20px; - flex: 1 0 auto; + flex: 0 0 auto; display: flex; align-items: flex-end; white-space: pre; diff --git a/app/containers/App/LotteryItem.js b/app/containers/App/LotteryItem.js index 4e59ca5..348a541 100644 --- a/app/containers/App/LotteryItem.js +++ b/app/containers/App/LotteryItem.js @@ -20,7 +20,7 @@ const Marker = styled.span` const Item = styled.a` min-height: min-content; margin-top: 20px; - flex: 1 0 auto; + flex: 0 0 auto; display: flex; align-items: flex-end; white-space: pre; diff --git a/app/containers/App/Timer.js b/app/containers/App/Timer.js index a164cd1..c62fce3 100644 --- a/app/containers/App/Timer.js +++ b/app/containers/App/Timer.js @@ -4,16 +4,34 @@ import styled from 'styled-components'; import moment from 'moment'; import { Container, Header } from '@/components/Mux'; +import { times } from '../../../constants'; const LAUNCH_TIME = 1556164800000; + +const HorizontalContainer = styled.div` + display: flex; + flex-direction: row; + position: relative; + margin: 0 5px; +`; + +const StretchedContainer = styled(Container)` + flex: 1; + margin-left: 10px; + margin-right: 10px; +`; + const Time = styled.div` - font-size: 72px; + font-size: 60px; `; + const pad = number => `0${number}`.slice(-2); +const findNext = () => times.find(time => time * 1000 > Date.now()) * 1000 || 0; class Timer extends PureComponent { state = { - duration: LAUNCH_TIME - Date.now(), + mainnetDuration: LAUNCH_TIME - Date.now(), + drawDuration: findNext() - Date.now(), }; componentDidMount() { @@ -21,22 +39,42 @@ class Timer extends PureComponent { } updateTime = () => { - this.setState({ duration: LAUNCH_TIME - Date.now() }); + const nextTime = findNext(); + + this.setState({ + mainnetDuration: LAUNCH_TIME - Date.now(), + drawDuration: nextTime - Date.now(), + }); } render() { - const duration = moment.duration(this.state.duration); + const { mainnetDuration, drawDuration } = this.state; + + const mainnetDurationDisplay = moment.duration(mainnetDuration); + const drawDurationDisplay = moment.duration(drawDuration); return ( - <Container> - <Header> - Time Until DEXON Mainnet Launch - </Header> - - <Time> - {(duration.days() * 24) + duration.hours()}:{pad(duration.minutes())}:{pad(duration.seconds())} - </Time> - </Container> + <HorizontalContainer> + <StretchedContainer> + <Header> + Time Until DEXON Mainnet Launch + </Header> + + <Time> + {(mainnetDurationDisplay.days() * 24) + mainnetDurationDisplay.hours()}:{pad(mainnetDurationDisplay.minutes())}:{pad(mainnetDurationDisplay.seconds())} + </Time> + </StretchedContainer> + + <StretchedContainer> + <Header> + Time Until Next Lucky Draw + </Header> + + <Time> + {(drawDurationDisplay.days() * 24) + drawDurationDisplay.hours()}:{pad(drawDurationDisplay.minutes())}:{pad(drawDurationDisplay.seconds())} + </Time> + </StretchedContainer> + </HorizontalContainer> ); } } diff --git a/app/services/Lottery/constants.js b/app/services/Lottery/constants.js index dd6062a..cab6009 100644 --- a/app/services/Lottery/constants.js +++ b/app/services/Lottery/constants.js @@ -1,2 +1 @@ export const DEXON_TESTNET = 'https://testnet-rpc.dexon.org'; -export const LOTTERY_ADDRESS = '0xAE64Df55807E2B9a58A124AB7d852EeBCAEb7CB9'; diff --git a/app/services/Lottery/index.js b/app/services/Lottery/index.js index 4244122..09b7d09 100644 --- a/app/services/Lottery/index.js +++ b/app/services/Lottery/index.js @@ -1,8 +1,9 @@ import Web3 from '@cobinhood/web3'; -import { DEXON_TESTNET, LOTTERY_ADDRESS } from './constants'; +import { address } from '../../../constants'; +import { DEXON_TESTNET } from './constants'; import { abi } from '../../../build/contracts/Lottery.json'; const web3 = new Web3(new Web3.providers.HttpProvider(DEXON_TESTNET)); -const lotteryContract = new web3.eth.Contract(abi, LOTTERY_ADDRESS); +const lotteryContract = new web3.eth.Contract(abi, address); export default lotteryContract; diff --git a/constants.js b/constants.js new file mode 100644 index 0000000..ee6590d --- /dev/null +++ b/constants.js @@ -0,0 +1,65 @@ +const address = '0xccc538a0DceA6608F8F7EBF649cFB550f2223230'; +const times = [ + 1555570800, // 4/18 15:00 + 1555581600, // 4/18 18:00 + 1555592400, // 4/18 21:00 + 1555603200, // 4/19 0:00 + 1555614000, // 4/19 3:00 + 1555624800, // 4/19 6:00 + 1555635600, // 4/19 9:00 + 1555646400, // 4/19 12:00 + 1555657200, // 4/19 15:00 + 1555668000, // 4/19 18:00 + 1555678800, // 4/19 21:00 + 1555689600, // 4/20 0:00 + 1555700400, // 4/20 3:00 + 1555711200, // 4/20 6:00 + 1555722000, // 4/20 9:00 + 1555732800, // 4/20 12:00 + 1555743600, // 4/20 15:00 + 1555754400, // 4/20 18:00 + 1555765200, // 4/20 21:00 + 1555776000, // 4/21 0:00 + 1555786800, // 4/21 3:00 + 1555797600, // 4/21 6:00 + 1555808400, // 4/21 9:00 + 1555819200, // 4/21 12:00 + 1555830000, // 4/21 15:00 + 1555840800, // 4/21 18:00 + 1555851600, // 4/21 21:00 + 1555862400, // 4/22 0:00 + 1555873200, // 4/22 3:00 + 1555884000, // 4/22 6:00 + 1555894800, // 4/22 9:00 + 1555905600, // 4/22 12:00 + 1555916400, // 4/22 15:00 + 1555927200, // 4/22 18:00 + 1555938000, // 4/22 21:00 + 1555948800, // 4/23 0:00 + 1555959600, // 4/23 3:00 + 1555970400, // 4/23 6:00 + 1555981200, // 4/23 9:00 + 1555992000, // 4/23 12:00 + 1556002800, // 4/23 15:00 + 1556013600, // 4/23 18:00 + 1556024400, // 4/23 21:00 + 1556035200, // 4/24 0:00 + 1556046000, // 4/24 3:00 + 1556056800, // 4/24 6:00 + 1556067600, // 4/24 9:00 + 1556078400, // 4/24 12:00 + 1556089200, // 4/24 15:00 + 1556100000, // 4/24 18:00 + 1556110800, // 4/24 21:00 + 1556121600, // 4/25 0:00 + 1556132400, // 4/25 3:00 + 1556143200, // 4/25 6:00 + 1556154000, // 4/25 9:00 + 1556164800, // 4/25 12:00 +]; + +module.exports = { + address, + times, +}; + diff --git a/runTimer.js b/runTimer.js index f16098d..4ee6f16 100644 --- a/runTimer.js +++ b/runTimer.js @@ -2,75 +2,10 @@ const Web3 = require('@cobinhood/web3'); const { mnemonicToSeed } = require('bip39'); const { fromMasterSeed } = require('ethereumjs-wallet/hdkey'); const { mnemonic } = require('./secret'); +const { address, times } = require('./constants'); const lottery = require('./build/contracts/Lottery.json'); -const address = '0xd6141c8099670fe22a67eea3224d559c5d05aa55'; - const web3 = new Web3('https://testnet-rpc.dexon.org'); -// const times = [ -// 1555570800, // 4/18 15:00 -// 1555581600, // 4/18 18:00 -// 1555592400, // 4/18 21:00 -// 1555603200, // 4/19 0:00 -// 1555614000, // 4/19 3:00 -// 1555624800, // 4/19 6:00 -// 1555635600, // 4/19 9:00 -// 1555646400, // 4/19 12:00 -// 1555657200, // 4/19 15:00 -// 1555668000, // 4/19 18:00 -// 1555678800, // 4/19 21:00 -// 1555689600, // 4/20 0:00 -// 1555700400, // 4/20 3:00 -// 1555711200, // 4/20 6:00 -// 1555722000, // 4/20 9:00 -// 1555732800, // 4/20 12:00 -// 1555743600, // 4/20 15:00 -// 1555754400, // 4/20 18:00 -// 1555765200, // 4/20 21:00 -// 1555776000, // 4/21 0:00 -// 1555786800, // 4/21 3:00 -// 1555797600, // 4/21 6:00 -// 1555808400, // 4/21 9:00 -// 1555819200, // 4/21 12:00 -// 1555830000, // 4/21 15:00 -// 1555840800, // 4/21 18:00 -// 1555851600, // 4/21 21:00 -// 1555862400, // 4/22 0:00 -// 1555873200, // 4/22 3:00 -// 1555884000, // 4/22 6:00 -// 1555894800, // 4/22 9:00 -// 1555905600, // 4/22 12:00 -// 1555916400, // 4/22 15:00 -// 1555927200, // 4/22 18:00 -// 1555938000, // 4/22 21:00 -// 1555948800, // 4/23 0:00 -// 1555959600, // 4/23 3:00 -// 1555970400, // 4/23 6:00 -// 1555981200, // 4/23 9:00 -// 1555992000, // 4/23 12:00 -// 1556002800, // 4/23 15:00 -// 1556013600, // 4/23 18:00 -// 1556024400, // 4/23 21:00 -// 1556035200, // 4/24 0:00 -// 1556046000, // 4/24 3:00 -// 1556056800, // 4/24 6:00 -// 1556067600, // 4/24 9:00 -// 1556078400, // 4/24 12:00 -// 1556089200, // 4/24 15:00 -// 1556100000, // 4/24 18:00 -// 1556110800, // 4/24 21:00 -// 1556121600, // 4/25 0:00 -// 1556132400, // 4/25 3:00 -// 1556143200, // 4/25 6:00 -// 1556154000, // 4/25 9:00 -// 1556164800, // 4/25 12:00 -// ]; - -const times = [ - 1554636900, - 1554636910, - 1554636920, -]; let account; let contract; @@ -93,6 +28,8 @@ mnemonicToSeed(mnemonic) .then((seed) => { const hdWallet = fromMasterSeed(seed); const key = hdWallet.derivePath('m/44\'/237\'/0\'/0/0'); + + // eslint-disable-next-line no-underscore-dangle const privateKey = `0x${key._hdkey._privateKey.toString('hex')}`; web3.eth.accounts.wallet.add(privateKey); |