This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
71 lines (63 loc) · 1.75 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
import React, { useEffect, useGlobal, setGlobal } from "reactn"
import { StyleSheet, View, Text } from "react-native"
import Constants from "expo-constants"
import MainConversion from "/components/MainConversion"
import ExtraConversion from "/components/ExtraConversion"
import { getExchangeRate } from "/utils/utils"
import { listSymbols, listCurrencies } from "/data/data"
import { shadow2 } from "/constants/shadows"
setGlobal({
usdRates: {
USD: 1,
VND: 23000
},
currentCurrency: {
amount: "",
info: listCurrencies.USD
}
})
export default function App() {
const [usdRates, setUsdRates] = useGlobal("usdRates")
// ComponentDidMount
useEffect(() => {
for (const symbol of listSymbols) {
getExchangeRate("USD", symbol).then(exchangeRate => {
setUsdRates(oldUsdRates => ({
...oldUsdRates,
[symbol]: exchangeRate
}))
.then(() => console.log("Call api getting exchange rate for " + symbol, usdRates) )
})
}
}, [])
// useEffect(() => {
// for (const symbol of listSymbols) {
// getExchangeRate("USD", symbol).then(exchangeRate => {
// usdRates[symbol] = exchangeRate
// console.log("Call api got exchange rate for " + symbol, usdRates)
// })
// }
// setUsdRates(usdRates)
// }, [])
return (
<View style={styles.container}>
<Text>App loaded succesfullyy</Text>
<MainConversion style={styles.mainConversion} />
<ExtraConversion style={styles.extraConversion} />
</View>
)
}
const styles = StyleSheet.create({
container: {
marginTop: Constants.statusBarHeight,
height: "100%"
},
mainConversion: {
flex: 4
},
extraConversion: {
flex: 4,
backgroundColor: "white",
...shadow2
}
})