Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
2.6 KB
Raw Blame
<%= turbo_frame_tag dom_id(@account, "holdings") do %>
  <div class="bg-container space-y-4 px-3 py-4 lg:p-4 rounded-xl shadow-border-xs">
    <div class="flex items-center justify-between">
      <%= tag.h2 t(".holdings"), class: "font-medium text-lg" %>
      <%= link_to new_trade_path(account_id: @account.id),
                  id: dom_id(@account, "new_trade"),
                  data: { turbo_frame: :modal },
                  class: "flex gap-1 font-medium items-center button-bg-secondary hover:button-bg-secondary-hover text-primary p-2 rounded-lg" do %>
        <span class="text-primary">
          <%= icon("plus", color: "current") %>
        </span>
        <%= tag.span t(".new_holding"), class: "text-sm" %>
      <% end %>
    </div>

    <% if @trade_republic_categories.present? %>
      <div class="grid gap-2 sm:grid-cols-2 lg:grid-cols-4">
        <% @trade_republic_categories.each do |category, summary| %>
          <div class="rounded-lg border border-secondary bg-container-inset px-3 py-2">
            <p class="text-xs text-secondary"><%= t("trade_republic_items.portfolio_categories.#{category}") %></p>
            <p class="text-sm font-medium text-primary"><%= t(".positions", count: summary[:count]) %></p>
            <p class="text-xs text-secondary"><%= format_money Money.new(summary[:value].round(2), @account.currency) %></p>
          </div>
        <% end %>
      </div>
    <% end %>

    <div class="bg-container-inset rounded-xl p-1 overflow-x-auto">
      <div class="w-max lg:w-full">
        <div class="grid grid-cols-12 items-center uppercase text-xs font-medium text-secondary px-4 py-2">
          <%= tag.p t(".name"), class: "col-span-4" %>
          <%= tag.p t(".weight"), class: "col-span-2 justify-self-end" %>
          <%= tag.p t(".average_cost"), class: "col-span-2 justify-self-end" %>
          <%= tag.p t(".holdings"), class: "col-span-2 justify-self-end" %>
          <%= tag.p t(".return"), class: "col-span-2 justify-self-end" %>
        </div>

        <div class="bg-container rounded-lg shadow-border-xs">
          <% if @account.cash_balance.to_d > 0 %>
            <%= render "holdings/cash", account: @account %>
            <%= render "shared/ruler" %>
          <% end %>

          <% if @current_holdings.any? %>
            <% @current_holdings.each_with_index do |holding, index| %>
              <%= render "holdings/holding", holding: holding, crypto: @account.crypto? %>
              <%= render "shared/ruler" unless index == @current_holdings.length - 1 %>
            <% end %>
          <% end %>
        </div>
      </div>
    </div>
  </div>
<% end %>