-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
109 lines (102 loc) · 2.62 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { useEffect } from 'react';
import { StyleSheet } from 'react-native';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { useWallet } from './src/hooks/useWallet';
import BlockchainService from './src/services/BlockchainService';
export default function App() {
const { connect, disconnect, account, chainId, error } = useWallet();
useEffect(() => {
// Initialize blockchain service with wallet connection
if (account && chainId) {
BlockchainService.initialize(account, chainId);
}
}, [account, chainId]);
return (
<SafeAreaProvider>
<StatusBar style="auto" />
<Stack
screenOptions={{
headerStyle: {
backgroundColor: '#f5f5f5',
},
headerTintColor: '#000',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
>
<Stack.Screen
name="index"
options={{
title: 'CommUnityMarket',
headerRight: () => (
<WalletButton
onConnect={connect}
onDisconnect={disconnect}
account={account}
error={error}
/>
),
}}
/>
<Stack.Screen
name="proposal"
options={{
title: 'Proposal Details',
}}
/>
<Stack.Screen
name="profile"
options={{
title: 'User Profile',
}}
/>
</Stack>
</SafeAreaProvider>
);
}
const WalletButton = ({ onConnect, onDisconnect, account, error }) => {
if (error) {
return (
<TouchableOpacity
style={[styles.button, styles.errorButton]}
onPress={onConnect}
>
<Text style={styles.buttonText}>Retry Connection</Text>
</TouchableOpacity>
);
}
if (account) {
return (
<TouchableOpacity style={styles.button} onPress={onDisconnect}>
<Text style={styles.buttonText}>
{account.slice(0, 6)}...{account.slice(-4)}
</Text>
</TouchableOpacity>
);
}
return (
<TouchableOpacity style={styles.button} onPress={onConnect}>
<Text style={styles.buttonText}>Connect Wallet</Text>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
backgroundColor: '#1976d2',
paddingHorizontal: 15,
paddingVertical: 8,
borderRadius: 20,
marginRight: 10,
},
errorButton: {
backgroundColor: '#d32f2f',
},
buttonText: {
color: 'white',
fontSize: 14,
fontWeight: '500',
},
});