-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.js
91 lines (80 loc) · 2.29 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
import React from 'react'
import {
View, Text, TouchableOpacity
} from 'react-native'
import NfcManager, { NfcEvents, NfcTech } from 'react-native-nfc-manager';
import sendAPDU from "./emv/commands/command-sender";
import SelectApdu, { SelectPpseApdu } from './emv/commands/select';
import parseTlvs from './emv/tlv-parser';
import { getAids } from './emv/tlv-utils';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
testing: false
};
}
componentDidMount() {
NfcManager.start();
}
componentWillUnmount() {
this._cancel();
}
_onTagDiscovered = async tag => {
console.log('Tag Discovered', tag);
this.setState({ tag });
console.log("tech requested")
try {
const response = await sendAPDU(SelectPpseApdu);
const tlvs = parseTlvs(response.response);
const aids = getAids(tlvs[0]);
const selectAidResponse = await sendAPDU(new SelectApdu(aids[0], 0));
this.setState({ response: selectAidResponse });
} catch (error) {
console.error(error);
this.setState({ response: error });
}
}
render() {
var tag = JSON.stringify(this.state?.tag);
var response = this.state?.response?.toString();
var testing = this.state?.testing;
return (
<View style={{ padding: 20 }}>
<Text>NFC Demo</Text>
{testing ?
<TouchableOpacity
style={{ padding: 10, width: 200, margin: 20, borderWidth: 1, borderColor: 'black' }}
onPress={this._cancel}
>
<Text>Cancel Test</Text>
</TouchableOpacity>
:
<TouchableOpacity
style={{ padding: 10, width: 200, margin: 20, borderWidth: 1, borderColor: 'black' }}
onPress={this._test}
>
<Text>Test</Text>
</TouchableOpacity>
}
<Text>{tag}</Text>
<Text>{response}</Text>
</View>
)
}
_cancel = () => {
NfcManager.cancelTechnologyRequest().catch(() => 0);
this.setState({ testing: false });
}
_test = async () => {
this.setState({ testing: true });
try {
await NfcManager.requestTechnology(NfcTech.IsoDep);
await this._onTagDiscovered();
} catch (ex) {
console.warn('ex', ex);
}
this._cancel();
}
}
export default App