Adapt holdings to number inputs (#1258)

* Adapt holdings to number inputs

* Reviews

* FIX a small provider hardcoded name

* PR l10n request

---------

Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
soky srm
2026-03-23 18:27:53 +01:00
committed by GitHub
parent 20f279875e
commit c7b9bc48bc
18 changed files with 131 additions and 16 deletions

View File

@@ -1,9 +1,22 @@
// Parses a float from a string that may use either commas or dots as decimal separators.
// Handles formats like "1,234.56" (English) and "1.234,56" (French/European).
export default function parseLocaleFloat(value) {
//
// When a `separator` hint is provided (e.g., from currency metadata), parsing is
// deterministic. Without a hint, a heuristic detects the format from the string.
export default function parseLocaleFloat(value, { separator } = {}) {
if (typeof value !== "string") return Number.parseFloat(value) || 0
const cleaned = value.replace(/\s/g, "")
// Deterministic parsing when the currency's decimal separator is known
if (separator === ",") {
return Number.parseFloat(cleaned.replace(/\./g, "").replace(",", ".")) || 0
}
if (separator === ".") {
return Number.parseFloat(cleaned.replace(/,/g, "")) || 0
}
// Heuristic: detect separator from the string when no hint is available
const lastComma = cleaned.lastIndexOf(",")
const lastDot = cleaned.lastIndexOf(".")

View File

@@ -61,12 +61,12 @@
<label class="form-field__label"><%= t(".total_cost_basis_label") %></label>
<div class="flex items-center gap-1">
<span class="text-secondary text-sm font-medium"><%= currency.symbol %></span>
<input type="text" inputmode="decimal"
<input type="number" step="any"
name="holding[cost_basis]"
class="form-field__input grow"
placeholder="0.00"
autocomplete="off"
value="<%= number_with_precision(current_total, precision: 2) if current_total %>"
value="<%= sprintf("%.2f", current_total) if current_total %>"
data-action="input->cost-basis-form#updatePerShare"
data-cost-basis-form-target="total">
<span class="text-secondary text-sm"><%= currency.iso_code %></span>
@@ -82,11 +82,11 @@
<label class="text-xs text-secondary block mb-1"><%= t(".or_per_share_label") %></label>
<div class="flex items-center gap-1">
<span class="text-secondary text-sm font-medium"><%= currency.symbol %></span>
<input type="text" inputmode="decimal"
<input type="number" step="any"
class="form-field__input grow"
placeholder="0.00"
autocomplete="off"
value="<%= number_with_precision(current_per_share, precision: 2) if current_per_share %>"
value="<%= sprintf("%.2f", current_per_share) if current_per_share %>"
data-action="input->cost-basis-form#updateTotal"
data-cost-basis-form-target="perShare">
<span class="text-secondary text-sm"><%= currency.iso_code %></span>

View File

@@ -133,12 +133,12 @@
<label class="form-field__label"><%= t("holdings.cost_basis_cell.total_cost_basis_label") %></label>
<div class="flex items-center gap-1">
<span class="text-secondary text-sm font-medium"><%= currency.symbol %></span>
<input type="text" inputmode="decimal"
<input type="number" step="any"
name="holding[cost_basis]"
class="form-field__input grow"
placeholder="0.00"
autocomplete="off"
value="<%= number_with_precision(current_total, precision: 2) if current_total %>"
value="<%= sprintf("%.2f", current_total) if current_total %>"
data-action="input->drawer-cost-basis#updatePerShare"
data-drawer-cost-basis-target="total">
<span class="text-secondary text-sm"><%= currency.iso_code %></span>
@@ -153,11 +153,11 @@
<label class="text-xs text-secondary block mb-1"><%= t("holdings.cost_basis_cell.or_per_share_label") %></label>
<div class="flex items-center gap-1">
<span class="text-secondary text-sm font-medium"><%= currency.symbol %></span>
<input type="text" inputmode="decimal"
<input type="number" step="any"
class="form-field__input grow"
placeholder="0.00"
autocomplete="off"
value="<%= number_with_precision(current_per_share, precision: 2) if current_per_share %>"
value="<%= sprintf("%.2f", current_per_share) if current_per_share %>"
data-action="input->drawer-cost-basis#updateTotal"
data-drawer-cost-basis-target="perShare">
<span class="text-secondary text-sm"><%= currency.iso_code %></span>

View File

@@ -18,7 +18,7 @@
</h3>
<% if entry.linked? %>
<span title="Linked with Plaid">
<span title="<%= t("transactions.transaction.linked_with_provider", provider: entry.account.provider_name&.titleize) %>">
<%= icon("refresh-ccw", size: "sm") %>
</span>
<% end %>

View File

@@ -12,7 +12,7 @@
<%= icon "arrow-left-right", size: "sm", class: "text-secondary" %>
<% end %>
<% if entry.linked? %>
<span title="<%= t("transactions.transaction.linked_with_plaid") %>" class="text-secondary">
<span title="<%= t("transactions.transaction.linked_with_provider", provider: entry.account.provider_name&.titleize) %>" class="text-secondary">
<%= icon("refresh-ccw", size: "sm") %>
</span>
<% end %>