-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComp.js
160 lines (131 loc) · 5.44 KB
/
Comp.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
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
import React, { useState, useContext, useEffect } from 'react';
import { View, Text, StyleSheet, Button, TouchableOpacity, Alert } from 'react-native';
import NetworkContext from './context/NetworkContext';
import { saveData, getData, removeData } from './utils/SecureStorage';
import rsaUtility from './utils/RsaEncryptDecycript';
import { navigateToScreen } from './utils/NavigationRef';
import { Dynatrace, reportCrash,DataCollectionLevel,DynatraceWebRequestTiming, UserPrivacyOptions } from '@dynatrace/react-native-plugin';
const SimpleComp = ({ navigation }) => {
const isConnected = useContext(NetworkContext);
useEffect(() => {
const runRSAExample = async () => {
const { publicKey, privateKey } = await rsaUtility.generateKeys();
setPublicKey(publicKey);
setPrivateKey(privateKey)
};
runRSAExample();
}, []);
const [encodedMessage, setencodedMessage] = useState("")
const [publicKey, setPublicKey] = useState("")
const [privateKey, setPrivateKey] = useState("")
const runEncrypt = async () => {
const message = 'my secret message';
const encodedMessages = await rsaUtility.encryptMessage(message, publicKey);
setencodedMessage(encodedMessages)
};
const runDeEncrypt = async () => {
const decryptedMessage = await rsaUtility.decryptMessage(encodedMessage, privateKey);
Alert.alert('Decrypted Message:', decryptedMessage);
};
const reportAction = async () => {
reportCrash("Crash is jere")
Dynatrace.identifyUser("User XY");
reportCrash("someCrasf");
// Dynatrace.endSession();
let myAction = Dynatrace.enterAutoAction("MyButton tapped");
myAction.reportStringValue("ValueName", "ImportantValue");
myAction.leaveAction();
let url = 'https://www.dynatrace.com';
// You can also use enterAutoAction if desired
let action = Dynatrace.enterManualAction("Manual Web Request");
let tag = await action.getRequestTag(url);
let timing = new DynatraceWebRequestTiming(url, tag);
try {
timing.startWebRequestTiming();
let axiosResponse = await axios.get(url);
timing.stopWebRequestTimingWithSize(axiosResponse.status, axiosResponse.data, 122, 63);
} catch (error) {
timing.stopWebRequestTiming(-1, error);
} finally {
action.leaveAction();
}
}
return (
<View style={styles.container}>
<Text style={styles.title}>
Error boundaries and Internet Connection
</Text>
<Text style={styles.text}>
Lets produce error by clicking on the following button to render a component that will throw an error.
</Text>
<TouchableOpacity
accessibilityLabel='Reported'
style={styles.buttons} onPress={() => {
reportAction()
let myAction = Dynatrace.enterManualAction("MyButton tapped");
//Perform the action and whatever else is needed.
myAction.leaveAction();
// let myAction = Dynatrace.enterAutoAction("MyButton tapped");
// myAction.leaveAction();
navigateToScreen('MediaPicker', { param1: 'value1' });
}
}>
<Text style={[{ color: '#ffff' }]}>Throw test error</Text>
</TouchableOpacity>
{isConnected ? (
<Text style={styles.title}>Network Status: Connected </Text>
) : (
<Text style={styles.title}>Network Status: Not connected </Text>
)}
<TouchableOpacity style={styles.buttons2} onPress={() => saveData('user', { name: 'John', age: 30 })}>
<Text style={[{ color: 'black' }]}>Store Secure User data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttons2} onPress={() => { getData('user').then((data) => Alert.alert('Retrieved data:', JSON.stringify(data))) }}>
<Text style={[{ color: 'black' }]}>Get User data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttons2} onPress={() => { removeData('user'); }}>
<Text style={[{ color: 'black' }]}>Remove data</Text>
</TouchableOpacity>
<Text style={styles.title}>RSA Encryption / Decryption </Text>
<TouchableOpacity style={styles.buttons2} onPress={runEncrypt}>
<Text style={[{ color: 'black' }]}>Encrypt Data</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.buttons2} onPress={runDeEncrypt}>
<Text style={[{ color: 'black' }]}>Decncrypt data</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
buttons: {
backgroundColor: 'red',
padding: 10,
borderRadius: 5
},
buttons2: {
padding: 10,
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingTop: 22,
// backgroundColor: '#ecf0f1',
padding: 28,
textAlign: 'center',
},
title: {
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
marginTop: 20
},
icon: {
fontSize: 48
},
text: {
marginVertical: 16
}
});
Dynatrace.withMonitoring(SimpleComp, "SimpleComp");
export default SimpleComp