-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
90 lines (85 loc) · 2.4 KB
/
App.js
File metadata and controls
90 lines (85 loc) · 2.4 KB
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
83
84
85
86
87
88
89
90
import React, { useState, useEffect } from "react";
import {
StyleSheet,
View,
Image,
ScrollView,
ActivityIndicator,
} from "react-native";
import Header from "./components/Header";
import Formulario from "./components/Formulario";
import Cotizacion from "./components/Cotizacion";
import axios from "axios";
export default function App() {
const [moneda, setMoneda] = useState("");
const [cripto, setCripto] = useState("");
const [consultarAPI, guardarConsultarAPI] = useState(false);
const [resultado, guardarResultado] = useState({});
// Spinners
const [cargando, guardarCargando] = useState(false);
useEffect(() => {
const cotizarCriptomoneda = async () => {
if (consultarAPI) {
// consultar la API para obtener la cotizacion
// seteo url
const url = `https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${cripto}&tsyms=${moneda}`;
// guardo consulta
const resultado = await axios.get(url);
guardarCargando(true);
// Ocultar el spinner y mostrar el resultado que
setTimeout(() => {
// Guardo resultado
guardarResultado(resultado.data.DISPLAY[cripto][moneda]);
// Para poder repetir consultas
guardarConsultarAPI(false);
guardarCargando(false);
}, 3000);
}
};
cotizarCriptomoneda();
}, [consultarAPI]);
// mostrar el spinner
const componente = cargando ? (
<ActivityIndicator size="large" color="#5e452e" />
) : (
<Cotizacion resultado={resultado} />
);
return (
<>
<ScrollView>
<View>
<Header />
<View style={styles.contenedorImagen}>
<Image
style={styles.imagen}
source={require("./assets/img/banner.jpg")}
/>
</View>
<View style={styles.contenedorForm}>
<Formulario
moneda={moneda}
cripto={cripto}
setMoneda={setMoneda}
setCripto={setCripto}
guardarConsultarAPI={guardarConsultarAPI}
/>
</View>
</View>
<View style={{ marginTop: 40 }}>{componente}</View>
</ScrollView>
</>
);
}
const styles = StyleSheet.create({
imagen: {
width: "100%",
height: 200,
},
contenedorImagen: {
borderBottomColor: "#35A7FF",
borderBottomWidth: 5,
},
contenedorForm: {
marginVertical: 20,
},
});