-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPrice.jsx
52 lines (40 loc) · 1.22 KB
/
Price.jsx
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
'use strict';
function Price(props){
const baseUrl = 'https://api.binance.com/api/v3/ticker/price?symbol='+props.symbol;
const [price, setPrice] = React.useState("Loading...");
const [temp, setTemp] = React.useState(false);
const [prevPrice, setPrevPrice] = React.useState(-9999999);
let req = new XMLHttpRequest();
React.useEffect(() => {
setTimeout(() => {
setTemp(!temp);
req.open('GET',baseUrl,true);
req.send();
req.onload = (() => {
setPrevPrice(price);
setPrice(JSON.parse(req.responseText).price);
});
},500);
}, [temp]);
const setColor = (() => {
if(price >= prevPrice) {
return '#7CFC00'
}
else return '#FF0000'
return 'white'
})
let style = {
backgroundColor:"black",
color:setColor(),
fontSize:"5em",
display:"flex",
flexDirection:"row",
justifyContent:"space-around"
}
return(
<div style={style}>
<div style = {{color: 'white'}}>{props.name}</div>
<div>{"$ " + price}</div>
</div>
)
}