From db2e47a7556f1b7829b495eab1cbf0e632e7f80d Mon Sep 17 00:00:00 2001 From: Zach Schmid Date: Tue, 15 Aug 2017 15:00:03 -0500 Subject: [PATCH] fixing bug where current value only pulls from the first entry --- lib/cryptofolio/web/templates/portfolio/index.html.eex | 2 +- lib/cryptofolio/web/views/portfolio_view.ex | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cryptofolio/web/templates/portfolio/index.html.eex b/lib/cryptofolio/web/templates/portfolio/index.html.eex index f10b8ae..a69de1b 100644 --- a/lib/cryptofolio/web/templates/portfolio/index.html.eex +++ b/lib/cryptofolio/web/templates/portfolio/index.html.eex @@ -107,7 +107,7 @@ e class="portfolio-pie" <%= format_money(coin_trades_cost(coin_trades), @fiat) %> <%= format_money(coin_trades_total_cost(coin_trades), @fiat) %> <%= format_money(List.first(coin_trades).currency.cost_usd, @fiat) %> - <%= format_money(List.first(coin_trades).current_value, @fiat) %> + <%= format_money(coin_trades_current_value(coin_trades), @fiat) %> <%= format_money(coin_trades_profit_lost(coin_trades), @fiat) %> diff --git a/lib/cryptofolio/web/views/portfolio_view.ex b/lib/cryptofolio/web/views/portfolio_view.ex index b4c2ffc..3a207da 100644 --- a/lib/cryptofolio/web/views/portfolio_view.ex +++ b/lib/cryptofolio/web/views/portfolio_view.ex @@ -52,6 +52,10 @@ defmodule Cryptofolio.Web.PortfolioView do Enum.reduce(trades, Decimal.new(0), fn(trade, acc) -> Decimal.add(Trade.profit_loss(trade), acc) end) end + def coin_trades_current_value(trades) do + Decimal.mult(List.first(trades).currency.cost_usd, coin_trades_amount(trades)) + end + def coin_trades_profit_lost_perc(trades) do total_cost = coin_trades_total_cost(trades)