From 3ceb7f219ae46216a2067837e18b0c9245ec848a Mon Sep 17 00:00:00 2001 From: padreug Date: Sun, 10 Aug 2025 19:25:08 +0200 Subject: [PATCH] feat: Format currency display to ensure two-digit representation - Update CurrencyDisplay.vue to use formattedCurrency for gold, silver, and copper values, ensuring consistent two-digit formatting. - Modify formatEverQuestCurrency function in currency.ts to pad currency values with leading zeros, enhancing visual consistency in currency representation. --- src/components/ui/CurrencyDisplay.vue | 16 +++++++++++++--- src/lib/utils/currency.ts | 8 ++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/ui/CurrencyDisplay.vue b/src/components/ui/CurrencyDisplay.vue index 642b060..556f09e 100644 --- a/src/components/ui/CurrencyDisplay.vue +++ b/src/components/ui/CurrencyDisplay.vue @@ -9,19 +9,19 @@
- {{ currency.gold }} + {{ formattedCurrency.gold }}
- {{ currency.silver }} + {{ formattedCurrency.silver }}
- {{ currency.copper }} + {{ formattedCurrency.copper }}
@@ -40,4 +40,14 @@ const currency = computed(() => { const satoshis = Math.floor(props.balanceMsat / 1000) return satoshisToEverQuest(satoshis) }) + +// Format currency values to always show 2 digits with leading zeros +const formattedCurrency = computed(() => { + return { + platinum: currency.value.platinum, + gold: currency.value.gold.toString().padStart(2, '0'), + silver: currency.value.silver.toString().padStart(2, '0'), + copper: currency.value.copper.toString().padStart(2, '0') + } +}) diff --git a/src/lib/utils/currency.ts b/src/lib/utils/currency.ts index b889ec2..89b0a76 100644 --- a/src/lib/utils/currency.ts +++ b/src/lib/utils/currency.ts @@ -43,20 +43,20 @@ export function formatEverQuestCurrency(currency: EverQuestCurrency): string { } if (currency.gold > 0) { - parts.push(`${currency.gold}g`) + parts.push(`${currency.gold.toString().padStart(2, '0')}g`) } if (currency.silver > 0) { - parts.push(`${currency.silver}s`) + parts.push(`${currency.silver.toString().padStart(2, '0')}s`) } if (currency.copper > 0) { - parts.push(`${currency.copper}c`) + parts.push(`${currency.copper.toString().padStart(2, '0')}c`) } // If no currency, show 0c if (parts.length === 0) { - return '0c' + return '00c' } return parts.join(' ')