Skip to content

Commit 920a995

Browse files
authored
v0.5.2 - Currency Improvements (#82)
* Add Colombian Peso (COP) currency support - Add COP to SupportedCurrencies in currency service - Add COP option to settings currency selector - Add COP option to subscription form currency dropdown * Fix currency conversion display in subscription list The subscription list template was ignoring the enriched conversion data provided by the handler. Now displays converted cost with original currency below, matching the dashboard behavior. Fixes #79 * Fix currency display and add conversion info tooltip - Add missing BRL (R$) and CHF (Fr.) to GetCurrencySymbol switch - Apply currency conversion display to subscriptions.html template - Add info icon with tooltip linking to Fixer.io for converted amounts - Tooltip explains 'Original amount before conversion (rates from Fixer.io)'
1 parent a0152d5 commit 920a995

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
lines changed

internal/service/currency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
// SupportedCurrencies defines the list of currencies supported for exchange rates and settings
18-
var SupportedCurrencies = []string{"USD", "EUR", "GBP", "JPY", "RUB", "SEK", "PLN", "INR", "CHF", "BRL"}
18+
var SupportedCurrencies = []string{"USD", "EUR", "GBP", "JPY", "RUB", "SEK", "PLN", "INR", "CHF", "BRL", "COP"}
1919

2020
// supportedCurrencySymbols returns the currencies as a comma-separated string for API calls
2121
func supportedCurrencySymbols() string {

internal/service/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func (s *SettingsService) GetCurrencySymbol() string {
223223
return "kr"
224224
case "INR":
225225
return "₹"
226+
case "CHF":
227+
return "Fr."
228+
case "BRL":
229+
return "R$"
226230
default:
227231
return "$"
228232
}

templates/dashboard.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ <h3 class="text-sm font-medium text-gray-900 dark:text-white">{{.Name}}</h3>
284284
<div class="text-right">
285285
{{if .ShowConversion}}
286286
<p class="text-sm font-medium text-gray-900 dark:text-white">{{.DisplayCurrencySymbol}}{{printf "%.2f" .ConvertedCost}}</p>
287-
<p class="text-xs text-gray-500 dark:text-gray-400">{{.OriginalCurrency}} {{printf "%.2f" .Cost}}</p>
287+
<a href="https://fixer.io" target="_blank" rel="noopener"
288+
class="text-xs text-gray-500 dark:text-gray-400 hover:text-primary inline-flex items-center gap-1"
289+
title="Original amount before conversion (rates from Fixer.io)">
290+
{{.OriginalCurrency}} {{printf "%.2f" .Cost}}
291+
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
292+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
293+
</svg>
294+
</a>
288295
{{else}}
289296
<p class="text-sm font-medium text-gray-900 dark:text-white">{{$.CurrencySymbol}}{{printf "%.2f" .Cost}}</p>
290297
{{end}}

templates/settings.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,18 @@ <h3 class="text-base font-medium text-gray-900 dark:text-white mb-4">Currency</h
664664
class="mr-2 text-primary focus:ring-primary">
665665
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">R$ BRL (Brazilian Real)</span>
666666
</label>
667+
668+
<label class="flex items-center">
669+
<input type="radio"
670+
name="currency"
671+
value="COP"
672+
{{if eq .Currency "COP"}}checked{{end}}
673+
hx-post="/api/settings/currency"
674+
hx-trigger="change"
675+
hx-vals='{"currency": "COP"}'
676+
class="mr-2 text-primary focus:ring-primary">
677+
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">$ COP (Colombian Peso)</span>
678+
</label>
667679
</div>
668680

669681
<div id="currency-message" class="mt-2"></div>

templates/subscription-form.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ <h3 class="text-lg font-semibold text-gray-900 dark:text-white">
9090
<option value="INR" {{if .Subscription}}{{if eq .Subscription.OriginalCurrency "INR"}}selected{{end}}{{end}}>₹ INR</option>
9191
<option value="CHF" {{if .Subscription}}{{if eq .Subscription.OriginalCurrency "CHF"}}selected{{end}}{{end}}>Fr. CHF</option>
9292
<option value="BRL" {{if .Subscription}}{{if eq .Subscription.OriginalCurrency "BRL"}}selected{{end}}{{end}}>R$ BRL</option>
93+
<option value="COP" {{if .Subscription}}{{if eq .Subscription.OriginalCurrency "COP"}}selected{{end}}{{end}}>$ COP</option>
9394
</select>
9495
</div>
9596

templates/subscription-list.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,19 @@
139139
<div class="text-sm text-gray-900 dark:text-white">{{.Category.Name}}</div>
140140
</td>
141141
<td class="px-6 py-4 whitespace-nowrap">
142+
{{if .ShowConversion}}
143+
<div class="text-sm font-medium text-gray-900 dark:text-white">{{.DisplayCurrencySymbol}}{{printf "%.2f" .ConvertedCost}}</div>
144+
<a href="https://fixer.io" target="_blank" rel="noopener"
145+
class="text-xs text-gray-500 dark:text-gray-400 hover:text-primary flex items-center gap-1"
146+
title="Original amount before conversion (rates from Fixer.io)">
147+
{{.OriginalCurrency}} {{printf "%.2f" .Cost}}
148+
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
149+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
150+
</svg>
151+
</a>
152+
{{else}}
142153
<div class="text-sm font-medium text-gray-900 dark:text-white">{{$.CurrencySymbol}}{{printf "%.2f" .Cost}}</div>
154+
{{end}}
143155
</td>
144156
<td class="px-6 py-4 whitespace-nowrap">
145157
<div class="text-sm text-gray-900 dark:text-white">{{.Schedule}}</div>

templates/subscriptions.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,19 @@ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">Subscriptions</h
324324
<div class="text-sm text-gray-900 dark:text-white">{{.Category.Name}}</div>
325325
</td>
326326
<td class="px-6 py-4 whitespace-nowrap">
327+
{{if .ShowConversion}}
328+
<div class="text-sm font-medium text-gray-900 dark:text-white">{{.DisplayCurrencySymbol}}{{printf "%.2f" .ConvertedCost}}</div>
329+
<a href="https://fixer.io" target="_blank" rel="noopener"
330+
class="text-xs text-gray-500 dark:text-gray-400 hover:text-primary flex items-center gap-1"
331+
title="Original amount before conversion (rates from Fixer.io)">
332+
{{.OriginalCurrency}} {{printf "%.2f" .Cost}}
333+
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
334+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
335+
</svg>
336+
</a>
337+
{{else}}
327338
<div class="text-sm font-medium text-gray-900 dark:text-white">{{$.CurrencySymbol}}{{printf "%.2f" .Cost}}</div>
339+
{{end}}
328340
</td>
329341
<td class="px-6 py-4 whitespace-nowrap">
330342
<div class="text-sm text-gray-900 dark:text-white">{{.Schedule}}</div>

0 commit comments

Comments
 (0)