diff --git a/lib/basket_web/live/overview.ex b/lib/basket_web/live/overview.ex index 8cf2629..1e46969 100644 --- a/lib/basket_web/live/overview.ex +++ b/lib/basket_web/live/overview.ex @@ -44,14 +44,7 @@ defmodule BasketWeb.Overview do {:ok, response} -> %{"bars" => ticker_bars} = response - initial_bars = - if ticker_bars == %{} do - %{"t" => "Market Closed"} - else - Enum.reduce(ticker_bars, %{}, fn {k, v}, acc -> - Map.put(acc, k, %TickerBar{value: v}) - end) - end + initial_bars = build_ticker_bars(ticker_bars) assign( socket, @@ -124,6 +117,16 @@ defmodule BasketWeb.Overview do """ end + defp build_ticker_bars(ticker_bars) do + if ticker_bars == %{} do + %{"t" => "Market Closed"} + else + Enum.reduce(ticker_bars, %{}, fn {k, v}, acc -> + Map.put(acc, k, %TickerBar{value: v}) + end) + end + end + defp load_tickers do case Http.Alpaca.list_assets() do {:ok, result} -> diff --git a/test/basket_web/live/overview_test.exs b/test/basket_web/live/overview_test.exs index 07eb48f..90fd7cb 100644 --- a/test/basket_web/live/overview_test.exs +++ b/test/basket_web/live/overview_test.exs @@ -263,7 +263,7 @@ defmodule BasketWeb.OverviewTest do value: "2023-11-15T20:59:00Z", prev_value: "2023-11-15T20:58:00Z" }, - "v" => %TickerBar{value: 43031, prev_value: 43025}, + "v" => %TickerBar{value: 43_031, prev_value: 43_025}, "vw" => %TickerBar{value: 188.117416, prev_value: 187.137416} } ] @@ -284,7 +284,7 @@ defmodule BasketWeb.OverviewTest do value: "2023-11-15T20:59:00Z", prev_value: "2023-11-15T20:59:00Z" }, - "v" => %TickerBar{value: 43031, prev_value: 43031}, + "v" => %TickerBar{value: 43_031, prev_value: 43_031}, "vw" => %TickerBar{ value: 188.117416, prev_value: 187.117416