-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathcurrency.js
46 lines (40 loc) · 1.8 KB
/
currency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const dataManager = require('./data_manager').default;
const CurrencyBase = require('../../_common/base/currency_base');
const localize = require('../../_common/localize').localize;
const getCurrencyFullName = (currency) => CurrencyBase.isCryptocurrency(currency) ? `${CurrencyBase.getCurrencyName(currency)} (${CurrencyBase.getCurrencyDisplayCode(currency)})` : currency;
const getCurrencyList = (currencies) => {
const currency_list = {
fiat : [],
crypto: [],
};
const $currencies = $('<select/>');
const $fiat_currencies = $('<optgroup/>', { label: localize('Fiat') });
const $cryptocurrencies = $('<optgroup/>', { label: localize('Crypto') });
currencies.forEach((currency) => {
const currency_name = getCurrencyFullName(currency);
(CurrencyBase.isCryptocurrency(currency) ? $cryptocurrencies : $fiat_currencies)
.append($('<option/>', { value: currency, text: currency_name }));
if (CurrencyBase.isCryptocurrency(currency)) {
currency_list.crypto.push({ value: currency, text: currency_name });
} else {
currency_list.fiat.push({ value: currency, text: currency_name });
}
});
dataManager.setTrade({
currency_list,
});
return $currencies.append($fiat_currencies.children().length ? $fiat_currencies : '').append($cryptocurrencies.children().length ? $cryptocurrencies : '');
};
const getCurrencyNameList = (currencies) => {
const currencies_name_list = [];
currencies.forEach((currency) => {
const currency_name = getCurrencyFullName(currency);
currencies_name_list.push(currency_name);
});
return currencies_name_list;
};
module.exports = Object.assign({
getCurrencyList,
getCurrencyNameList,
getCurrencyFullName,
}, CurrencyBase);