mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
ADD: Added more Fiat currencies
This commit is contained in:
parent
1c61b4d9b7
commit
854139d88b
17
currency.js
17
currency.js
@ -30,11 +30,11 @@ async function updateExchangeRate() {
|
||||
let json;
|
||||
try {
|
||||
const api = new Frisbee({
|
||||
baseURI: 'https://www.bitstamp.net',
|
||||
baseURI: 'https://api.coindesk.com',
|
||||
});
|
||||
let response = await api.get('/api/v2/ticker/' + preferredFiatCurrency.endPointKey);
|
||||
let response = await api.get('/v1/bpi/currentprice/' + preferredFiatCurrency.endPointKey + '.json');
|
||||
json = response.body;
|
||||
if (typeof json === 'undefined' || typeof json.last === 'undefined') {
|
||||
if (typeof json === 'undefined' || typeof json.bpi[preferredFiatCurrency.endPointKey].rate_foat === 'undefined') {
|
||||
throw new Error('Could not update currency rate: ' + response.err);
|
||||
}
|
||||
} catch (Err) {
|
||||
@ -43,7 +43,8 @@ async function updateExchangeRate() {
|
||||
}
|
||||
|
||||
lang[STRUCT.LAST_UPDATED] = +new Date();
|
||||
lang[STRUCT[preferredFiatCurrency.storageKey]] = json.last * 1;
|
||||
lang[STRUCT[preferredFiatCurrency['BTC_' + preferredFiatCurrency.endPointKey]]] =
|
||||
json.bpi[preferredFiatCurrency.endPointKey].rate_foat * 1;
|
||||
await AsyncStorage.setItem(AppStorage.CURRENCY, JSON.stringify(lang));
|
||||
}
|
||||
|
||||
@ -69,24 +70,24 @@ async function startUpdater(force = false) {
|
||||
}
|
||||
lang = lang || {};
|
||||
lang[STRUCT.LAST_UPDATED] = lang[STRUCT.LAST_UPDATED] || 0;
|
||||
lang[STRUCT[preferredFiatCurrency.storageKey]] = lang[STRUCT[preferredFiatCurrency.storageKey]] || 6500;
|
||||
lang[STRUCT['BTC_' + preferredFiatCurrency.endPointKey]] = lang[STRUCT['BTC_' + preferredFiatCurrency.endPointKey]] || 6500;
|
||||
setInterval(() => updateExchangeRate(), 2 * 60 * 100);
|
||||
return updateExchangeRate();
|
||||
}
|
||||
|
||||
function satoshiToLocalCurrency(satoshi) {
|
||||
if (!lang[STRUCT[preferredFiatCurrency.storageKey]]) return satoshi;
|
||||
if (!lang[STRUCT['BTC_' + preferredFiatCurrency.endPointKey]]) return satoshi;
|
||||
|
||||
let b = new BigNumber(satoshi);
|
||||
b = b
|
||||
.dividedBy(100000000)
|
||||
.multipliedBy(lang[STRUCT[preferredFiatCurrency.storageKey]])
|
||||
.multipliedBy(lang[STRUCT['BTC_' + preferredFiatCurrency.endPointKey]])
|
||||
.toString(10);
|
||||
b = parseFloat(b).toFixed(2);
|
||||
|
||||
const formatter = new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: preferredFiatCurrency.formatterValue,
|
||||
currency: preferredFiatCurrency.endPointKey,
|
||||
minimumFractionDigits: 2,
|
||||
});
|
||||
return formatter.format(b);
|
||||
|
@ -1,4 +1,168 @@
|
||||
export const FiatUnit = Object.freeze({
|
||||
USD: { endPointKey: 'btcusd', storageKey: 'BTC_USD', formatterValue: 'USD', symbol: '$' },
|
||||
EUR: { endPointKey: 'btceur', storageKey: 'BTC_EUR', formatterValue: 'EUR', symbol: '€' },
|
||||
USD: { endPointKey: 'USD', symbol: '$' },
|
||||
EUR: { endPointKey: 'EUR', symbol: '€' },
|
||||
AED: { endPointKey: 'AED', symbol: 'د.إ' },
|
||||
AFN: { endPointKey: 'AFN', symbol: '؋' },
|
||||
ALL: { endPointKey: 'ALL', symbol: 'L' },
|
||||
AMD: { endPointKey: 'AMD', symbol: '֏' },
|
||||
ANG: { endPointKey: 'ANG', symbol: 'ƒ' },
|
||||
AOA: { endPointKey: 'AOA', symbol: 'Kz' },
|
||||
ARS: { endPointKey: 'ARS', symbol: '$' },
|
||||
AUD: { endPointKey: 'AUD', symbol: '$' },
|
||||
AWG: { endPointKey: 'AWG', symbol: 'ƒ' },
|
||||
AZN: { endPointKey: 'AZN', symbol: '₼' },
|
||||
BAM: { endPointKey: 'BAM', symbol: 'KM' },
|
||||
BBD: { endPointKey: 'BBD', symbol: '$' },
|
||||
BDT: { endPointKey: 'BDT', symbol: '৳' },
|
||||
BGN: { endPointKey: 'BGN', symbol: 'лв' },
|
||||
BHD: { endPointKey: 'BHD', symbol: '.د.ب' },
|
||||
BIF: { endPointKey: 'BIF', symbol: 'FBu' },
|
||||
BMD: { endPointKey: 'BMD', symbol: '$' },
|
||||
BND: { endPointKey: 'BND', symbol: '$' },
|
||||
BOB: { endPointKey: 'BOB', symbol: '$b' },
|
||||
BRL: { endPointKey: 'BRL', symbol: 'R$' },
|
||||
BSD: { endPointKey: 'BSD', symbol: '$' },
|
||||
BTN: { endPointKey: 'BTN', symbol: 'Nu.' },
|
||||
BWP: { endPointKey: 'BWP', symbol: 'P' },
|
||||
BYR: { endPointKey: 'BYR', symbol: 'Br' },
|
||||
// { endPointKey: 'BZD', symbol: 'Belize Dollar' },
|
||||
// { endPointKey: 'CAD', symbol: 'Canadian Dollar' },
|
||||
// { endPointKey: 'CDF', symbol: 'Congolese Franc' },
|
||||
// { endPointKey: 'CHF', symbol: 'Swiss Franc' },
|
||||
// { endPointKey: 'CLF', symbol: 'Chilean Unit of Account (UF)' },
|
||||
// { endPointKey: 'CLP', symbol: 'Chilean Peso' },
|
||||
// { endPointKey: 'CNY', symbol: 'Chinese Yuan' },
|
||||
// { endPointKey: 'COP', symbol: 'Colombian Peso' },
|
||||
// { endPointKey: 'CRC', symbol: 'Costa Rican Col\u00f3n' },
|
||||
// { endPointKey: 'CUP', symbol: 'Cuban Peso' },
|
||||
// { endPointKey: 'CVE', symbol: 'Cape Verdean Escudo' },
|
||||
// { endPointKey: 'CZK', symbol: 'Czech Republic Koruna' },
|
||||
// { endPointKey: 'DJF', symbol: 'Djiboutian Franc' },
|
||||
// { endPointKey: 'DKK', symbol: 'Danish Krone' },
|
||||
// { endPointKey: 'DOP', symbol: 'Dominican Peso' },
|
||||
// { endPointKey: 'DZD', symbol: 'Algerian Dinar' },
|
||||
// { endPointKey: 'EEK', symbol: 'Estonian Kroon' },
|
||||
// { endPointKey: 'EGP', symbol: 'Egyptian Pound' },
|
||||
// { endPointKey: 'ERN', symbol: 'Eritrean Nnakfa' },
|
||||
// { endPointKey: 'ETB', symbol: 'Ethiopian Birr' },
|
||||
// { endPointKey: 'FJD', symbol: 'Fijian Dollar' },
|
||||
// { endPointKey: 'FKP', symbol: 'Falkland Islands Pound' },
|
||||
// { endPointKey: 'GBP', symbol: 'British Pound Sterling' },
|
||||
// { endPointKey: 'GEL', symbol: 'Georgian Lari' },
|
||||
// { endPointKey: 'GHS', symbol: 'Ghanaian Cedi' },
|
||||
// { endPointKey: 'GIP', symbol: 'Gibraltar Pound' },
|
||||
// { endPointKey: 'GMD', symbol: 'Gambian Dalasi' },
|
||||
// { endPointKey: 'GNF', symbol: 'Guinean Franc' },
|
||||
// { endPointKey: 'GTQ', symbol: 'Guatemalan Quetzal' },
|
||||
// { endPointKey: 'GYD', symbol: 'Guyanaese Dollar' },
|
||||
// { endPointKey: 'HKD', symbol: 'Hong Kong Dollar' },
|
||||
// { endPointKey: 'HNL', symbol: 'Honduran Lempira' },
|
||||
// { endPointKey: 'HRK', symbol: 'Croatian Kuna' },
|
||||
// { endPointKey: 'HTG', symbol: 'Haitian Gourde' },
|
||||
// { endPointKey: 'HUF', symbol: 'Hungarian Forint' },
|
||||
// { endPointKey: 'IDR', symbol: 'Indonesian Rupiah' },
|
||||
// { endPointKey: 'ILS', symbol: 'Israeli New Sheqel' },
|
||||
// { endPointKey: 'INR', symbol: 'Indian Rupee' },
|
||||
// { endPointKey: 'IQD', symbol: 'Iraqi Dinar' },
|
||||
// { endPointKey: 'IRR', symbol: 'Iranian Rial' },
|
||||
// { endPointKey: 'ISK', symbol: 'Icelandic Kr\u00f3na' },
|
||||
// { endPointKey: 'JEP', symbol: 'Jersey Pound' },
|
||||
// { endPointKey: 'JMD', symbol: 'Jamaican Dollar' },
|
||||
// { endPointKey: 'JOD', symbol: 'Jordanian Dinar' },
|
||||
// { endPointKey: 'JPY', symbol: 'Japanese Yen' },
|
||||
// { endPointKey: 'KES', symbol: 'Kenyan Shilling' },
|
||||
// { endPointKey: 'KGS', symbol: 'Kyrgystani Som' },
|
||||
// { endPointKey: 'KHR', symbol: 'Cambodian Riel' },
|
||||
// { endPointKey: 'KMF', symbol: 'Comorian Franc' },
|
||||
// { endPointKey: 'KPW', symbol: 'North Korean Won' },
|
||||
// { endPointKey: 'KRW', symbol: 'South Korean Won' },
|
||||
// { endPointKey: 'KWD', symbol: 'Kuwaiti Dinar' },
|
||||
// { endPointKey: 'KYD', symbol: 'Cayman Islands Dollar' },
|
||||
// { endPointKey: 'KZT', symbol: 'Kazakhstani Tenge' },
|
||||
// { endPointKey: 'LAK', symbol: 'Laotian Kip' },
|
||||
// { endPointKey: 'LBP', symbol: 'Lebanese Pound' },
|
||||
// { endPointKey: 'LKR', symbol: 'Sri Lankan Rupee' },
|
||||
// { endPointKey: 'LRD', symbol: 'Liberian Dollar' },
|
||||
// { endPointKey: 'LSL', symbol: 'Lesotho Loti' },
|
||||
// { endPointKey: 'LTL', symbol: 'Lithuanian Litas' },
|
||||
// { endPointKey: 'LVL', symbol: 'Latvian Lats' },
|
||||
// { endPointKey: 'LYD', symbol: 'Libyan Dinar' },
|
||||
// { endPointKey: 'MAD', symbol: 'Moroccan Dirham' },
|
||||
// { endPointKey: 'MDL', symbol: 'Moldovan Leu' },
|
||||
// { endPointKey: 'MGA', symbol: 'Malagasy Ariary' },
|
||||
// { endPointKey: 'MKD', symbol: 'Macedonian Denar' },
|
||||
// { endPointKey: 'MMK', symbol: 'Myanma Kyat' },
|
||||
// { endPointKey: 'MNT', symbol: 'Mongolian Tugrik' },
|
||||
// { endPointKey: 'MOP', symbol: 'Macanese Pataca' },
|
||||
// { endPointKey: 'MRO', symbol: 'Mauritanian Ouguiya' },
|
||||
// { endPointKey: 'MTL', symbol: 'Maltese Lira' },
|
||||
// { endPointKey: 'MUR', symbol: 'Mauritian Rupee' },
|
||||
// { endPointKey: 'MVR', symbol: 'Maldivian Rufiyaa' },
|
||||
// { endPointKey: 'MWK', symbol: 'Malawian Kwacha' },
|
||||
// { endPointKey: 'MXN', symbol: 'Mexican Peso' },
|
||||
// { endPointKey: 'MYR', symbol: 'Malaysian Ringgit' },
|
||||
// { endPointKey: 'MZN', symbol: 'Mozambican Metical' },
|
||||
// { endPointKey: 'NAD', symbol: 'Namibian Dollar' },
|
||||
// { endPointKey: 'NGN', symbol: 'Nigerian Naira' },
|
||||
// { endPointKey: 'NIO', symbol: 'Nicaraguan C\u00f3rdoba' },
|
||||
// { endPointKey: 'NOK', symbol: 'Norwegian Krone' },
|
||||
// { endPointKey: 'NPR', symbol: 'Nepalese Rupee' },
|
||||
// { endPointKey: 'NZD', symbol: 'New Zealand Dollar' },
|
||||
// { endPointKey: 'OMR', symbol: 'Omani Rial' },
|
||||
// { endPointKey: 'PAB', symbol: 'Panamanian Balboa' },
|
||||
// { endPointKey: 'PEN', symbol: 'Peruvian Nuevo Sol' },
|
||||
// { endPointKey: 'PGK', symbol: 'Papua New Guinean Kina' },
|
||||
// { endPointKey: 'PHP', symbol: 'Philippine Peso' },
|
||||
// { endPointKey: 'PKR', symbol: 'Pakistani Rupee' },
|
||||
// { endPointKey: 'PLN', symbol: 'Polish Zloty' },
|
||||
// { endPointKey: 'PYG', symbol: 'Paraguayan Guarani' },
|
||||
// { endPointKey: 'QAR', symbol: 'Qatari Rial' },
|
||||
// { endPointKey: 'RON', symbol: 'Romanian Leu' },
|
||||
// { endPointKey: 'RSD', symbol: 'Serbian Dinar' },
|
||||
// { endPointKey: 'RUB', symbol: 'Russian Ruble' },
|
||||
// { endPointKey: 'RWF', symbol: 'Rwandan Franc' },
|
||||
// { endPointKey: 'SAR', symbol: 'Saudi Riyal' },
|
||||
// { endPointKey: 'SBD', symbol: 'Solomon Islands Dollar' },
|
||||
// { endPointKey: 'SCR', symbol: 'Seychellois Rupee' },
|
||||
// { endPointKey: 'SDG', symbol: 'Sudanese Pound' },
|
||||
// { endPointKey: 'SEK', symbol: 'Swedish Krona' },
|
||||
// { endPointKey: 'SGD', symbol: 'Singapore Dollar' },
|
||||
// { endPointKey: 'SHP', symbol: 'Saint Helena Pound' },
|
||||
// { endPointKey: 'SLL', symbol: 'Sierra Leonean Leone' },
|
||||
// { endPointKey: 'SOS', symbol: 'Somali Shilling' },
|
||||
// { endPointKey: 'SRD', symbol: 'Surinamese Dollar' },
|
||||
// { endPointKey: 'STD', symbol: 'S\u00e3o Tom\u00e9 and Pr\u00edncipe Dobra' },
|
||||
// { endPointKey: 'SVC', symbol: 'Salvadoran Col\u00f3n' },
|
||||
// { endPointKey: 'SYP', symbol: 'Syrian Pound' },
|
||||
// { endPointKey: 'SZL', symbol: 'Swazi Lilangeni' },
|
||||
// { endPointKey: 'THB', symbol: 'Thai Baht' },
|
||||
// { endPointKey: 'TJS', symbol: 'Tajikistani Somoni' },
|
||||
// { endPointKey: 'TMT', symbol: 'Turkmenistani Manat' },
|
||||
// { endPointKey: 'TND', symbol: 'Tunisian Dinar' },
|
||||
// { endPointKey: 'TOP', symbol: 'Tongan Pa?anga' },
|
||||
// { endPointKey: 'TRY', symbol: 'Turkish Lira' },
|
||||
// { endPointKey: 'TTD', symbol: 'Trinidad and Tobago Dollar' },
|
||||
// { endPointKey: 'TWD', symbol: 'New Taiwan Dollar' },
|
||||
// { endPointKey: 'TZS', symbol: 'Tanzanian Shilling' },
|
||||
// { endPointKey: 'UAH', symbol: 'Ukrainian Hryvnia' },
|
||||
// { endPointKey: 'UGX', symbol: 'Ugandan Shilling' },
|
||||
// { endPointKey: 'UYU', symbol: 'Uruguayan Peso' },
|
||||
// { endPointKey: 'UZS', symbol: 'Uzbekistan Som' },
|
||||
// { endPointKey: 'VEF', symbol: 'Venezuelan Bol\u00edvar Fuerte' },
|
||||
// { endPointKey: 'VND', symbol: 'Vietnamese Dong' },
|
||||
// { endPointKey: 'VUV', symbol: 'Vanuatu Vatu' },
|
||||
// { endPointKey: 'WST', symbol: 'Samoan Tala' },
|
||||
// { endPointKey: 'XAF', symbol: 'CFA Franc BEAC' },
|
||||
// { endPointKey: 'XAG', symbol: 'Silver (troy ounce)' },
|
||||
// { endPointKey: 'XAU', symbol: 'Gold (troy ounce)' },
|
||||
// { endPointKey: 'XBT', symbol: 'Bitcoin' },
|
||||
// { endPointKey: 'XCD', symbol: 'East Caribbean Dollar' },
|
||||
// { endPointKey: 'XDR', symbol: 'Special Drawing Rights' },
|
||||
// { endPointKey: 'XOF', symbol: 'CFA Franc BCEAO' },
|
||||
// { endPointKey: 'XPF', symbol: 'CFP Franc' },
|
||||
// { endPointKey: 'YER', symbol: 'Yemeni Rial' },
|
||||
// { endPointKey: 'ZAR', symbol: 'South African Rand' },
|
||||
// { endPointKey: 'ZMK', symbol: 'Zambian Kwacha (pre-2013)' },
|
||||
// { endPointKey: 'ZMW', symbol: 'Zambian Kwacha' },
|
||||
// { endPointKey: 'ZWL', symbol: 'Zimbabwean Dollar' },
|
||||
});
|
||||
|
@ -44,8 +44,8 @@ export default class Currency extends Component {
|
||||
}}
|
||||
>
|
||||
<BlueListItem
|
||||
title={item.symbol + ' ' + item.formatterValue}
|
||||
{...(this.state.selectedCurrency.formatterValue === item.formatterValue
|
||||
title={item.symbol + ' ' + item.endPointKey}
|
||||
{...(this.state.selectedCurrency.endPointKey === item.endPointKey
|
||||
? {
|
||||
rightIcon: this.state.selectedNewCurrency ? (
|
||||
<ActivityIndicator />
|
||||
|
Loading…
Reference in New Issue
Block a user