-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
92 lines (83 loc) · 2.28 KB
/
App.js
File metadata and controls
92 lines (83 loc) · 2.28 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
import React, { Component } from 'react';
import { StyleSheet, Text, View, Image, Button, TouchableWithoutFeedback } from 'react-native';
export default class App extends Component {
state = {
pending: false,
finished: false,
address: null,
}
startReceiving = () => {
console.log('Starting to receive shizzle!');
this.setState({
pending: true
});
setTimeout(() => {
this.setState({
address: 'iota://9YDL9GNKTPRZNQPADINAUEWIQGTZYOEXNIOWPZHJIVXAYTN9TDDQMNMQUSGYDLAEXNIOIGAGZJAXTJJJ9ZCPWYDWDG/?timeout_at=1571568930076&multi_use=1'
})
}, 200)
}
onMoneyReceived = () => {
this.setState({
address: null,
pending: false,
finished: true
})
setTimeout(() => {
this.setState({
finished: false
})
}, 4000)
}
renderPending = () => {
const { address } = this.state;
if (address === null) {
return (<View><Text>...</Text></View>)
}
return (
<TouchableWithoutFeedback onPress={this.onMoneyReceived}>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text style={{fontSize: 18, textAlign: 'center'}}>
Hold the phone in front of the bottle taker
</Text>
<Image source={{
uri: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURI(address)}`,
}} style={{
width: 150,
height: 150,
resizeMode: 'contain'
}} />
</View>
</TouchableWithoutFeedback>
)
}
renderFinished = () => {
return (
<View style={{backgroundColor: '#00FF00', flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text style={{fontSize: 24, color: 'white', textAlign: 'center'}}>Money received!</Text>
</View>
)
}
render() {
const { pending, finished} = this.state;
if (pending) {
return this.renderPending();
}
if (finished) {
return this.renderFinished();
}
return (
<View style={styles.container}>
<Button onPress={this.startReceiving} title={'Return bottles'} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});