feat: Add wallet balance display and currency formatting

- Implement wallet balance computation and formatting in Navbar.vue, enhancing user experience by displaying wallet balance in both the main navigation and dropdown menu.
- Introduce currency conversion utilities in currency.ts to format wallet balances into EverQuest currency denominations, improving clarity for users.
This commit is contained in:
padreug 2025-08-01 23:49:39 +02:00
parent c959cf8101
commit 4cf2b769d6
2 changed files with 110 additions and 1 deletions

76
src/lib/utils/currency.ts Normal file
View file

@ -0,0 +1,76 @@
/**
* EverQuest Currency Conversion
* 1 sat = 1 copper
* 100 copper = 1 silver
* 100 silver = 1 gold
* 100 gold = 1 platinum
*/
export interface EverQuestCurrency {
platinum: number
gold: number
silver: number
copper: number
}
export function satoshisToEverQuest(satoshis: number): EverQuestCurrency {
// Convert satoshis to copper (1 sat = 1 copper)
let copper = satoshis
// Convert to higher denominations
const platinum = Math.floor(copper / 1000000) // 100 gold = 1 platinum
copper %= 1000000
const gold = Math.floor(copper / 10000) // 100 silver = 1 gold
copper %= 10000
const silver = Math.floor(copper / 100) // 100 copper = 1 silver
copper %= 100
return {
platinum,
gold,
silver,
copper
}
}
export function formatEverQuestCurrency(currency: EverQuestCurrency): string {
const parts: string[] = []
if (currency.platinum > 0) {
parts.push(`${currency.platinum}p`)
}
if (currency.gold > 0) {
parts.push(`${currency.gold}g`)
}
if (currency.silver > 0) {
parts.push(`${currency.silver}s`)
}
if (currency.copper > 0) {
parts.push(`${currency.copper}c`)
}
// If no currency, show 0c
if (parts.length === 0) {
return '0c'
}
return parts.join(' ')
}
export function formatWalletBalance(balanceMsat: number): string {
// Convert msat to satoshis (1 sat = 1000 msat)
const satoshis = Math.floor(balanceMsat / 1000)
const currency = satoshisToEverQuest(satoshis)
return formatEverQuestCurrency(currency)
}
// Test examples:
// 100 sat = 1s (1 silver)
// 10000 sat = 1g (1 gold)
// 1000000 sat = 1p (1 platinum)
// 1234567 sat = 1p 2g 3s 4c