overviewWidget :: forall t m. (
    SupportsServantReflex t m
  , MonadWidget t m
  ) => Behavior t ProfileState -> m ()
overviewWidget bhRouteEvent = do
  t <- liftIO $ getCurrentTime
  evClock <- tickLossy 30.0 t
  postBuild <- getPostBuild
  let evRefresh = leftmost [
          postBuild
        , (\_ -> ()) <$> evClock
        ]

  bittrexTicker <- Bittrex.tickerWidget (constDyn $ QParamSome "USDT-BTC") evRefresh
  bitfinexTicker <- Bitfinex.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  bitstampTicker <- Bitstamp.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  gdaxTicker <- GDAX.tickerWidget (Right <$> constDyn "BTC-USD") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  hitBTCTicker <- HitBTC.tickerWidget (Right <$> constDyn "BTCUSD") (Bittrex.tw_prevDay bittrexTicker) evRefresh

  -- Summaries
  let prevDay = Bittrex.tw_prevDay bittrexTicker

  let bittrexShowLast = T.pack . show <$> Bittrex.tw_last bittrexTicker
  let bittrex24hDiff = diff24hDyn prevDay (Bittrex.tw_last bittrexTicker)
  let bittrexMarket24hPercent = T.pack . show <$> bittrex24hDiff

  let bitfinexShowLast = T.pack . show <$> Bitfinex.tw_last bitfinexTicker
  let bitfinex24hDiff = diff24hDyn prevDay (Bitfinex.tw_last bitfinexTicker)
  let bitfinexMarket24hPercent = T.pack . show <$> bitfinex24hDiff

  let gdaxShowLast = T.pack . show <$> GDAX.tw_last gdaxTicker
  let gdax24hDiff = diff24hDyn prevDay (GDAX.tw_last gdaxTicker)
  let gdaxMarket24hPercent = T.pack . show <$> gdax24hDiff

  let bitstampShowLast = T.pack . show <$> Bitstamp.tw_last bitstampTicker
  let bitstamp24hDiff = diff24hDyn prevDay (Bitstamp.tw_last bitstampTicker)
  let bitstampMarket24hPercent = T.pack . show <$> bitstamp24hDiff

  let hitBTCShowLast = T.pack . show <$> HitBTC.tw_last hitBTCTicker
  let hitBTC24hDiff = diff24hDyn prevDay (HitBTC.tw_last hitBTCTicker)
  let hitBTCMarket24hPercent = T.pack . show <$> hitBTC24hDiff

  let combinedRate = averages <$> mconcat [
          (\x -> [x]) <$> Bittrex.tw_last bittrexTicker
        , (\x -> [x]) <$> Bitfinex.tw_last bitfinexTicker
        , (\x -> [x]) <$> GDAX.tw_last gdaxTicker
        , (\x -> [x]) <$> Bitstamp.tw_last bitstampTicker
        , (\x -> [x]) <$> HitBTC.tw_last hitBTCTicker
        ]

  divClass "ui centered header" $ do
    dynText (T.pack . ((++) "1BTC = $") . show <$> combinedRate)

  elClass "table" "ui table" $ do
    el "thead" $ do
      el "tr" $ do
        el "th" $ text "Exchange"
        el "th" $ text "Market"
        el "th" $ text "Last"
        el "th" $ text "24h % Delta"
    el "tbody" $ do
      el "tr" $ do
        el "td" $ text "Bittrex"
        el "td" $ dynText $ Bittrex.tw_marketName bittrexTicker
        el "td" $ dynText (T.pack . show <$> Bittrex.tw_last bittrexTicker)
        percentCell bittrex24hDiff bittrexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitfinex"
        el "td" $ dynText $ Bitfinex.tw_marketName bitfinexTicker
        el "td" $ dynText (T.pack . show <$> Bitfinex.tw_last bitfinexTicker)
        percentCell bitfinex24hDiff bitfinexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitstamp"
        el "td" $ dynText $ Bitstamp.tw_marketName bitstampTicker
        el "td" $ dynText (T.pack . show <$> Bitstamp.tw_last bitstampTicker)
        percentCell bitstamp24hDiff bitstampMarket24hPercent
      el "tr" $ do
        el "td" $ text "GDAX"
        el "td" $ dynText $ GDAX.tw_marketName gdaxTicker
        el "td" $ dynText (T.pack . show <$> GDAX.tw_last gdaxTicker)
        percentCell gdax24hDiff gdaxMarket24hPercent
      el "tr" $ do
        el "td" $ text "HitBTC"
        el "td" $ dynText $ HitBTC.tw_marketName hitBTCTicker
        el "td" $ dynText (T.pack . show <$> HitBTC.tw_last hitBTCTicker)
        percentCell hitBTC24hDiff hitBTCMarket24hPercent

  return ()
overviewWidget :: forall t m. (
    SupportsServantReflex t m
  , MonadWidget t m
  ) => Behavior t ProfileState -> m ()
overviewWidget bhRouteEvent = do
  t <- liftIO $ getCurrentTime
  evClock <- tickLossy 30.0 t
  postBuild <- getPostBuild
  let evRefresh = leftmost [
          postBuild
        , (\_ -> ()) <$> evClock
        ]

  bittrexTicker <- Bittrex.tickerWidget (constDyn $ QParamSome "USDT-BTC") evRefresh
  bitfinexTicker <- Bitfinex.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  bitstampTicker <- Bitstamp.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  gdaxTicker <- GDAX.tickerWidget (Right <$> constDyn "BTC-USD") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  hitBTCTicker <- HitBTC.tickerWidget (Right <$> constDyn "BTCUSD") (Bittrex.tw_prevDay bittrexTicker) evRefresh

  -- Summaries
  let prevDay = Bittrex.tw_prevDay bittrexTicker

  let bittrexShowLast = T.pack . show <$> Bittrex.tw_last bittrexTicker
  let bittrex24hDiff = diff24hDyn prevDay (Bittrex.tw_last bittrexTicker)
  let bittrexMarket24hPercent = T.pack . show <$> bittrex24hDiff

  let bitfinexShowLast = T.pack . show <$> Bitfinex.tw_last bitfinexTicker
  let bitfinex24hDiff = diff24hDyn prevDay (Bitfinex.tw_last bitfinexTicker)
  let bitfinexMarket24hPercent = T.pack . show <$> bitfinex24hDiff

  let gdaxShowLast = T.pack . show <$> GDAX.tw_last gdaxTicker
  let gdax24hDiff = diff24hDyn prevDay (GDAX.tw_last gdaxTicker)
  let gdaxMarket24hPercent = T.pack . show <$> gdax24hDiff

  let bitstampShowLast = T.pack . show <$> Bitstamp.tw_last bitstampTicker
  let bitstamp24hDiff = diff24hDyn prevDay (Bitstamp.tw_last bitstampTicker)
  let bitstampMarket24hPercent = T.pack . show <$> bitstamp24hDiff

  let hitBTCShowLast = T.pack . show <$> HitBTC.tw_last hitBTCTicker
  let hitBTC24hDiff = diff24hDyn prevDay (HitBTC.tw_last hitBTCTicker)
  let hitBTCMarket24hPercent = T.pack . show <$> hitBTC24hDiff

  let combinedRate = averages <$> mconcat [
          (\x -> [x]) <$> Bittrex.tw_last bittrexTicker
        , (\x -> [x]) <$> Bitfinex.tw_last bitfinexTicker
        , (\x -> [x]) <$> GDAX.tw_last gdaxTicker
        , (\x -> [x]) <$> Bitstamp.tw_last bitstampTicker
        , (\x -> [x]) <$> HitBTC.tw_last hitBTCTicker
        ]

  divClass "ui centered header" $ do
    dynText (T.pack . ((++) "1BTC = $") . show <$> combinedRate)

  elClass "table" "ui table" $ do
    el "thead" $ do
      el "tr" $ do
        el "th" $ text "Exchange"
        el "th" $ text "Market"
        el "th" $ text "Last"
        el "th" $ text "24h % Delta"
    el "tbody" $ do
      el "tr" $ do
        el "td" $ text "Bittrex"
        el "td" $ dynText $ Bittrex.tw_marketName bittrexTicker
        el "td" $ dynText (T.pack . show <$> Bittrex.tw_last bittrexTicker)
        percentCell bittrex24hDiff bittrexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitfinex"
        el "td" $ dynText $ Bitfinex.tw_marketName bitfinexTicker
        el "td" $ dynText (T.pack . show <$> Bitfinex.tw_last bitfinexTicker)
        percentCell bitfinex24hDiff bitfinexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitstamp"
        el "td" $ dynText $ Bitstamp.tw_marketName bitstampTicker
        el "td" $ dynText (T.pack . show <$> Bitstamp.tw_last bitstampTicker)
        percentCell bitstamp24hDiff bitstampMarket24hPercent
      el "tr" $ do
        el "td" $ text "GDAX"
        el "td" $ dynText $ GDAX.tw_marketName gdaxTicker
        el "td" $ dynText (T.pack . show <$> GDAX.tw_last gdaxTicker)
        percentCell gdax24hDiff gdaxMarket24hPercent
      el "tr" $ do
        el "td" $ text "HitBTC"
        el "td" $ dynText $ HitBTC.tw_marketName hitBTCTicker
        el "td" $ dynText (T.pack . show <$> HitBTC.tw_last hitBTCTicker)
        percentCell hitBTC24hDiff hitBTCMarket24hPercent

  return ()
overviewWidget bhRouteEvent = do
  t <- liftIO $ getCurrentTime
  evClock <- tickLossy 30.0 t
  postBuild <- getPostBuild
  let evRefresh = leftmost [
          postBuild
        , (\_ -> ()) <$> evClock
        ]

  bittrexTicker <- Bittrex.tickerWidget (constDyn $ QParamSome "USDT-BTC") evRefresh
  bitfinexTicker <- Bitfinex.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  bitstampTicker <- Bitstamp.tickerWidget (Right <$> constDyn "btcusd") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  gdaxTicker <- GDAX.tickerWidget (Right <$> constDyn "BTC-USD") (Bittrex.tw_prevDay bittrexTicker) evRefresh
  hitBTCTicker <- HitBTC.tickerWidget (Right <$> constDyn "BTCUSD") (Bittrex.tw_prevDay bittrexTicker) evRefresh

  -- Summaries
  let prevDay = Bittrex.tw_prevDay bittrexTicker

  let bittrexShowLast = T.pack . show <$> Bittrex.tw_last bittrexTicker
  let bittrex24hDiff = diff24hDyn prevDay (Bittrex.tw_last bittrexTicker)
  let bittrexMarket24hPercent = T.pack . show <$> bittrex24hDiff

  let bitfinexShowLast = T.pack . show <$> Bitfinex.tw_last bitfinexTicker
  let bitfinex24hDiff = diff24hDyn prevDay (Bitfinex.tw_last bitfinexTicker)
  let bitfinexMarket24hPercent = T.pack . show <$> bitfinex24hDiff

  let gdaxShowLast = T.pack . show <$> GDAX.tw_last gdaxTicker
  let gdax24hDiff = diff24hDyn prevDay (GDAX.tw_last gdaxTicker)
  let gdaxMarket24hPercent = T.pack . show <$> gdax24hDiff

  let bitstampShowLast = T.pack . show <$> Bitstamp.tw_last bitstampTicker
  let bitstamp24hDiff = diff24hDyn prevDay (Bitstamp.tw_last bitstampTicker)
  let bitstampMarket24hPercent = T.pack . show <$> bitstamp24hDiff

  let hitBTCShowLast = T.pack . show <$> HitBTC.tw_last hitBTCTicker
  let hitBTC24hDiff = diff24hDyn prevDay (HitBTC.tw_last hitBTCTicker)
  let hitBTCMarket24hPercent = T.pack . show <$> hitBTC24hDiff

  let combinedRate = averages <$> mconcat [
          (\x -> [x]) <$> Bittrex.tw_last bittrexTicker
        , (\x -> [x]) <$> Bitfinex.tw_last bitfinexTicker
        , (\x -> [x]) <$> GDAX.tw_last gdaxTicker
        , (\x -> [x]) <$> Bitstamp.tw_last bitstampTicker
        , (\x -> [x]) <$> HitBTC.tw_last hitBTCTicker
        ]

  divClass "ui centered header" $ do
    dynText (T.pack . ((++) "1BTC = $") . show <$> combinedRate)

  elClass "table" "ui table" $ do
    el "thead" $ do
      el "tr" $ do
        el "th" $ text "Exchange"
        el "th" $ text "Market"
        el "th" $ text "Last"
        el "th" $ text "24h % Delta"
    el "tbody" $ do
      el "tr" $ do
        el "td" $ text "Bittrex"
        el "td" $ dynText $ Bittrex.tw_marketName bittrexTicker
        el "td" $ dynText (T.pack . show <$> Bittrex.tw_last bittrexTicker)
        percentCell bittrex24hDiff bittrexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitfinex"
        el "td" $ dynText $ Bitfinex.tw_marketName bitfinexTicker
        el "td" $ dynText (T.pack . show <$> Bitfinex.tw_last bitfinexTicker)
        percentCell bitfinex24hDiff bitfinexMarket24hPercent
      el "tr" $ do
        el "td" $ text "Bitstamp"
        el "td" $ dynText $ Bitstamp.tw_marketName bitstampTicker
        el "td" $ dynText (T.pack . show <$> Bitstamp.tw_last bitstampTicker)
        percentCell bitstamp24hDiff bitstampMarket24hPercent
      el "tr" $ do
        el "td" $ text "GDAX"
        el "td" $ dynText $ GDAX.tw_marketName gdaxTicker
        el "td" $ dynText (T.pack . show <$> GDAX.tw_last gdaxTicker)
        percentCell gdax24hDiff gdaxMarket24hPercent
      el "tr" $ do
        el "td" $ text "HitBTC"
        el "td" $ dynText $ HitBTC.tw_marketName hitBTCTicker
        el "td" $ dynText (T.pack . show <$> HitBTC.tw_last hitBTCTicker)
        percentCell hitBTC24hDiff hitBTCMarket24hPercent

  return ()