feat: add RUB and BRL currencies, make settings currency dropdown dynamic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { t, i18n } from '../../i18n.js'
|
||||
import { auth } from '../../services/auth.js'
|
||||
import { favoritesService } from '../../services/favorites.js'
|
||||
import { getCurrencySymbol, SUPPORTED_CURRENCIES } from '../../services/currency.js'
|
||||
|
||||
class PageSettings extends HTMLElement {
|
||||
constructor() {
|
||||
@@ -210,9 +211,11 @@ class PageSettings extends HTMLElement {
|
||||
<div class="setting-item">
|
||||
<label for="currency-select">${t('settings.currency')}</label>
|
||||
<select id="currency-select">
|
||||
<option value="USD" ${this.getCurrentCurrency() === 'USD' ? 'selected' : ''}>USD ($)</option>
|
||||
<option value="EUR" ${this.getCurrentCurrency() === 'EUR' ? 'selected' : ''}>EUR (€)</option>
|
||||
<option value="CHF" ${this.getCurrentCurrency() === 'CHF' ? 'selected' : ''}>CHF</option>
|
||||
${SUPPORTED_CURRENCIES.filter(c => c !== 'XMR').map(c => {
|
||||
const sym = getCurrencySymbol(c)
|
||||
const label = sym !== c ? `${c} (${sym})` : c
|
||||
return `<option value="${c}" ${this.getCurrentCurrency() === c ? 'selected' : ''}>${label}</option>`
|
||||
}).join('')}
|
||||
</select>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -13,7 +13,9 @@ const CURRENCY_SYMBOLS = {
|
||||
USD: '$',
|
||||
GBP: '£',
|
||||
CHF: 'CHF',
|
||||
JPY: '¥'
|
||||
JPY: '¥',
|
||||
RUB: '₽',
|
||||
BRL: 'R$'
|
||||
}
|
||||
|
||||
const CACHE_DURATION = 60 * 60 * 1000 // 60 minutes (CoinGecko free tier is strict)
|
||||
@@ -90,7 +92,7 @@ async function fetchRates() {
|
||||
lastRequestTime = Date.now()
|
||||
|
||||
try {
|
||||
const currencies = 'eur,usd,gbp,chf,jpy'
|
||||
const currencies = 'eur,usd,gbp,chf,jpy,rub,brl'
|
||||
const response = await fetch(`${COINGECKO_API}?ids=monero&vs_currencies=${currencies}`)
|
||||
|
||||
// Handle rate limit response
|
||||
@@ -111,7 +113,9 @@ async function fetchRates() {
|
||||
USD: data.monero.usd,
|
||||
GBP: data.monero.gbp,
|
||||
CHF: data.monero.chf,
|
||||
JPY: data.monero.jpy
|
||||
JPY: data.monero.jpy,
|
||||
RUB: data.monero.rub,
|
||||
BRL: data.monero.brl
|
||||
}
|
||||
|
||||
// Update cache
|
||||
@@ -135,7 +139,9 @@ function getDefaultRates() {
|
||||
USD: 165,
|
||||
GBP: 130,
|
||||
CHF: 145,
|
||||
JPY: 24000
|
||||
JPY: 24000,
|
||||
RUB: 15000,
|
||||
BRL: 850
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +272,7 @@ export function formatFiat(amount, currency) {
|
||||
}).format(amount)
|
||||
|
||||
// Symbol before or after amount
|
||||
if (['EUR', 'GBP', 'USD'].includes(currency)) {
|
||||
if (['EUR', 'GBP', 'USD', 'BRL'].includes(currency)) {
|
||||
return `${symbol} ${formatted}`
|
||||
}
|
||||
return `${formatted} ${symbol}`
|
||||
@@ -284,7 +290,7 @@ export function getCurrencySymbol(currency) {
|
||||
/**
|
||||
* List of supported currencies
|
||||
*/
|
||||
export const SUPPORTED_CURRENCIES = ['XMR', 'EUR', 'CHF', 'USD', 'GBP', 'JPY']
|
||||
export const SUPPORTED_CURRENCIES = ['XMR', 'EUR', 'CHF', 'USD', 'GBP', 'JPY', 'RUB', 'BRL']
|
||||
|
||||
export default {
|
||||
getXmrRates,
|
||||
|
||||
Reference in New Issue
Block a user