-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTodayWidget.js
128 lines (112 loc) · 2.47 KB
/
TodayWidget.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
import React from 'react';
import {
ActivityIndicator,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {
getGreatLakesBalance,
getMohelaBalance,
} from './Api';
const styles = StyleSheet.create({
container: {
alignItems: 'center',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
marginLeft: 20,
marginRight: 20,
},
refreshButton: {
alignItems: 'center',
backgroundColor: '#c4c7c8',
borderRadius: 35,
flex: 0,
height: 70,
justifyContent: 'center',
opacity: 0.8,
width: 70,
},
refreshText: {
color: 'black',
},
totalAmount: {
fontSize: 28,
marginTop: 5,
},
totalTitle: {
fontSize: 20,
},
totalContainer: {
flex: 0,
},
});
class TodayWidget extends React.Component {
constructor(args) {
super(...args);
this.state = {
greatLakesBalance: 0.0,
greatLakesLoading: true,
mohelaBalance: 0.0,
mohelaLoading: true,
};
}
componentDidMount() {
this.refreshBalances();
}
updateGreatLakesBalance = async () => {
this.setState({ greatLakesLoading: true });
const greatLakesBalance = await getGreatLakesBalance();
this.setState({
greatLakesBalance,
greatLakesLoading: false,
});
}
updateMohelaBalance = async () => {
this.setState({ mohelaLoading: true });
const mohelaBalance = await getMohelaBalance();
this.setState({
mohelaLoading: false,
mohelaBalance,
});
}
refreshBalances = () => {
this.updateGreatLakesBalance();
this.updateMohelaBalance();
}
render() {
const {
greatLakesBalance,
greatLakesLoading,
mohelaBalance,
mohelaLoading,
} = this.state;
const isLoading = mohelaLoading || greatLakesLoading;
return (
<View
style={styles.container}
>
<View style={styles.totalContainer}>
<Text style={styles.totalTitle}>
{'Total balance:'}
</Text>
<Text style={styles.totalAmount}>
{isLoading ? '' : `$${(mohelaBalance + greatLakesBalance).toFixed(2)}`}
</Text>
{isLoading &&
<ActivityIndicator animating />
}
</View>
<TouchableOpacity
onPress={this.refreshBalances}
style={styles.refreshButton}
>
<Text style={styles.refreshText}>{'Refresh'}</Text>
</TouchableOpacity>
</View>
);
}
}
export default TodayWidget;