-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
134 lines (120 loc) · 2.87 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
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
import React, { Component } from 'react';
import {
ActivityIndicator,
Button,
StyleSheet,
Text,
View,
} from 'react-native';
import {
getGreatLakesBalance,
getMohelaBalance,
} from './Api';
const styles = StyleSheet.create({
balances: {
fontSize: 20,
textAlign: 'center',
padding: 10,
},
balancesContainer: {
alignItems: 'center',
flex: 0,
flexDirection: 'row',
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
refreshButton: {
bottom: 20,
position: 'absolute',
},
total: {
fontSize: 30,
textAlign: 'center',
},
totalContainer: {
alignItems: 'center',
flex: 0,
flexDirection: 'row',
paddingTop: 20,
},
});
export default class App extends 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;
return (
<View style={styles.container}>
<View style={styles.balancesContainer}>
<Text style={styles.balances}>
{`Mohela balance: ${mohelaLoading ? '' : `$${mohelaBalance.toFixed(2)}`}`}
</Text>
{mohelaLoading &&
<ActivityIndicator animating />
}
</View>
<View style={styles.balancesContainer}>
<Text style={styles.balances}>
{`Great lakes balance: ${greatLakesLoading ? '' : `$${greatLakesBalance.toFixed(2)}`}`}
</Text>
{greatLakesLoading &&
<ActivityIndicator animating />
}
</View>
<View style={styles.totalContainer}>
<Text style={styles.total}>
{`Total balance: ${mohelaLoading ? '' : `$${(mohelaBalance + greatLakesBalance).toFixed(2)}`}`}
</Text>
{(mohelaLoading || greatLakesLoading) &&
<ActivityIndicator animating />
}
</View>
<View style={styles.refreshButton}>
<Button
onPress={this.refreshBalances}
title="Refresh"
/>
</View>
</View>
);
}
}