From af4562f09b1ca332a73895f850466d2288b87943 Mon Sep 17 00:00:00 2001 From: Sunny Gleason Date: Thu, 1 Aug 2019 10:05:05 -0400 Subject: [PATCH] feat: stat cards and stage configuration for TdS --- src/v2/components/TourDeSol/Cards/index.jsx | 16 ++- src/v2/components/TourDeSol/index.jsx | 103 +++++++++++++++++--- 2 files changed, 100 insertions(+), 19 deletions(-) diff --git a/src/v2/components/TourDeSol/Cards/index.jsx b/src/v2/components/TourDeSol/Cards/index.jsx index 73b39c18..7efaab05 100644 --- a/src/v2/components/TourDeSol/Cards/index.jsx +++ b/src/v2/components/TourDeSol/Cards/index.jsx @@ -7,7 +7,11 @@ import Card from 'v2/components/UI/StatCard'; import useStyles from './styles'; -const Cards = () => { +const Cards = ({ + stageDurationBlocks = null, + blocksLeftInStage = null, + daysLeftInStage = null, +}) => { const classes = useStyles(); const { cluster, @@ -19,13 +23,19 @@ const Cards = () => { const cards = [ { title: 'Stage Duration Blocks', - value: 'TODO', + value: stageDurationBlocks || '...', + changes: '', + period: 'since yesterday', + }, + { + title: 'Blocks Left In Stage', + value: blocksLeftInStage || '...', changes: '', period: 'since yesterday', }, { title: 'Days Left In Stage', - value: 'TODO', + value: daysLeftInStage || '...', changes: '', period: 'since yesterday', }, diff --git a/src/v2/components/TourDeSol/index.jsx b/src/v2/components/TourDeSol/index.jsx index 6fd38704..cad70e09 100644 --- a/src/v2/components/TourDeSol/index.jsx +++ b/src/v2/components/TourDeSol/index.jsx @@ -5,32 +5,99 @@ import cn from 'classnames'; import {observer} from 'mobx-react-lite'; import SectionHeader from 'v2/components/UI/SectionHeader'; import iconRight from 'v2/assets/icons/arrow-right-dark.png'; - import Ranking from './Ranking'; import Table from './Table'; import Cards from './Cards'; +import OverviewStore from 'v2/stores/networkOverview'; + import useStyles from './styles'; +import _ from 'lodash'; +import moment from 'moment'; + +const SLOTS_PER_DAY = (1.0 * 24 * 60 * 60) / 0.8; +const TDS_ACTIVE_STAGE = parseInt(process.env.TDS_ACTIVE_STAGE || '0'); +const TDS_DEFAULT_STAGE_LENGTH_BLOCKS = SLOTS_PER_DAY * 5.0; + +const TDS_STAGES = [ + {title: 'Stage 0', hidden: true}, + { + title: 'Stage 1', + start_date: '2019-09-02T17:00:00.0Z', + end_date: '2019-09-06T17:00:00.0Z', + duration: TDS_DEFAULT_STAGE_LENGTH_BLOCKS, + }, + { + title: 'Stage 2', + start_date: '2019-09-09T17:00:00.0Z', + end_date: '2019-09-13T17:00:00.0Z', + duration: TDS_DEFAULT_STAGE_LENGTH_BLOCKS, + }, + { + title: 'Stage 3', + start_date: '2019-09-16T17:00:00.0Z', + end_date: '2019-09-20T17:00:00.0Z', + duration: TDS_DEFAULT_STAGE_LENGTH_BLOCKS, + }, +]; const TourDeSol = () => { const classes = useStyles(); + const currentStage = + TDS_ACTIVE_STAGE < TDS_STAGES.length && TDS_STAGES[TDS_ACTIVE_STAGE]; + + const {globalStats} = OverviewStore; + const slot = globalStats['!blkLastSlot']; + const slotsLeftInStage = + currentStage && currentStage.duration && currentStage.duration - slot; + const daysLeftInStage = + slotsLeftInStage && (slotsLeftInStage / SLOTS_PER_DAY).toFixed(3); + + function renderStage(stage, i) { + if (stage.hidden) { + return; + } + + const isActive = i === TDS_ACTIVE_STAGE; + const isFinished = i < TDS_ACTIVE_STAGE; + const stageDateStart = moment(stage.start_date).format('l'); + const stageDateEnd = moment(stage.end_date).format('l'); + + if (isActive) { + return ( +
  • +
    + {stage.title} (LIVE!) + +
    +
  • + ); + } else if (isFinished) { + return ( +
  • +
    + {stage.title} +
    + (finished {stageDateEnd}) +
    +
  • + ); + } else { + return ( +
  • +
    + {stage.title} +
    + (coming {stageDateStart}) +
    +
  • + ); + } + } return ( -
      -
    • -
      - Stage 1 (live!) - -
      -
    • -
    • - Stage 1(coming 09/01/19) -
    • -
    • - Stage 3(coming 10/01/19) -
    • -
    +
      {_.map(TDS_STAGES, renderStage)}
    @@ -38,7 +105,11 @@ const TourDeSol = () => { - +