@meshconnect/uwc-react 0.2.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.
Files changed (62) hide show
  1. package/README.md +222 -0
  2. package/dist/hooks/index.d.ts +9 -0
  3. package/dist/hooks/index.d.ts.map +1 -0
  4. package/dist/hooks/index.js +9 -0
  5. package/dist/hooks/index.js.map +1 -0
  6. package/dist/hooks/useConnection.d.ts +22 -0
  7. package/dist/hooks/useConnection.d.ts.map +1 -0
  8. package/dist/hooks/useConnection.js +98 -0
  9. package/dist/hooks/useConnection.js.map +1 -0
  10. package/dist/hooks/useDisconnect.d.ts +27 -0
  11. package/dist/hooks/useDisconnect.d.ts.map +1 -0
  12. package/dist/hooks/useDisconnect.js +44 -0
  13. package/dist/hooks/useDisconnect.js.map +1 -0
  14. package/dist/hooks/useNetworks.d.ts +16 -0
  15. package/dist/hooks/useNetworks.d.ts.map +1 -0
  16. package/dist/hooks/useNetworks.js +23 -0
  17. package/dist/hooks/useNetworks.js.map +1 -0
  18. package/dist/hooks/useSession.d.ts +18 -0
  19. package/dist/hooks/useSession.d.ts.map +1 -0
  20. package/dist/hooks/useSession.js +33 -0
  21. package/dist/hooks/useSession.js.map +1 -0
  22. package/dist/hooks/useSignMessage.d.ts +22 -0
  23. package/dist/hooks/useSignMessage.d.ts.map +1 -0
  24. package/dist/hooks/useSignMessage.js +61 -0
  25. package/dist/hooks/useSignMessage.js.map +1 -0
  26. package/dist/hooks/useSwitchNetwork.d.ts +28 -0
  27. package/dist/hooks/useSwitchNetwork.d.ts.map +1 -0
  28. package/dist/hooks/useSwitchNetwork.js +68 -0
  29. package/dist/hooks/useSwitchNetwork.js.map +1 -0
  30. package/dist/hooks/useTransaction.d.ts +25 -0
  31. package/dist/hooks/useTransaction.d.ts.map +1 -0
  32. package/dist/hooks/useTransaction.js +64 -0
  33. package/dist/hooks/useTransaction.js.map +1 -0
  34. package/dist/hooks/useWallets.d.ts +16 -0
  35. package/dist/hooks/useWallets.d.ts.map +1 -0
  36. package/dist/hooks/useWallets.js +23 -0
  37. package/dist/hooks/useWallets.js.map +1 -0
  38. package/dist/index.d.ts +3 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +3 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/providers/ConnectionProvider.d.ts +21 -0
  43. package/dist/providers/ConnectionProvider.d.ts.map +1 -0
  44. package/dist/providers/ConnectionProvider.js +31 -0
  45. package/dist/providers/ConnectionProvider.js.map +1 -0
  46. package/dist/providers/index.d.ts +2 -0
  47. package/dist/providers/index.d.ts.map +1 -0
  48. package/dist/providers/index.js +2 -0
  49. package/dist/providers/index.js.map +1 -0
  50. package/package.json +43 -0
  51. package/src/hooks/index.ts +8 -0
  52. package/src/hooks/useConnection.ts +123 -0
  53. package/src/hooks/useDisconnect.ts +52 -0
  54. package/src/hooks/useNetworks.ts +26 -0
  55. package/src/hooks/useSession.ts +37 -0
  56. package/src/hooks/useSignMessage.ts +69 -0
  57. package/src/hooks/useSwitchNetwork.ts +84 -0
  58. package/src/hooks/useTransaction.ts +79 -0
  59. package/src/hooks/useWallets.ts +26 -0
  60. package/src/index.ts +2 -0
  61. package/src/providers/ConnectionProvider.tsx +76 -0
  62. package/src/providers/index.ts +1 -0
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # @meshconnect/uwc-react
2
+
3
+ React hooks and providers for Universal Wallet Connector.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @meshconnect/uwc-react @meshconnect/uwc-core @meshconnect/uwc-types @meshconnect/uwc-constants
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Setup Provider
14
+
15
+ ```tsx
16
+ import { ConnectionProvider } from '@meshconnect/uwc-react'
17
+ import { mainnetNetwork, baseNetwork } from '@meshconnect/uwc-constants'
18
+ import type { WalletMetadata } from '@meshconnect/uwc-types'
19
+
20
+ // Define your wallets
21
+ const wallets: WalletMetadata[] = [
22
+ {
23
+ id: 'metamask',
24
+ name: 'MetaMask',
25
+ metadata: {
26
+ icon: 'https://...',
27
+ description: 'Connect with MetaMask'
28
+ },
29
+ extensionInjectedProvider: {
30
+ supportedNetworkIds: ['eip155:1', 'eip155:8453'],
31
+ // ... other config
32
+ },
33
+ walletConnectProvider: {
34
+ supportedNetworkIds: ['eip155:1', 'eip155:8453']
35
+ }
36
+ }
37
+ ]
38
+
39
+ function App() {
40
+ return (
41
+ <ConnectionProvider
42
+ networks={[mainnetNetwork, baseNetwork]}
43
+ wallets={wallets}
44
+ usingIntegratedBrowser={false}
45
+ >
46
+ {/* Your app */}
47
+ </ConnectionProvider>
48
+ )
49
+ }
50
+ ```
51
+
52
+ ### Using Hooks
53
+
54
+ #### useConnection
55
+
56
+ Connect to a specific wallet with different connection modes:
57
+
58
+ ```tsx
59
+ import { useConnection } from '@meshconnect/uwc-react'
60
+
61
+ function WalletButton({ walletId }: { walletId: string }) {
62
+ const { walletConnect, injected } = useConnection(walletId)
63
+
64
+ return (
65
+ <div>
66
+ {/* Injected connection */}
67
+ <button
68
+ onClick={() => injected.connect()}
69
+ disabled={injected.isLoading}
70
+ >
71
+ {injected.isLoading ? 'Connecting...' : 'Connect with Browser'}
72
+ </button>
73
+
74
+ {/* WalletConnect connection */}
75
+ <button
76
+ onClick={() => walletConnect.connect()}
77
+ disabled={walletConnect.isLoading}
78
+ >
79
+ {walletConnect.isLoading ? 'Connecting...' : 'Connect with WalletConnect'}
80
+ </button>
81
+
82
+ {/* Show QR code URI when available */}
83
+ {walletConnect.connectionURI && (
84
+ <div>Connection URI: {walletConnect.connectionURI}</div>
85
+ )}
86
+ </div>
87
+ )
88
+ }
89
+ ```
90
+
91
+ #### useSwitchNetwork
92
+
93
+ Switch between available networks:
94
+
95
+ ```tsx
96
+ import { useSwitchNetwork, useSession } from '@meshconnect/uwc-react'
97
+
98
+ function NetworkSwitcher() {
99
+ const { switchNetwork, isLoading, isWaitingForUserApproval } = useSwitchNetwork()
100
+ const session = useSession()
101
+
102
+ return (
103
+ <div>
104
+ <p>Current network: {session.activeNetwork?.name}</p>
105
+
106
+ <button
107
+ onClick={() => switchNetwork('eip155:1')}
108
+ disabled={isLoading}
109
+ >
110
+ {isWaitingForUserApproval
111
+ ? 'Waiting for approval...'
112
+ : isLoading
113
+ ? 'Switching...'
114
+ : 'Switch to Mainnet'}
115
+ </button>
116
+ </div>
117
+ )
118
+ }
119
+ ```
120
+
121
+ #### useDisconnect
122
+
123
+ Disconnect from the current wallet:
124
+
125
+ ```tsx
126
+ import { useDisconnect } from '@meshconnect/uwc-react'
127
+
128
+ function DisconnectButton() {
129
+ const { disconnect, isLoading } = useDisconnect()
130
+
131
+ return (
132
+ <button onClick={disconnect} disabled={isLoading}>
133
+ {isLoading ? 'Disconnecting...' : 'Disconnect'}
134
+ </button>
135
+ )
136
+ }
137
+ ```
138
+
139
+ #### useSession
140
+
141
+ Access the current session state:
142
+
143
+ ```tsx
144
+ import { useSession } from '@meshconnect/uwc-react'
145
+
146
+ function SessionInfo() {
147
+ const session = useSession()
148
+
149
+ return (
150
+ <div>
151
+ <p>Connected: {session.activeAddress ? 'Yes' : 'No'}</p>
152
+ <p>Address: {session.activeAddress}</p>
153
+ <p>Network: {session.activeNetwork?.name}</p>
154
+ <p>Wallet: {session.activeWallet?.name}</p>
155
+ <p>Mode: {session.connectionMode}</p>
156
+ </div>
157
+ )
158
+ }
159
+ ```
160
+
161
+ #### useWallets and useNetworks
162
+
163
+ Access available wallets and networks:
164
+
165
+ ```tsx
166
+ import { useWallets, useNetworks } from '@meshconnect/uwc-react'
167
+
168
+ function WalletList() {
169
+ const wallets = useWallets()
170
+ const networks = useNetworks()
171
+
172
+ return (
173
+ <div>
174
+ <h3>Available Wallets:</h3>
175
+ {wallets.map(wallet => (
176
+ <div key={wallet.id}>
177
+ {wallet.name}
178
+ </div>
179
+ ))}
180
+
181
+ <h3>Available Networks:</h3>
182
+ {networks.map(network => (
183
+ <div key={network.id}>
184
+ {network.name}
185
+ </div>
186
+ ))}
187
+ </div>
188
+ )
189
+ }
190
+ ```
191
+
192
+ ## API Reference
193
+
194
+ ### ConnectionProvider
195
+
196
+ Provider component that initializes the UniversalWalletConnector and provides it to child components.
197
+
198
+ Props:
199
+ - `networks: Network[]` - Array of supported networks
200
+ - `wallets: WalletMetadata[]` - Array of supported wallets
201
+ - `usingIntegratedBrowser?: boolean` - Whether using integrated browser (default: false)
202
+ - `walletConnectConfig?: WalletConnectConfig` - Optional WalletConnect configuration
203
+
204
+ ### Hooks
205
+
206
+ #### useConnection(walletId: string)
207
+ Returns an object with connection methods for both injected and WalletConnect modes.
208
+
209
+ #### useSwitchNetwork()
210
+ Returns methods and state for switching networks.
211
+
212
+ #### useDisconnect()
213
+ Returns disconnect method and loading state.
214
+
215
+ #### useSession()
216
+ Returns the current session state.
217
+
218
+ #### useWallets()
219
+ Returns the list of available wallets.
220
+
221
+ #### useNetworks()
222
+ Returns the list of available networks.
@@ -0,0 +1,9 @@
1
+ export * from './useConnection';
2
+ export * from './useSwitchNetwork';
3
+ export * from './useDisconnect';
4
+ export * from './useSession';
5
+ export * from './useWallets';
6
+ export * from './useNetworks';
7
+ export * from './useSignMessage';
8
+ export * from './useTransaction';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,9 @@
1
+ export * from './useConnection';
2
+ export * from './useSwitchNetwork';
3
+ export * from './useDisconnect';
4
+ export * from './useSession';
5
+ export * from './useWallets';
6
+ export * from './useNetworks';
7
+ export * from './useSignMessage';
8
+ export * from './useTransaction';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { UseConnectionReturn } from '@meshconnect/uwc-types';
2
+ /**
3
+ * Hook for managing wallet connections with both injected and WalletConnect modes
4
+ * @param walletId - The ID of the wallet to connect to (e.g., 'metamask', 'trust')
5
+ * @returns Connection methods and state for both injected and WalletConnect modes
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const { walletConnect, injected } = useConnection('metamask')
10
+ *
11
+ * // Connect with browser extension
12
+ * await injected.connect('eip155:1')
13
+ *
14
+ * // Connect with WalletConnect QR code
15
+ * await walletConnect.connect('eip155:1')
16
+ * if (walletConnect.connectionURI) {
17
+ * // Display QR code with walletConnect.connectionURI
18
+ * }
19
+ * ```
20
+ */
21
+ export declare function useConnection(walletId: string): UseConnectionReturn;
22
+ //# sourceMappingURL=useConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnection.d.ts","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,mBAAmB,EAEpB,MAAM,wBAAwB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,CA+FnE"}
@@ -0,0 +1,98 @@
1
+ import { useContext, useCallback, useState, useEffect } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for managing wallet connections with both injected and WalletConnect modes
5
+ * @param walletId - The ID of the wallet to connect to (e.g., 'metamask', 'trust')
6
+ * @returns Connection methods and state for both injected and WalletConnect modes
7
+ * @throws Error if used outside of ConnectionProvider
8
+ * @example
9
+ * ```tsx
10
+ * const { walletConnect, injected } = useConnection('metamask')
11
+ *
12
+ * // Connect with browser extension
13
+ * await injected.connect('eip155:1')
14
+ *
15
+ * // Connect with WalletConnect QR code
16
+ * await walletConnect.connect('eip155:1')
17
+ * if (walletConnect.connectionURI) {
18
+ * // Display QR code with walletConnect.connectionURI
19
+ * }
20
+ * ```
21
+ */
22
+ export function useConnection(walletId) {
23
+ const context = useContext(ConnectionContext);
24
+ if (!context) {
25
+ throw new Error('useConnection must be used within a ConnectionProvider');
26
+ }
27
+ const { connector, isReady } = context;
28
+ const [walletConnectLoading, setWalletConnectLoading] = useState(false);
29
+ const [injectedLoading, setInjectedLoading] = useState(false);
30
+ const [walletConnectError, setWalletConnectError] = useState();
31
+ const [injectedError, setInjectedError] = useState();
32
+ const [connectionURI, setConnectionURI] = useState();
33
+ const [walletConnectAvailable, setWalletConnectAvailable] = useState(false);
34
+ const [injectedAvailable, setInjectedAvailable] = useState(false);
35
+ // Update connection URI and availability when they change
36
+ useEffect(() => {
37
+ const checkState = () => {
38
+ const uri = connector.getConnectionURI();
39
+ setConnectionURI(uri);
40
+ // Check availability for both connection modes
41
+ const wcAvailable = connector.isConnectionModeAvailable('walletConnect', walletId);
42
+ const injAvailable = connector.isConnectionModeAvailable('injected', walletId);
43
+ setWalletConnectAvailable(wcAvailable);
44
+ setInjectedAvailable(injAvailable);
45
+ };
46
+ // Check initially and on state changes
47
+ checkState();
48
+ const unsubscribe = connector.subscribe(checkState);
49
+ return unsubscribe;
50
+ }, [connector, walletId]);
51
+ const connectWalletConnect = useCallback(async (networkId) => {
52
+ setWalletConnectLoading(true);
53
+ setWalletConnectError(undefined);
54
+ try {
55
+ await connector.connect('walletConnect', walletId, networkId);
56
+ }
57
+ catch (error) {
58
+ const walletError = error;
59
+ setWalletConnectError(walletError);
60
+ throw error;
61
+ }
62
+ finally {
63
+ setWalletConnectLoading(false);
64
+ }
65
+ }, [connector, walletId]);
66
+ const connectInjected = useCallback(async (networkId) => {
67
+ setInjectedLoading(true);
68
+ setInjectedError(undefined);
69
+ try {
70
+ await connector.connect('injected', walletId, networkId);
71
+ }
72
+ catch (error) {
73
+ const walletError = error;
74
+ setInjectedError(walletError);
75
+ throw error;
76
+ }
77
+ finally {
78
+ setInjectedLoading(false);
79
+ }
80
+ }, [connector, walletId]);
81
+ return {
82
+ walletConnect: {
83
+ connect: connectWalletConnect,
84
+ connectionURI,
85
+ isLoading: walletConnectLoading,
86
+ error: walletConnectError,
87
+ available: walletConnectAvailable
88
+ },
89
+ injected: {
90
+ connect: connectInjected,
91
+ isLoading: injectedLoading,
92
+ error: injectedError,
93
+ available: injectedAvailable
94
+ },
95
+ isReady
96
+ };
97
+ }
98
+ //# sourceMappingURL=useConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnection.js","sourceRoot":"","sources":["../../src/hooks/useConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAOnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAEtC,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACvE,MAAM,CAAC,eAAe,EAAE,kBAA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connect: () => Promise<void>;
3
+ isLoading: boolean;
4
+ }
5
+ /**
6
+ * Hook for disconnecting the current wallet
7
+ * @returns Disconnect function and loading state
8
+ * @throws Error if used outside of ConnectionProvider
9
+ * @example
10
+ * ```tsx
11
+ * const { disconnect, isLoading } = useDisconnect()
12
+ *
13
+ * const handleDisconnect = async () => {
14
+ * await disconnect()
15
+ * console.log('Wallet disconnected')
16
+ * }
17
+ *
18
+ * return (
19
+ * <button onClick={handleDisconnect} disabled={isLoading}>
20
+ * {isLoading ? 'Disconnecting...' : 'Disconnect'}
21
+ * </button>
22
+ * )
23
+ * ```
24
+ */
25
+ export declare function useDisconnect(): UseDisconnectReturn;
26
+ export {};
27
+ //# sourceMappingURL=useDisconnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDisconnect.d.ts","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAGA,UAAU,mBAAmB;IAC3B,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,SAAS,EAAE,OAAO,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,IAAI,mBAAmB,CAuBnD"}
@@ -0,0 +1,44 @@
1
+ import { useContext, useCallback, useState } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for disconnecting the current wallet
5
+ * @returns Disconnect function and loading state
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const { disconnect, isLoading } = useDisconnect()
10
+ *
11
+ * const handleDisconnect = async () => {
12
+ * await disconnect()
13
+ * console.log('Wallet disconnected')
14
+ * }
15
+ *
16
+ * return (
17
+ * <button onClick={handleDisconnect} disabled={isLoading}>
18
+ * {isLoading ? 'Disconnecting...' : 'Disconnect'}
19
+ * </button>
20
+ * )
21
+ * ```
22
+ */
23
+ export function useDisconnect() {
24
+ const context = useContext(ConnectionContext);
25
+ if (!context) {
26
+ throw new Error('useDisconnect must be used within a ConnectionProvider');
27
+ }
28
+ const { connector } = context;
29
+ const [isLoading, setIsLoading] = useState(false);
30
+ const disconnect = useCallback(async () => {
31
+ setIsLoading(true);
32
+ try {
33
+ await connector.disconnect();
34
+ }
35
+ finally {
36
+ setIsLoading(false);
37
+ }
38
+ }, [connector]);
39
+ return {
40
+ disconnect,
41
+ isLoading
42
+ };
43
+ }
44
+ //# sourceMappingURL=useDisconnect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDisconnect.js","sourceRoot":"","sources":["../../src/hooks/useDisconnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAOnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAC7B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEjD,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACxC,YAAY,CAAC,IAAI,CAAC,CAAA;QAClB,IAAI,CAAC;YACH,MAAM,SAAS,CAAC,UAAU,EAAE,CAAA;QAC9B,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO;QACL,UAAU;QACV,SAAS;KACV,CAAA;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Network } from '@meshconnect/uwc-types';
2
+ /**
3
+ * Hook for accessing the list of configured networks
4
+ * @returns Array of network configurations
5
+ * @throws Error if used outside of ConnectionProvider
6
+ * @example
7
+ * ```tsx
8
+ * const networks = useNetworks()
9
+ *
10
+ * networks.forEach(network => {
11
+ * console.log(`${network.name}: ${network.id}`)
12
+ * })
13
+ * ```
14
+ */
15
+ export declare function useNetworks(): Network[];
16
+ //# sourceMappingURL=useNetworks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNetworks.d.ts","sourceRoot":"","sources":["../../src/hooks/useNetworks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAErD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,IAAI,OAAO,EAAE,CAQvC"}
@@ -0,0 +1,23 @@
1
+ import { useContext } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for accessing the list of configured networks
5
+ * @returns Array of network configurations
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const networks = useNetworks()
10
+ *
11
+ * networks.forEach(network => {
12
+ * console.log(`${network.name}: ${network.id}`)
13
+ * })
14
+ * ```
15
+ */
16
+ export function useNetworks() {
17
+ const context = useContext(ConnectionContext);
18
+ if (!context) {
19
+ throw new Error('useNetworks must be used within a ConnectionProvider');
20
+ }
21
+ return context.networks;
22
+ }
23
+ //# sourceMappingURL=useNetworks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNetworks.js","sourceRoot":"","sources":["../../src/hooks/useNetworks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;IACzE,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,CAAA;AACzB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { UseSessionReturn } from '@meshconnect/uwc-types';
2
+ /**
3
+ * Hook for accessing the current wallet session state
4
+ * @returns Session information including active address, network, and connection details
5
+ * @throws Error if used outside of ConnectionProvider
6
+ * @example
7
+ * ```tsx
8
+ * const { activeAddress, activeNetwork, availableNetworks } = useSession()
9
+ *
10
+ * if (activeAddress) {
11
+ * console.log(`Connected: ${activeAddress}`)
12
+ * console.log(`Network: ${activeNetwork?.name}`)
13
+ * console.log(`Available networks: ${availableNetworks.length}`)
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function useSession(): UseSessionReturn;
18
+ //# sourceMappingURL=useSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSession.d.ts","sourceRoot":"","sources":["../../src/hooks/useSession.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAiB7C"}
@@ -0,0 +1,33 @@
1
+ import { useContext } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for accessing the current wallet session state
5
+ * @returns Session information including active address, network, and connection details
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const { activeAddress, activeNetwork, availableNetworks } = useSession()
10
+ *
11
+ * if (activeAddress) {
12
+ * console.log(`Connected: ${activeAddress}`)
13
+ * console.log(`Network: ${activeNetwork?.name}`)
14
+ * console.log(`Available networks: ${availableNetworks.length}`)
15
+ * }
16
+ * ```
17
+ */
18
+ export function useSession() {
19
+ const context = useContext(ConnectionContext);
20
+ if (!context) {
21
+ throw new Error('useSession must be used within a ConnectionProvider');
22
+ }
23
+ const { session } = context;
24
+ return {
25
+ session,
26
+ activeAddress: session.activeAddress,
27
+ activeNetwork: session.activeNetwork,
28
+ availableNetworks: session.availableNetworks,
29
+ activeConnector: session.connectionMode,
30
+ availableAddresses: session.availableAddresses
31
+ };
32
+ }
33
+ //# sourceMappingURL=useSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSession.js","sourceRoot":"","sources":["../../src/hooks/useSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACxE,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAE3B,OAAO;QACL,OAAO;QACP,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;QAC5C,eAAe,EAAE,OAAO,CAAC,cAAc;QACvC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;KAC/C,CAAA;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { UseSignMessageReturn } from '@meshconnect/uwc-types';
2
+ /**
3
+ * Hook for signing messages with the connected wallet
4
+ * @returns Object containing signMessage function, loading state, and last signature
5
+ * @throws Error if used outside of ConnectionProvider
6
+ * @example
7
+ * ```tsx
8
+ * const { signMessage, isLoading, signature } = useSignMessage()
9
+ *
10
+ * const handleSign = async () => {
11
+ * try {
12
+ * const sig = await signMessage('Hello World')
13
+ * console.log('Signature:', sig)
14
+ * // signature state will also be updated with the result
15
+ * } catch (error) {
16
+ * console.error('Failed to sign:', error)
17
+ * }
18
+ * }
19
+ * ```
20
+ */
21
+ export declare function useSignMessage(): UseSignMessageReturn;
22
+ //# sourceMappingURL=useSignMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSignMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSignMessage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAe,MAAM,wBAAwB,CAAA;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,IAAI,oBAAoB,CA6CrD"}
@@ -0,0 +1,61 @@
1
+ import { useContext, useCallback, useState } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for signing messages with the connected wallet
5
+ * @returns Object containing signMessage function, loading state, and last signature
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const { signMessage, isLoading, signature } = useSignMessage()
10
+ *
11
+ * const handleSign = async () => {
12
+ * try {
13
+ * const sig = await signMessage('Hello World')
14
+ * console.log('Signature:', sig)
15
+ * // signature state will also be updated with the result
16
+ * } catch (error) {
17
+ * console.error('Failed to sign:', error)
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export function useSignMessage() {
23
+ const context = useContext(ConnectionContext);
24
+ if (!context) {
25
+ throw new Error('useSignMessage must be used within a ConnectionProvider');
26
+ }
27
+ const { connector, session } = context;
28
+ const [isLoading, setIsLoading] = useState(false);
29
+ const [signature, setSignature] = useState();
30
+ const [error, setError] = useState();
31
+ const signMessage = useCallback(async (message) => {
32
+ if (!session.activeAddress) {
33
+ throw new Error('No wallet connected');
34
+ }
35
+ if (!message) {
36
+ throw new Error('Message is required');
37
+ }
38
+ setIsLoading(true);
39
+ setError(undefined);
40
+ try {
41
+ const sig = await connector.signMessage(message);
42
+ setSignature(sig);
43
+ return sig;
44
+ }
45
+ catch (err) {
46
+ const walletError = err;
47
+ setError(walletError);
48
+ throw err;
49
+ }
50
+ finally {
51
+ setIsLoading(false);
52
+ }
53
+ }, [connector, session.activeAddress]);
54
+ return {
55
+ signMessage,
56
+ isLoading,
57
+ signature,
58
+ error
59
+ };
60
+ }
61
+ //# sourceMappingURL=useSignMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSignMessage.js","sourceRoot":"","sources":["../../src/hooks/useSignMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;IAC5E,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IACtC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,EAAsB,CAAA;IAChE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAA2B,CAAA;IAE7D,MAAM,WAAW,GAAG,WAAW,CAC7B,KAAK,EAAE,OAAe,EAAmB,EAAE;QACzC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACxC,CAAC;QAED,YAAY,CAAC,IAAI,CAAC,CAAA;QAClB,QAAQ,CAAC,SAAS,CAAC,CAAA;QACnB,IA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