-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
82 lines (74 loc) · 2.08 KB
/
App.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, {useEffect, useState} from 'react';
import {
ActivityIndicator,
Image,
ScrollView,
StyleSheet,
View,
} from 'react-native';
import Form from './components/Form';
import Header from './components/Header';
import axios from 'axios';
import MarketPrice from './components/MarketPrice';
const App = () => {
const [currency, setCurrency] = useState([]);
const [cryptocurrency, setCryptocurrency] = useState([]);
const [consultAPI, setConsultAPI] = useState(false);
const [tradingResult, setTradingResult] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => {
const tradeCryptocurrency = async () => {
if (consultAPI) {
const url = `https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${cryptocurrency}&tsyms=${currency}`;
const {data} = await axios.get(url);
setLoading(true);
setTimeout(() => {
setTradingResult(data.DISPLAY[cryptocurrency][currency]);
setConsultAPI(false);
setLoading(false);
}, 3000);
}
};
tradeCryptocurrency();
}, [consultAPI, cryptocurrency, currency]);
const tradingComponent = loading ? (
<ActivityIndicator size="large" color="#5E49E2" />
) : (
<MarketPrice tradingResult={tradingResult} />
);
return (
<>
<ScrollView>
<Header />
<Image
style={styles.bgImage}
source={require('./assets/img/cryptocurrencies.png')}
/>
<View style={styles.content}>
<Form
currency={currency}
cryptocurrency={cryptocurrency}
setCurrency={setCurrency}
setCryptocurrency={setCryptocurrency}
setConsultAPI={setConsultAPI}
/>
</View>
<View style={styles.contentTradingResult}>{tradingComponent}</View>
</ScrollView>
</>
);
};
const styles = StyleSheet.create({
bgImage: {
width: '100%',
height: 150,
marginHorizontal: '2.5%',
},
content: {
marginHorizontal: '2.5%',
},
contentTradingResult: {
marginTop: 40,
},
});
export default App;