@sudobility/web3-components-rn 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ import React from 'react';
2
+ import { View, Text, type ViewProps } from 'react-native';
3
+ import { cn } from '@sudobility/components-rn';
4
+
5
+ export type WalletProvider =
6
+ | 'metamask'
7
+ | 'walletconnect'
8
+ | 'coinbase'
9
+ | 'rainbow'
10
+ | 'phantom'
11
+ | 'trust'
12
+ | 'generic';
13
+
14
+ export interface WalletIconProps extends ViewProps {
15
+ provider: WalletProvider;
16
+ size?: 'sm' | 'md' | 'lg';
17
+ showLabel?: boolean;
18
+ }
19
+
20
+ const walletConfig: Record<WalletProvider, { label: string; emoji: string; color: string }> = {
21
+ metamask: { label: 'MetaMask', emoji: '🦊', color: 'bg-orange-100 dark:bg-orange-900/30' },
22
+ walletconnect: { label: 'WalletConnect', emoji: '🔗', color: 'bg-blue-100 dark:bg-blue-900/30' },
23
+ coinbase: { label: 'Coinbase', emoji: '🔵', color: 'bg-blue-100 dark:bg-blue-900/30' },
24
+ rainbow: { label: 'Rainbow', emoji: '🌈', color: 'bg-purple-100 dark:bg-purple-900/30' },
25
+ phantom: { label: 'Phantom', emoji: '👻', color: 'bg-purple-100 dark:bg-purple-900/30' },
26
+ trust: { label: 'Trust Wallet', emoji: '🛡️', color: 'bg-blue-100 dark:bg-blue-900/30' },
27
+ generic: { label: 'Wallet', emoji: '💳', color: 'bg-gray-100 dark:bg-gray-800' },
28
+ };
29
+
30
+ const sizeClasses = {
31
+ sm: 'w-6 h-6',
32
+ md: 'w-10 h-10',
33
+ lg: 'w-14 h-14',
34
+ };
35
+
36
+ const textSizes = {
37
+ sm: 'text-sm',
38
+ md: 'text-lg',
39
+ lg: 'text-2xl',
40
+ };
41
+
42
+ /**
43
+ * Wallet icon component for displaying wallet provider icons
44
+ */
45
+ export const WalletIcon: React.FC<WalletIconProps> = ({
46
+ provider,
47
+ size = 'md',
48
+ showLabel = false,
49
+ className,
50
+ ...props
51
+ }) => {
52
+ const config = walletConfig[provider] || walletConfig.generic;
53
+
54
+ return (
55
+ <View
56
+ className={cn('flex-row items-center gap-2', className)}
57
+ accessibilityLabel={config.label}
58
+ {...props}
59
+ >
60
+ <View
61
+ className={cn(
62
+ 'rounded-full items-center justify-center',
63
+ sizeClasses[size],
64
+ config.color
65
+ )}
66
+ >
67
+ <Text className={textSizes[size]}>{config.emoji}</Text>
68
+ </View>
69
+ {showLabel && (
70
+ <Text className="text-gray-900 dark:text-white font-medium">
71
+ {config.label}
72
+ </Text>
73
+ )}
74
+ </View>
75
+ );
76
+ };
@@ -0,0 +1,268 @@
1
+ import React from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ Pressable,
6
+ ActivityIndicator,
7
+ Linking,
8
+ type ViewProps,
9
+ } from 'react-native';
10
+ import { cn } from '@sudobility/components-rn';
11
+ import { WalletIcon, type WalletProvider } from './WalletIcon';
12
+
13
+ export interface WalletOption {
14
+ id: string;
15
+ name: string;
16
+ icon?: string;
17
+ available: boolean;
18
+ connecting?: boolean;
19
+ chainType: 'evm' | 'solana';
20
+ connector?: unknown;
21
+ onPress: () => void;
22
+ }
23
+
24
+ export interface WalletSelectionButtonProps extends ViewProps {
25
+ wallet: WalletOption;
26
+ disabled?: boolean;
27
+ statusLabels?: {
28
+ available: string;
29
+ notAvailable: string;
30
+ };
31
+ }
32
+
33
+ const getProviderFromName = (name: string): WalletProvider => {
34
+ const lower = name.toLowerCase();
35
+ if (lower.includes('metamask')) return 'metamask';
36
+ if (lower.includes('walletconnect')) return 'walletconnect';
37
+ if (lower.includes('coinbase')) return 'coinbase';
38
+ if (lower.includes('rainbow')) return 'rainbow';
39
+ if (lower.includes('phantom')) return 'phantom';
40
+ if (lower.includes('trust')) return 'trust';
41
+ return 'generic';
42
+ };
43
+
44
+ export const WalletSelectionButton: React.FC<WalletSelectionButtonProps> = ({
45
+ wallet,
46
+ disabled = false,
47
+ className,
48
+ statusLabels = { available: 'Available', notAvailable: 'Not Available' },
49
+ ...props
50
+ }) => {
51
+ const isDisabled = disabled || !wallet.available;
52
+
53
+ return (
54
+ <Pressable
55
+ onPress={wallet.onPress}
56
+ disabled={isDisabled}
57
+ accessibilityRole="button"
58
+ accessibilityLabel={`Connect ${wallet.name} wallet for ${wallet.chainType === 'solana' ? 'Solana' : 'Ethereum'} network`}
59
+ accessibilityState={{ disabled: isDisabled }}
60
+ className={cn(
61
+ 'w-full flex-row items-center justify-between p-4',
62
+ 'border border-gray-200 dark:border-gray-700 rounded-lg',
63
+ 'bg-white dark:bg-gray-900',
64
+ 'active:bg-gray-50 dark:active:bg-gray-700',
65
+ isDisabled && 'opacity-50',
66
+ className
67
+ )}
68
+ {...props}
69
+ >
70
+ <View className="flex-row items-center gap-3">
71
+ <WalletIcon provider={getProviderFromName(wallet.name)} size="md" />
72
+ <View>
73
+ <Text className="font-medium text-gray-900 dark:text-white">
74
+ {wallet.name}
75
+ </Text>
76
+ <Text
77
+ className={cn(
78
+ 'text-xs',
79
+ wallet.available
80
+ ? 'text-green-600 dark:text-green-400'
81
+ : 'text-red-600 dark:text-red-400'
82
+ )}
83
+ >
84
+ {wallet.available
85
+ ? statusLabels.available
86
+ : statusLabels.notAvailable}
87
+ </Text>
88
+ </View>
89
+ </View>
90
+
91
+ {wallet.connecting && (
92
+ <ActivityIndicator
93
+ size="small"
94
+ color={wallet.chainType === 'solana' ? '#9333ea' : '#2563eb'}
95
+ />
96
+ )}
97
+ </Pressable>
98
+ );
99
+ };
100
+
101
+ export interface WalletTabProps {
102
+ active: boolean;
103
+ onPress: () => void;
104
+ icon: string;
105
+ label: string;
106
+ color: 'blue' | 'purple';
107
+ }
108
+
109
+ export const WalletTab: React.FC<WalletTabProps> = ({
110
+ active,
111
+ onPress,
112
+ icon,
113
+ label,
114
+ color,
115
+ }) => {
116
+ return (
117
+ <Pressable
118
+ onPress={onPress}
119
+ accessibilityRole="tab"
120
+ accessibilityState={{ selected: active }}
121
+ className={cn(
122
+ 'flex-1 py-2 px-4 rounded-md',
123
+ active
124
+ ? color === 'blue'
125
+ ? 'bg-white dark:bg-gray-800'
126
+ : 'bg-white dark:bg-gray-800'
127
+ : 'bg-transparent'
128
+ )}
129
+ >
130
+ <View className="flex-row items-center justify-center gap-2">
131
+ <Text
132
+ className={cn(
133
+ 'text-base',
134
+ active
135
+ ? color === 'blue'
136
+ ? 'text-blue-600 dark:text-blue-400'
137
+ : 'text-purple-600 dark:text-purple-400'
138
+ : 'text-gray-600 dark:text-gray-400'
139
+ )}
140
+ >
141
+ {icon}
142
+ </Text>
143
+ <Text
144
+ className={cn(
145
+ 'font-medium',
146
+ active
147
+ ? color === 'blue'
148
+ ? 'text-blue-600 dark:text-blue-400'
149
+ : 'text-purple-600 dark:text-purple-400'
150
+ : 'text-gray-600 dark:text-gray-400'
151
+ )}
152
+ >
153
+ {label}
154
+ </Text>
155
+ </View>
156
+ </Pressable>
157
+ );
158
+ };
159
+
160
+ export interface WalletSelectionGridProps extends ViewProps {
161
+ evmWallets: WalletOption[];
162
+ solanaWallets: WalletOption[];
163
+ activeTab: 'ethereum' | 'solana';
164
+ onTabChange: (tab: 'ethereum' | 'solana') => void;
165
+ connectingWallet?: string | null;
166
+ labels?: {
167
+ ethereum?: string;
168
+ solana?: string;
169
+ available?: string;
170
+ notAvailable?: string;
171
+ noWalletText?: string;
172
+ installMetaMask?: string;
173
+ installPhantom?: string;
174
+ };
175
+ }
176
+
177
+ export const WalletSelectionGrid: React.FC<WalletSelectionGridProps> = ({
178
+ evmWallets,
179
+ solanaWallets,
180
+ activeTab,
181
+ onTabChange,
182
+ connectingWallet,
183
+ className,
184
+ labels = {},
185
+ ...props
186
+ }) => {
187
+ const defaultLabels = {
188
+ ethereum: 'Ethereum',
189
+ solana: 'Solana',
190
+ available: 'Available',
191
+ notAvailable: 'Not Available',
192
+ noWalletText: "Don't have a wallet?",
193
+ installMetaMask: 'Install MetaMask',
194
+ installPhantom: 'Install Phantom',
195
+ };
196
+
197
+ const finalLabels = { ...defaultLabels, ...labels };
198
+ const currentWallets = activeTab === 'ethereum' ? evmWallets : solanaWallets;
199
+
200
+ const handleInstallPress = () => {
201
+ const url =
202
+ activeTab === 'ethereum'
203
+ ? 'https://metamask.io/download/'
204
+ : 'https://phantom.app/download';
205
+ Linking.openURL(url);
206
+ };
207
+
208
+ return (
209
+ <View className={cn('gap-6', className)} {...props}>
210
+ {/* Tab Navigation */}
211
+ <View className="flex-row gap-1 p-1 bg-gray-100 dark:bg-gray-700 rounded-lg">
212
+ <WalletTab
213
+ active={activeTab === 'ethereum'}
214
+ onPress={() => onTabChange('ethereum')}
215
+ icon="⟠"
216
+ label={finalLabels.ethereum}
217
+ color="blue"
218
+ />
219
+ <WalletTab
220
+ active={activeTab === 'solana'}
221
+ onPress={() => onTabChange('solana')}
222
+ icon="◎"
223
+ label={finalLabels.solana}
224
+ color="purple"
225
+ />
226
+ </View>
227
+
228
+ {/* Wallet List */}
229
+ <View className="gap-3">
230
+ {currentWallets.map((wallet) => (
231
+ <WalletSelectionButton
232
+ key={wallet.id}
233
+ wallet={{
234
+ ...wallet,
235
+ connecting: connectingWallet === wallet.name,
236
+ }}
237
+ disabled={!!connectingWallet}
238
+ statusLabels={{
239
+ available: finalLabels.available,
240
+ notAvailable: finalLabels.notAvailable,
241
+ }}
242
+ />
243
+ ))}
244
+ </View>
245
+
246
+ {/* Help Text */}
247
+ <View className="items-center pt-2">
248
+ <Text className="text-sm text-gray-600 dark:text-gray-400">
249
+ {finalLabels.noWalletText}{' '}
250
+ </Text>
251
+ <Pressable onPress={handleInstallPress} accessibilityRole="link">
252
+ <Text
253
+ className={cn(
254
+ 'text-sm font-medium',
255
+ activeTab === 'ethereum'
256
+ ? 'text-blue-600 dark:text-blue-400'
257
+ : 'text-purple-600 dark:text-purple-400'
258
+ )}
259
+ >
260
+ {activeTab === 'ethereum'
261
+ ? finalLabels.installMetaMask
262
+ : finalLabels.installPhantom}
263
+ </Text>
264
+ </Pressable>
265
+ </View>
266
+ </View>
267
+ );
268
+ };
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @sudobility/web3-components-rn
3
+ * React Native Web3 components for Sudobility
4
+ */
5
+
6
+ export { AddressLabel, type AddressLabelProps } from './AddressLabel';
7
+ export { CryptoPortfolio, type CryptoPortfolioProps } from './CryptoPortfolio';
8
+ export { GasTracker, type GasTrackerProps } from './GasTracker';
9
+ export { NftGallery, type NftGalleryProps } from './NftGallery';
10
+ export { TokenSwap, type TokenSwapProps } from './TokenSwap';
11
+ export { WalletConnect, type WalletConnectProps } from './WalletConnect';
12
+ export { WalletIcon, type WalletIconProps, type WalletProvider } from './WalletIcon';
13
+ export {
14
+ WalletSelectionButton,
15
+ WalletSelectionGrid,
16
+ WalletTab,
17
+ type WalletOption,
18
+ type WalletSelectionButtonProps,
19
+ type WalletSelectionGridProps,
20
+ type WalletTabProps,
21
+ } from './WalletSelection';
@@ -0,0 +1,23 @@
1
+ // Type declarations for NativeWind className prop
2
+ import 'react-native';
3
+
4
+ declare module 'react-native' {
5
+ interface ViewProps {
6
+ className?: string;
7
+ }
8
+ interface TextProps {
9
+ className?: string;
10
+ }
11
+ interface ImageProps {
12
+ className?: string;
13
+ }
14
+ interface PressableProps {
15
+ className?: string;
16
+ }
17
+ interface TouchableOpacityProps {
18
+ className?: string;
19
+ }
20
+ interface ScrollViewProps {
21
+ className?: string;
22
+ }
23
+ }