-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApp.js
More file actions
311 lines (269 loc) · 8.31 KB
/
App.js
File metadata and controls
311 lines (269 loc) · 8.31 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import React, { useState, useCallback } from 'react';
import {
Text,
View,
Button,
Switch,
TextInput,
StyleSheet,
ScrollView,
} from 'react-native';
import SmallcaseGateway, { GATEWAY_ENV } from 'react-native-smallcase-gateway';
import ScLoan from 'react-native-smallcase-gateway';
const App = () => {
const [log, setLog] = useState<string>('');
const [env, setEnv] = useState<GATEWAY_ENV>(GATEWAY_ENV.PROD);
const [sdkToken, setSdkToken] = useState(
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJndWVzdCI6dHJ1ZSwiaWF0IjoxNTk5Njc0MzYyLCJleHAiOjE2OTk2Nzc5NjJ9.12czJ5vFOlyZqxa8Q3dg-p5OilcJvb8ZdiP-MiSaQb0'
);
const [iscid, setIscid] = useState('60ae3f69e3f4b0e0c5f98d12');
const [transactionId, setTransactionId] = useState('');
const [targetEndpoint, setTargetEndpoint] = useState('');
const [isLeprechaunEnabled, setIsLeprechaunEnabled] = useState(false);
// const toggleSwitch = () => setIsLeprechaunEnabled(previousState => !previousState);
const toggleLeprechaunSwitch = () =>
setIsLeprechaunEnabled(!isLeprechaunEnabled);
const [isAmoEnabled, setIsAmoEnabled] = useState(false);
// const toggleAmoSwitch = () => setIsAmoEnabled(previousState => !previousState);
const toggleAmoSwitch = () => setIsAmoEnabled(!isAmoEnabled);
const sdkVersion = useCallback(async () => {
setLog((p) => p + '\n sdk version is:');
try {
const res = await SmallcaseGateway.getSdkVersion();
setLog((p) => p + res);
} catch (err) {
setLog((p) => p + '\n error fetching version string' + err);
}
}, []);
const updateEnv = useCallback(async () => {
setLog((p) => p + '\n setting config');
setLog((p) => p + isLeprechaunEnabled);
setLog((p) => p + isAmoEnabled);
try {
await SmallcaseGateway.setConfigEnvironment({
environmentName: env,
gatewayName: 'gatewaydemo',
isLeprechaun: isLeprechaunEnabled,
isAmoEnabled: isAmoEnabled,
brokerList: [],
});
setLog((p) => p + '\n config set successfully');
} catch (err) {
setLog((p) => p + '\n error setting config' + err);
}
}, [env, isLeprechaunEnabled, isAmoEnabled]);
const init = useCallback(async () => {
setLog((p) => p + '\n starting init');
try {
await SmallcaseGateway.initSDK(sdkToken);
setLog((p) => p + '\n init success');
} catch (err: any) {
setLog((p) => p + '\n error during init' + JSON.stringify(err.userInfo));
}
}, [sdkToken]);
const startTransaction = useCallback(async () => {
setLog((p) => p + '\n starting transaction');
try {
const res = await SmallcaseGateway.triggerTransaction(transactionId, {
test: 'test',
});
setLog((p) => p + '\n transaction success');
setLog((p) => p + '\n' + JSON.stringify(res, null, 2));
} catch (err: any) {
setLog(
(p) => p + '\n error during transaction' + JSON.stringify(err.userInfo)
);
}
}, [transactionId]);
const showOrders = useCallback(async () => {
setLog((p) => p + '\n starting show orders');
try {
const showOrdersRes = await SmallcaseGateway.showOrders();
setLog((p) => p + '\n show order success');
setLog((p) => p + '\n' + JSON.stringify(showOrdersRes, null, 2));
} catch (err: any) {
setLog(
(p) => p + '\n show order error: \n' + JSON.stringify(err.userInfo)
);
}
}, []);
const markSmallcaseArchive = useCallback(async () => {
setLog((p) => p + '\n marking smallcase archive');
try {
const res = await SmallcaseGateway.archiveSmallcase(iscid);
setLog((p) => p + '\n archive success');
setLog((p) => p + '\n' + JSON.stringify(res, null, 2));
} catch (err) {
setLog((p) => p + '\n error during archive' + JSON.stringify(err));
}
}, [iscid]);
const triggerLeadGen = useCallback(async () => {
setLog((p) => p + '\n triggering lead gen');
try {
const res = await SmallcaseGateway.triggerLeadGenWithStatus({
name: 'test',
});
setLog((p) => p + '\n lead gen success');
setLog((p) => p + '\n' + JSON.stringify(res, null, 2));
} catch (err: any) {
setLog(
(p) =>
p + '\n error during trigger lead gen' + JSON.stringify(err.userInfo)
);
}
}, []);
const launchSmallplug = useCallback(async () => {
setLog((p) => p + '\n launching smallplug');
try {
const res = await SmallcaseGateway.launchSmallplugWithBranding(
targetEndpoint,
''
);
setLog((p) => p + '\n' + JSON.stringify(res, null, 2));
} catch (err) {
setLog(
(p) => p + '\n error while launching smallplug' + JSON.stringify(err)
);
}
}, []);
return (
<ScrollView style={styles.container}>
<Text>Smallcase SDK Tester</Text>
<View style={styles.envContainer}>
<EnvButton
buttonEnv={GATEWAY_ENV.PROD}
currentEnv={env}
onPress={setEnv}
/>
<EnvButton
buttonEnv={GATEWAY_ENV.STAG}
currentEnv={env}
onPress={setEnv}
/>
<EnvButton
buttonEnv={GATEWAY_ENV.DEV}
currentEnv={env}
onPress={setEnv}
/>
</View>
<View
style={[
styles.container,
{
flexDirection: 'row',
},
]}
>
<Text>Leprechaun Mode</Text>
<Switch
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={isLeprechaunEnabled ? '#f5dd4b' : '#f4f3f4'}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleLeprechaunSwitch}
value={isLeprechaunEnabled}
/>
</View>
<View
style={[
styles.container,
{
flexDirection: 'row',
},
]}
>
<Text>isAmoEnabled</Text>
<Switch
trackColor={{ false: '#767577', true: '#81b0ff' }}
thumbColor={isAmoEnabled ? '#f5dd4b' : '#f4f3f4'}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleAmoSwitch}
value={isAmoEnabled}
/>
</View>
<Button title="Get SDK version" onPress={sdkVersion} />
<Button title="update env" onPress={updateEnv} />
<TextInput
value={sdkToken}
onChangeText={setSdkToken}
style={styles.inp}
placeholder="sdk token"
/>
<Button title="initialize" onPress={init} />
<TextInput
value={transactionId}
onChangeText={setTransactionId}
style={styles.inp}
placeholder="transaction id"
/>
<Button title="start transaction" onPress={startTransaction} />
<Button title="Show Orders" onPress={showOrders} />
<Button title="Lead Gen" onPress={triggerLeadGen} />
{/* <View style={styles.envContainer}>
<Button
title="Open lead gen"
onPress={triggerLeadGen}
// onPress={() => {
// SmallcaseGateway.triggerLeadGen();
// }}
/>
</View> */}
{/* <TextInput
value={iscid}
onChangeText={setIscid}
style={styles.inp}
placeholder="iscid"
/>
<Button title="archive smallcase" onPress={markSmallcaseArchive} /> */}
<TextInput
value={targetEndpoint}
onChangeText={setTargetEndpoint}
style={styles.inp}
placeholder="Target Endpoint"
/>
<Button title="launch smallplug" onPress={launchSmallplug} />
<View style={styles.logBox}>
<Button title="clear logs" onPress={() => setLog('')} />
<Text>{log}</Text>
</View>
</ScrollView>
);
};
interface EnvButtonProps {
buttonEnv: GATEWAY_ENV;
currentEnv: GATEWAY_ENV;
onPress(e: GATEWAY_ENV): void;
}
const EnvButton = ({ buttonEnv, currentEnv, onPress }: EnvButtonProps) => {
let color = '#cecece';
if (currentEnv === buttonEnv) {
color = '#27BC94';
}
return (
<Button
color={color}
title={buttonEnv}
onPress={() => onPress(buttonEnv)}
/>
);
};
const styles = StyleSheet.create({
container: {
margin: 16,
},
inp: {
backgroundColor: '#A8D0DB',
borderRadius: 8,
paddingHorizontal: 8,
marginVertical: 16,
},
envContainer: {
flexDirection: 'row',
marginVertical: 16,
justifyContent: 'space-evenly',
},
logBox: {
alignItems: 'flex-start',
marginVertical: 16,
},
});
export default App;