This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
HomeView.js
166 lines (145 loc) · 4.14 KB
/
HomeView.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React from 'react';
import { View, Text, StyleSheet, TouchableHighlight, Switch } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
export default class CoinInformationHeader extends React.Component {
constructor(props) {
super(props);
this.state = {
switchValue: true,
price: 0,
price_btc: 0,
price_usd: 0,
rehydrated: false,
isLoaded: false,
hour: 0,
day: 0,
week: 0,
};
}
componentWillReceiveProps(){
let obj = this.props.coinInfo.coinInfo[0];
let rehydrated = this.props.rehydrated;
if (rehydrated){
let obj = this.props.coinInfo.coinInfo[0];
if (typeof obj != 'undefined'){
this.onLoad()
} else {this.setState({ price: 0, price_btc: 0, price_usd: 0})}
}
}
componentWillUnmount(){
this.setState({
switchValue: true,
price: 0,
price_btc: 0,
price_usd: 0,
rehydrated: false,
isLoaded: false,
hour: 0,
day: 0,
week: 0,
})
}
clickFunction() {
this.setState({switchValue: !this.state.switchValue});
};
changeFunction(value){
if (this.props.coinData.time === '1h'){
return this.state.hour;
}
if (this.props.coinData.time === '1d'){
return this.state.day;
}
if (this.props.coinData.time === '1w'){
return this.state.week;
}
else {
return value;
}
};
onLoad(){
//console.log(this.props.coinInfo.coinInfo[0])
let price_btc = this.props.coinInfo.coinInfo[0].price_btc;
let price_usd =this.props.coinInfo.coinInfo[0].price_usd;
let hour = this.props.coinInfo.coinInfo[0].percent_change_1h;
let day = this.props.coinInfo.coinInfo[0].percent_change_24h;
let week = this.props.coinInfo.coinInfo[0].percent_change_7d;
this.setState({
price_btc: price_btc,
price_usd: price_usd,
hour: hour,
day: day,
week: week,
});
}
render(){
// price_btc = (this.props.coinInfo.coinInfo[0].price_btc || 0);
var price_btc = this.state.price_btc;
//var price_btc = (this.props.coinInfo.coinInfo[0].price_btc.length > 0) ? this.props.coinInfo.coinInfo[0].price_btc: 0;
var price_usd = this.state.price_usd;
//var price_usd = this.props.coinInfo.coinInfo[0].price_usd;
change = this.props.coinData.change;
this.changeFunction(this.props.coinData.time)
var colorGains = change > 0 ? '#03C9A9' : '#D64541';
return (
<View style={styles.container}>
<Text style={styles.text}> {this.props.coinInfo.name}</Text>
<TouchableHighlight
onPress = {() => this.clickFunction()}>
<Text style={styles.textPrice}>
{!this.state.switchValue? price_btc + ' BTC':'$' + price_usd}
</Text>
</TouchableHighlight>
<Text style={styles.text}> {this.changeFunction(change)} %</Text>
</View>
);
}
}
const styles = StyleSheet.create({
containerTop: {
flexDirection: 'row',
paddingTop: 0,
paddingBottom: 10,
paddingLeft: 10,
paddingRight: 10,
},
container: {
},
containerTopLeft: {
flex:3,
alignItems: 'flex-start',
justifyContent: 'center',
paddingLeft: 10
},
containerTopCenter:{
flex:3,
alignItems: 'center',
justifyContent: 'center'
},
containerTopRight: {
flex:3,
alignItems: 'flex-end',
justifyContent: 'center',
paddingRight: 10
},
textHeader: {
textAlign: 'center',
fontSize: 28,
color: '#ffffff',
//paddingTop: 15,
fontFamily: 'HelveticaNeue-Thin'
},
textPrice: {
textAlign: 'center',
fontSize: 35,
color: '#ffffff',
paddingTop: 5,
fontFamily: 'HelveticaNeue-Thin'
},
text: {
textAlign: 'center',
//paddingTop: 5,
fontSize: 20,
color: 'grey',
fontFamily: 'HelveticaNeue-Thin'
}
});