-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
51 lines (46 loc) · 1.83 KB
/
ui.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
47
48
49
50
51
class UI {
static getCurrencies(firstSelect, secondSelect) {
Currency.getCurrencies()
.then(currencies => {
currencies.sort()
for (const index in currencies) {
firstSelect.options[firstSelect.options.length] = new Option(currencies[index])
if (currencies[index] == "USD") {
firstSelect.selectedIndex = index
}
}
currencies.forEach((currency, index) => {
secondSelect[index] = new Option(currency)
if (currency == "TRY") {
secondSelect.selectedIndex = index
}
})
date.textContent = ""
})
.catch(err => console.log(err))
}
static updateOutputs(firstCurrency, secondCurrency) {
firstOutput.textContent = firstCurrency
secondOutput.textContent = secondCurrency
}
static exchange(amount, firstCurrency, secondCurrency, rate, date, result) {
Currency.exchange(amount, firstCurrency, secondCurrency)
.then(obj => {
rate.textContent = `(${obj.rate.toFixed(4)})`
date.textContent = obj.date
result.value = obj.total.toFixed(2)
})
.catch(err => console.log(err))
}
static loading() {
rate.textContent = ""
result.value = ""
date.innerHTML = `
<div class="spinner-border spinner-border-sm text-warning" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border spinner-border-sm text-danger" role="status">
<span class="visually-hidden">Loading...</span>
</div>`
}
}