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