Skip to content

Commit 4282ccb

Browse files
committed
Add secondary currency
1 parent fa54efc commit 4282ccb

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

css/app.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ ul {
182182
}
183183
.coin-list .block {
184184
display: inline-block;
185-
vertical-align: top;
185+
vertical-align: middle;
186186
}
187187
.coin-list .block label {
188188
font-size: 12px;
@@ -274,7 +274,7 @@ ul {
274274
padding: 2px 3px 2px;
275275
font-size: 14px;
276276
float: right;
277-
margin: 10px 0px 0px;
277+
margin: 28px 0px;
278278
background: #000;
279279
}
280280
.coin-list li .change.positive {

index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ <h3>Choose Your Base Currency</h3>
6060
<option value="ZAR">ZAR</option>
6161
</select>
6262
</label>
63+
64+
<h3>Choose Your Secondary Currency</h3>
65+
<label class="custom-select">
66+
<select id="secondary" onchange="setSecondary()">
67+
<option value="BTC">BTC</option>
68+
<option value="USD">USD</option>
69+
<!-- 20 most traded currencies - https://en.wikipedia.org/wiki/Template:Most_traded_currencies -->
70+
<option value="AUD">AUD</option>
71+
<option value="BRL">BRL</option>
72+
<option value="CAD">CAD</option>
73+
<option value="CNY">CNY</option>
74+
<option value="EUR">EUR</option>
75+
<option value="GBP">GBP</option>
76+
<option value="HKD">HKD</option>
77+
<option value="INR">INR</option>
78+
<option value="JPY">JPY</option>
79+
<option value="KRW">KRW</option>
80+
<option value="MXN">MXN</option>
81+
<option value="NOK">NOK</option>
82+
<option value="NZD">NZD</option>
83+
<option value="RUB">RUB</option>
84+
<option value="SEK">SEK</option>
85+
<option value="SGD">SGD</option>
86+
<option value="TRY">TRY</option>
87+
<option value="ZAR">ZAR</option>
88+
</select>
89+
</label>
6390

6491
<div class="checkbox-wrapper">
6592
<input id="pin-to-top" class="checkbox-styled" type="checkbox" name="pin-to-top">

js/app_common.js

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ if (settings.has("user.currency")) {
2121
settings.set("user.currency", "USD");
2222
}
2323

24+
//default secondary currency
25+
if (settings.has("user.secondaryCurrency")) {
26+
//do nothing because secondary currency already set
27+
} else {
28+
settings.set("user.secondaryCurrency", "BRL");
29+
}
30+
2431
/* Base Currency */
2532
base = settings.get("user.currency"); // get the user's base currency
2633
var currSel = document.getElementById("base"); //select the currency select box
@@ -35,6 +42,20 @@ setBase = function () {
3542
updateData(); //immediately reflect the changed currency
3643
};
3744

45+
/* Secondary Currency */
46+
secondary = settings.get("user.secondaryCurrency"); // get the user's secondary currency
47+
var currSel = document.getElementById("secondary"); //select the currency select box
48+
currSel.value = settings.get("user.secondaryCurrency"); //select the option that corresponds to the user's secondary currency
49+
setSecondary = function () {
50+
//selected secondary currency
51+
var sel = document.getElementById("secondary");
52+
var x = sel.selectedIndex;
53+
var y = sel.options;
54+
secondary = y[x].text;
55+
settings.set("user.secondaryCurrency", secondary); //save the user's selection
56+
updateData(); //immediately reflect the changed secondary currency
57+
};
58+
3859
//Functions for creating/appending elements
3960
function createNode(element) {
4061
return document.createElement(element);
@@ -64,7 +85,7 @@ function initData() {
6485
"https://min-api.cryptocompare.com/data/pricemultifull?fsyms=" +
6586
settings.get("user.coins") +
6687
"&tsyms=" +
67-
base +
88+
[base, secondary].join(',') +
6889
"&extraParams=crypto-price-widget";
6990
fetch(url)
7091
.then(
@@ -166,7 +187,7 @@ function updateData() {
166187
"https://min-api.cryptocompare.com/data/pricemultifull?fsyms=" +
167188
settings.get("user.coins") +
168189
"&tsyms=" +
169-
base +
190+
[base, secondary].join(',') +
170191
"&extraParams=crypto-price-widget";
171192
/*
172193
** What data needs to be grabbed/changed?
@@ -187,13 +208,15 @@ function updateData() {
187208
for (let key of Object.keys(pricesRAW)) {
188209
let coinDISPLAY = pricesDISPLAY[key];
189210
let coinDISPLAYchange = coinDISPLAY[base].CHANGEPCT24HOUR;
211+
let secondaryCoinDISPLAYchange = coinDISPLAY[secondary].CHANGEPCT24HOUR;
190212
let coinRAW = pricesRAW[key];
191213
//console.log(coinDISPLAY);
192214
let li = document.getElementById("coin-" + [key]),
193215
span = document.querySelector("#coin-" + [key] + " span");
194216

195217
let coinSymbol = coinRAW[base].FROMSYMBOL;
196218
let coinRate = coinDISPLAY[base].PRICE.replace(/ /g, ""); //.replace(/ /g,'') removes space after $
219+
let secondaryCoinRate = coinDISPLAY[secondary].PRICE.replace(/ /g, ""); //.replace(/ /g,'') removes space after $
197220

198221
//replace currencies that have no symbols with easier to read formats
199222
if (coinRate.includes("AUD")) {
@@ -227,12 +250,47 @@ function updateData() {
227250
coinRate = coinRate.replace("ZAR", "R");
228251
}
229252

253+
if (secondaryCoinRate.includes("AUD")) {
254+
secondaryCoinRate = secondaryCoinRate.replace("AUD", "A$");
255+
}
256+
if (secondaryCoinRate.includes("CAD")) {
257+
secondaryCoinRate = secondaryCoinRate.replace("CAD", "C$");
258+
}
259+
if (secondaryCoinRate.includes("HKD")) {
260+
secondaryCoinRate = secondaryCoinRate.replace("HKD", "HK$");
261+
}
262+
if (secondaryCoinRate.includes("MXN")) {
263+
secondaryCoinRate = secondaryCoinRate.replace("MXN", "$");
264+
}
265+
if (secondaryCoinRate.includes("NOK")) {
266+
secondaryCoinRate = secondaryCoinRate.replace("NOK", "kr");
267+
}
268+
if (secondaryCoinRate.includes("NZD")) {
269+
secondaryCoinRate = secondaryCoinRate.replace("NZD", "NZ$");
270+
}
271+
if (secondaryCoinRate.includes("SEK")) {
272+
secondaryCoinRate = secondaryCoinRate.replace("SEK", "kr");
273+
}
274+
if (secondaryCoinRate.includes("SGD")) {
275+
secondaryCoinRate = secondaryCoinRate.replace("SGD", "S$");
276+
}
277+
if (secondaryCoinRate.includes("TRY")) {
278+
secondaryCoinRate = secondaryCoinRate.replace("TRY", "₺");
279+
}
280+
if (secondaryCoinRate.includes("ZAR")) {
281+
secondaryCoinRate = secondaryCoinRate.replace("ZAR", "R");
282+
}
283+
230284
//console.log(span);
231285
span.innerHTML =
232286
'<span class="sym">' +
233287
coinSymbol +
234-
"</span> " +
288+
"</span>" +
289+
' <div class="block">' +
235290
coinRate +
291+
'<br />' +
292+
secondaryCoinRate +
293+
'</div>' +
236294
'<span class="change">' +
237295
coinDISPLAYchange +
238296
"%</span>";

0 commit comments

Comments
 (0)