-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
136 lines (125 loc) · 3.57 KB
/
App.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
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
import React, {useState, useEffect, useCallback} from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {Image, View, Text, StyleSheet, TouchableOpacity} from 'react-native';
import {useWalletConnect} from '@walletconnect/react-native-dapp';
import ConnectedComponent from './components/ConnectedComponent';
export default function App() {
const [account, setAccount] = useState<string>('NOT CONNECTED');
const connector = useWalletConnect();
const connectWallet = useCallback(() => {
return connector.connect();
}, [connector]);
const killSession = useCallback(() => {
connector.killSession();
setAccount('NOT CONNECTED');
}, [connector]);
useEffect(() => {
if (connector.accounts != null && connector.accounts[0] != null) {
setAccount(connector.accounts[0]);
}
}, [connector]);
const shortenAddress = (address: string) => {
return `${address.slice(0, 6)}...${address.slice(
address.length - 4,
address.length,
)}`;
};
return (
<SafeAreaProvider style={styles.container}>
{!connector.connected && account === 'NOT CONNECTED' ? (
<>
<Image source={require('./assets/images/peanut_butter.png')} />
<View style={styles.mainContainer}>
<View style={styles.maxWidth}>
<Text style={styles.title}>Welcome to</Text>
<Text style={[styles.title, styles.bold]}>Whip & Slip</Text>
</View>
<TouchableOpacity
onPress={connectWallet}
style={styles.buttonStyle}>
<Text style={styles.buttonTextStyle}>Connect a Wallet</Text>
</TouchableOpacity>
</View>
</>
) : (
<>
<View style={styles.connectedContainer}>
<View>
<Image source={require('./assets/images/peanut_butter.png')} />
</View>
<View style={styles.connectedContent}>
<Text style={[styles.userAccount, styles.bold]}>Account</Text>
<Text style={[styles.userAccount]}>
{shortenAddress(account)}
</Text>
<TouchableOpacity
onPress={killSession}
style={styles.buttonStyle}>
<Text style={styles.buttonTextStyle}>Kill session</Text>
</TouchableOpacity>
</View>
</View>
<View style={styles.mainContainer}>
<ConnectedComponent account={account} connector={connector} />
</View>
</>
)}
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
bold: {
fontWeight: '700',
},
container: {
flex: 1,
backgroundColor: '#333138',
alignItems: 'center',
paddingTop: 60,
paddingBottom: 40,
},
mainContainer: {
width: '100%',
alignItems: 'center',
backgroundColor: '#e7a61a',
height: '80%',
position: 'absolute',
bottom: 0,
borderTopLeftRadius: 18,
borderTopRightRadius: 18,
paddingTop: 24,
},
title: {
color: '#ffffff',
fontSize: 24,
textAlign: 'center',
},
userAccount: {
color: '#ffffff',
fontSize: 18,
textAlign: 'center',
},
buttonStyle: {
paddingVertical: 6,
paddingHorizontal: 10,
borderColor: '#ffffff',
borderRadius: 8,
borderWidth: 2,
marginTop: 12,
},
buttonTextStyle: {
color: '#ffffff',
fontSize: 20,
fontWeight: '500',
},
maxWidth: {
maxWidth: 250,
},
connectedContainer: {
flexDirection: 'row',
},
connectedContent: {
justifyContent: 'center',
alignItems: 'flex-start',
},
});