The personal finance app for everyone (by everyone)
Ruby
<% content_for :title, t(".title") %>
<%= render DS::Dialog.new do |dialog| %>
<% dialog.with_header(title: t(".title")) do %>
<div class="flex items-center gap-2">
<%= icon "waves", class: "text-primary" %>
<span class="text-primary"><%= t(".subtitle") %></span>
</div>
<% end %>
<% dialog.with_body do %>
<%= form_with url: complete_account_setup_kraken_item_path(@kraken_item),
method: :post,
local: true,
id: "kraken-setup-form",
data: {
controller: "loading-button",
action: "submit->loading-button#showLoading",
loading_button_loading_text_value: t(".creating"),
turbo_frame: "_top"
},
class: "space-y-6" do |form| %>
<div class="space-y-4">
<div class="bg-surface border border-primary p-4 rounded-lg">
<div class="flex items-start gap-3">
<%= icon "info", size: "sm", class: "text-primary mt-0.5 flex-shrink-0" %>
<p class="text-sm text-primary"><%= t(".instructions") %></p>
</div>
</div>
<% if @kraken_accounts.empty? %>
<div class="text-center py-8">
<p class="text-secondary"><%= t(".no_accounts") %></p>
</div>
<% else %>
<div data-controller="select-all">
<div class="flex items-center justify-between mb-2">
<span class="text-sm text-secondary">
<%= t(".accounts_count", count: @kraken_accounts.count) %>
</span>
<label class="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox"
id="kraken-select-all"
data-action="change->select-all#toggle"
class="checkbox checkbox--dark">
<span class="text-secondary"><%= t(".select_all") %></span>
</label>
</div>
<div class="space-y-2 max-h-96 overflow-y-auto">
<% @kraken_accounts.each do |kraken_account| %>
<label for="ka_<%= kraken_account.id %>" class="flex items-center gap-3 p-3 border border-primary rounded-lg hover:bg-surface transition-colors cursor-pointer">
<%= check_box_tag "selected_accounts[]",
kraken_account.id,
false,
id: "ka_#{kraken_account.id}",
class: "checkbox checkbox--dark",
data: { select_all_target: "checkbox" } %>
<div class="flex-1 min-w-0">
<p class="font-medium text-primary truncate"><%= kraken_account.name %></p>
<p class="text-xs text-secondary"><%= kraken_account.account_type %></p>
</div>
<%# Kraken reports in USD. Show the figure in the currency the account
will actually be created in, which is the one every other number
on the screen is in. With no rate the account opens at zero
(Account.convert_provider_balance), so that is what is shown:
the reported figure would promise a balance the account will
not have. %>
<% reported = Money.new(kraken_account.current_balance || 0, kraken_account.currency)
display = begin
reported.exchange_to(Current.family.currency)
rescue Money::ConversionError
Money.new(0, Current.family.currency)
end %>
<div class="text-right flex-shrink-0">
<p class="text-sm font-medium text-primary"><%= format_money(display) %></p>
<p class="text-xs text-secondary"><%= display.currency.iso_code %></p>
</div>
</label>
<% end %>
</div>
</div>
<% end %>
</div>
<div class="flex gap-3">
<%= render DS::Button.new(
text: t(".import_selected"),
variant: "primary",
icon: "plus",
type: "submit",
class: "flex-1",
data: { loading_button_target: "button" }
) %>
<%= render DS::Link.new(text: t(".cancel"), variant: "secondary", href: accounts_path) %>
</div>
<% end %>
<% end %>
<% end %>