-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayments.tsx
64 lines (59 loc) · 1.93 KB
/
Payments.tsx
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
import React, { useState } from 'react';
import { View, Text, TextInput, Button, StyleSheet } from 'react-native';
const Payments: React.FC = () => {
const [senderSecret, setSenderSecret] = useState<string>('');
const [receiverPublicKey, setReceiverPublicKey] = useState<string>('');
const [amount, setAmount] = useState<string>('');
const [paymentMessage, setPaymentMessage] = useState<string>('');
const makePayment = async () => {
console.log('Make Payment button clicked');
try {
const response = await fetch('http://10.0.2.2:3001/make-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
senderSecret,
receiverPublicKey,
amount,
}),
});
const data = await response.json();
console.log('Payment made:', data);
setPaymentMessage(data.message);
} catch (error) {
console.error('Error making payment:', error);
setPaymentMessage('Error making payment.');
}
};
return (
<View style={styles.container}>
<Text style={styles.heading}>Payments</Text>
<TextInput
style={styles.input}
placeholder="Sender Secret Key"
value={senderSecret}
onChangeText={setSenderSecret}
/>
<TextInput
style={styles.input}
placeholder="Receiver Public Key"
value={receiverPublicKey}
onChangeText={setReceiverPublicKey}
/>
<TextInput
style={styles.input}
placeholder="Amount"
value={amount}
onChangeText={setAmount}
/>
<Button title="Make Payment" onPress={makePayment} />
<Text>{paymentMessage}</Text>
</View>
);
};
const styles = StyleSheet.create({
container: { padding: 20 },
heading: { fontSize: 24, marginBottom: 20 },
input: { height: 40, borderColor: 'gray', borderWidth: 1, marginBottom: 10, paddingLeft: 8 }
});
export default Payments;