-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
245 lines (212 loc) · 5.68 KB
/
App.js
File metadata and controls
245 lines (212 loc) · 5.68 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import React, { Component } from 'react';
import { Text, TextInput, View, Button, StyleSheet } from 'react-native';
import QRScanner from './qrscanner.js';
import t from 'tcomb-form-native';
const Form = t.form.Form;
import styles from './styles.js';
import RESTfunct from './requestsOfficial.js';
import { Camera } from 'expo-camera';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
page: 'home',
product: {},
secret_key: undefined,
};
this.setPage = this.setPage.bind(this);
this.setProduct = this.setProduct.bind(this);
this.setSecretKey = this.setSecretKey.bind(this);
this.getTransaction = this.getTransaction.bind(this);
this.funct = {
setPage: this.setPage,
setProduct: this.setProduct,
setSecretKey: this.setSecretKey,
getTransaction: this.getTransaction
};
}
setPage(page) {
this.setState({page: page});
}
setProduct(obj, product) {
this.state.product[obj] = product;
}
setSecretKey(secret_key) {
this.setState({secret_key: secret_key});
}
getTransaction() {
return ({
secret_key: this.state.secret_key,
price: this.state.product.price,
recipient: this.state.product.vendor_email,
product_name: this.state.product.name
});
}
render() {
if (this.state.page === 'home') {
return <Home funct={this.funct} />;
}
if (this.state.page === 'vendor') {
return <Vendor funct={this.funct} />;
}
if (this.state.page === 'buyer') {
return <QRScanner funct={this.funct} />;
}
if (this.state.page === 'login') {
return <Login funct={this.funct} />;
}
if (this.state.page === 'confirm') {
return <Confirm funct={this.funct} />
}
if (this.state.page === 'complete') {
return <Complete funct={this.funct} />
}
}
};
class Home extends Component {
constructor(props) {
super(props);
this.funct = props.funct;
}
render() {
return (
<View style={styles.home}>
<Text style={styles.title}>CheckPlz</Text>
<View style={styles.buttonContainer}>
<Button style={styles.roundButton}
onPress={() => this.funct.setPage('vendor')}
title="Vendor"
/>
</View>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('buyer')}
title="Buyer"
/>
</View>
</View>
);
}
}
class Vendor extends Component {
constructor(props) {
super(props);
this.funct = props.funct;
}
render() {
return (
<View style={styles.home}>
<Text>Vendor placeholder</Text>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('home')}
title="Go back"
/>
</View>
</View>
);
}
}
class Login extends Component {
constructor(props) {
super(props);
this.funct = props.funct;
this.state = {
email: '',
password: '',
invalid: false
}
}
processLogin(email, password) {
RESTfunct.emailToSecret(email, (secret_key) => {
this.funct.setSecretKey(secret_key);
this.funct.setPage('confirm');
}).catch(() => {
this.setState({invalid: true});
});
}
render() {
return (
<View style={styles.home}>
{ this.state.invalid && ( <Text>Invalid email</Text> )}
<TextInput
style={styles.input}
placeholder='Email'
onChangeText={(text) => this.setState({email: text})}
/>
<TextInput
secureTextEntry={true}
style={styles.input}
placeholder='Password'
onChangeText={(text) => this.setState({password: text})}
/>
<View style={styles.buttonContainer}>
<Button
onPress={() => {this.processLogin(this.state.email, this.state.password)}}
title="Submit"
/>
</View>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('home')}
title="Go back"
/>
</View>
</View>
);
}
}
class Confirm extends Component {
constructor(props) {
super(props);
this.funct = props.funct;
}
render() {
var transaction = this.funct.getTransaction();
return (
<View style={styles.home}>
<Text style={styles.title}>Confirmation</Text>
<Text style={{fontSize: 15, margin: 5}}>Product name</Text>
<Text>{transaction.product_name}</Text>
<Text style={{fontSize: 15, margin: 5}}>Transaction price</Text>
<Text>{transaction.price}</Text>
<Text style={{fontSize: 15, margin: 5}}>Recipient</Text>
<Text>{transaction.recipient}</Text>
<View style={styles.buttonContainer}>
<Button
onPress={() => {
RESTfunct.sendTransaction(transaction.secret_key, transaction.recipient, transaction.price);
this.funct.setPage('complete');
}}
title="Confirm"
/>
</View>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('home')}
title="Go back"
/>
</View>
</View>
);
}
}
class Complete extends Component {
constructor(props) {
super(props);
this.funct = props.funct;
}
render() {
return (
<View style={styles.home}>
<Text style={styles.title}>Transaction complete</Text>
<View style={styles.buttonContainer}>
<Button
onPress={() => this.funct.setPage('home')}
title="Go home"
/>
</View>
</View>
);
}
}