Skip to content

Commit a854434

Browse files
committed
Fix
1 parent 48087cd commit a854434

File tree

2 files changed

+110
-39
lines changed

2 files changed

+110
-39
lines changed

src/navigation/CreateWallet.tsx

Lines changed: 75 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useState } from 'react';
2-
import { View, Text, Button } from 'react-native';
2+
import { View, Text, Button, StyleSheet } from 'react-native';
33
import * as bitcoin from 'bitcoinjs-lib';
44
import QRCode from 'react-native-qrcode-svg';
5-
import * as bolt11 from 'light-bolt11-decoder';
5+
import { encode } from 'light-bolt11-decoder'; // Changed import to get encode directly
66

77
const CreateWallet = () => {
88
const [segwitAddress, setSegwitAddress] = useState<string | null>(null);
@@ -11,53 +11,103 @@ const CreateWallet = () => {
1111

1212
// Function to generate SegWit and Taproot addresses
1313
const generateAddresses = () => {
14-
const keyPair = bitcoin.ECPair.makeRandom();
15-
const { address: segwitAddr } = bitcoin.payments.p2wpkh({
16-
pubkey: keyPair.publicKey,
17-
});
18-
const { address: taprootAddr } = bitcoin.payments.p2tr({
19-
pubkey: keyPair.publicKey,
20-
});
21-
22-
setSegwitAddress(segwitAddr || null); // Ensure it's null if undefined
23-
setTaprootAddress(taprootAddr || null); // Ensure it's null if undefined
14+
try {
15+
const keyPair = bitcoin.ECPair.makeRandom({ network: bitcoin.networks.bitcoin });
16+
const { address: segwitAddr } = bitcoin.payments.p2wpkh({
17+
pubkey: keyPair.publicKey,
18+
network: bitcoin.networks.bitcoin,
19+
});
20+
const { address: taprootAddr } = bitcoin.payments.p2tr({
21+
pubkey: keyPair.publicKey,
22+
network: bitcoin.networks.bitcoin,
23+
});
24+
25+
setSegwitAddress(segwitAddr || null);
26+
setTaprootAddress(taprootAddr || null);
27+
} catch (error) {
28+
console.error('Error generating addresses:', error);
29+
}
2430
};
2531

2632
// Function to create a Lightning invoice (BOLT11)
2733
const generateBolt11Invoice = () => {
28-
const amountSats = 10000; // Example amount in satoshis
29-
const invoice = bolt11.encode({
30-
millisatoshis: amountSats * 1000,
31-
tags: [{ tagName: 'purpose', data: 'Payment for goods' }],
32-
});
33-
setInvoice(invoice || null); // Ensure it's null if undefined
34+
try {
35+
const amountSats = 10000; // Example amount in satoshis
36+
const paymentRequest = encode({
37+
paymentHash: Buffer.from('00'.repeat(32), 'hex'), // Dummy payment hash
38+
amount: amountSats.toString(), // Amount in satoshis as string
39+
timestamp: Math.floor(Date.now() / 1000),
40+
tags: [
41+
{
42+
tagName: 'payment_hash',
43+
data: '00'.repeat(32), // 32 bytes of zeros
44+
},
45+
{
46+
tagName: 'description',
47+
data: 'Payment for goods',
48+
},
49+
],
50+
});
51+
setInvoice(paymentRequest || null);
52+
} catch (error) {
53+
console.error('Error generating invoice:', error);
54+
}
3455
};
3556

3657
return (
37-
<View>
58+
<View style={styles.container}>
3859
<Button title="Generate Wallet Addresses" onPress={generateAddresses} />
60+
3961
{segwitAddress && (
40-
<View>
41-
<Text>SegWit Address: {segwitAddress}</Text>
62+
<View style={styles.addressContainer}>
63+
<Text style={styles.label}>SegWit Address:</Text>
64+
<Text style={styles.address}>{segwitAddress}</Text>
4265
<QRCode value={segwitAddress} size={150} />
4366
</View>
4467
)}
68+
4569
{taprootAddress && (
46-
<View>
47-
<Text>Taproot Address: {taprootAddress}</Text>
70+
<View style={styles.addressContainer}>
71+
<Text style={styles.label}>Taproot Address:</Text>
72+
<Text style={styles.address}>{taprootAddress}</Text>
4873
<QRCode value={taprootAddress} size={150} />
4974
</View>
5075
)}
76+
5177
<Button title="Generate Lightning Invoice" onPress={generateBolt11Invoice} />
78+
5279
{invoice && (
53-
<View>
54-
<Text>Lightning Invoice: {invoice}</Text>
80+
<View style={styles.addressContainer}>
81+
<Text style={styles.label}>Lightning Invoice:</Text>
82+
<Text style={styles.address}>{invoice}</Text>
5583
<QRCode value={invoice} size={150} />
5684
</View>
5785
)}
5886
</View>
5987
);
6088
};
6189

90+
const styles = StyleSheet.create({
91+
container: {
92+
flex: 1,
93+
padding: 16,
94+
alignItems: 'center',
95+
},
96+
addressContainer: {
97+
marginVertical: 16,
98+
alignItems: 'center',
99+
},
100+
label: {
101+
fontSize: 16,
102+
fontWeight: 'bold',
103+
marginBottom: 8,
104+
},
105+
address: {
106+
fontSize: 14,
107+
marginBottom: 8,
108+
textAlign: 'center',
109+
},
110+
});
111+
62112
export default CreateWallet;
63113

src/navigation/Fees.tsx

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
import React from 'react';
22
import { NavigationContainer } from '@react-navigation/native';
3-
import { createStackNavigator } from '@react-navigation/stack'; // Import Stack Navigator
3+
import { createStackNavigator } from '@react-navigation/stack';
44
import Fees from '../components/Fees';
55
import MinerFees from '../components/MinerFees';
66
import FeesMempoolBlocks from '../components/FeesMempoolBlocks';
7-
import Home from './path/to/Home'; // Adjust paths as necessary
7+
import Home from './path/to/Home'; // Make sure this path is correct for your project structure
88

9-
const Stack = createStackNavigator(); // Create Stack Navigator
9+
const Stack = createStackNavigator();
1010

1111
const App = () => {
12-
return (
13-
<NavigationContainer>
14-
<Stack.Navigator>
15-
<Stack.Screen name="Fees" component={Fees} />
16-
<Stack.Screen name="Miner Fees" component={MinerFees} />
17-
<Stack.Screen name="Fees Mempool Blocks" component={FeesMempoolBlocks} />
18-
<Stack.Screen name="Home" component={Home} /> {/* Corrected here */}
19-
</Stack.Navigator>
20-
</NavigationContainer>
21-
);
12+
return (
13+
<NavigationContainer>
14+
<Stack.Navigator
15+
initialRouteName="Home" // Optional: sets Home as the initial screen
16+
screenOptions={{
17+
headerShown: true, // Optional: shows header by default
18+
}}
19+
>
20+
<Stack.Screen
21+
name="Home"
22+
component={Home}
23+
options={{ title: 'Home' }} // Optional: customizes the header title
24+
/>
25+
<Stack.Screen
26+
name="Fees"
27+
component={Fees}
28+
options={{ title: 'Fees' }}
29+
/>
30+
<Stack.Screen
31+
name="MinerFees" // Changed to camelCase for consistency
32+
component={MinerFees}
33+
options={{ title: 'Miner Fees' }}
34+
/>
35+
<Stack.Screen
36+
name="FeesMempoolBlocks" // Changed to camelCase for consistency
37+
component={FeesMempoolBlocks}
38+
options={{ title: 'Fees Mempool Blocks' }}
39+
/>
40+
</Stack.Navigator>
41+
</NavigationContainer>
42+
);
2243
};
2344

24-
export default App;
45+
export default App;

0 commit comments

Comments
 (0)