@meshconnect/uwc-react 0.3.17 → 0.3.19

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.
@@ -7,4 +7,5 @@ export * from './useWallet';
7
7
  export * from './useNetworks';
8
8
  export * from './useSignMessage';
9
9
  export * from './useTransaction';
10
+ export * from './useWalletCapabilities';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA"}
@@ -7,4 +7,5 @@ export * from './useWallet';
7
7
  export * from './useNetworks';
8
8
  export * from './useSignMessage';
9
9
  export * from './useTransaction';
10
+ export * from './useWalletCapabilities';
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { UseWalletCapabilitiesReturn } from '@meshconnect/uwc-types';
2
+ /**
3
+ * Hook for managing wallet capabilities
4
+ * @returns Wallet capabilities state and a fetch function to manually fetch capabilities
5
+ * @throws Error if used outside of ConnectionProvider
6
+ * @example
7
+ * ```tsx
8
+ * const { capabilities, networkCapabilities, isLoading, error, fetchCapabilities } = useWalletCapabilities()
9
+ *
10
+ * const handleFetchCapabilities = async () => {
11
+ * await fetchCapabilities()
12
+ * }
13
+ *
14
+ * if (isLoading) {
15
+ * return <div>Loading capabilities...</div>
16
+ * }
17
+ *
18
+ * if (capabilities?.['eip155:1']?.atomicBatching.supported) {
19
+ * console.log('Atomic batching is supported')
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function useWalletCapabilities(): UseWalletCapabilitiesReturn;
24
+ //# sourceMappingURL=useWalletCapabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWalletCapabilities.d.ts","sourceRoot":"","sources":["../../src/hooks/useWalletCapabilities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,2BAA2B,EAE5B,MAAM,wBAAwB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,qBAAqB,IAAI,2BAA2B,CAiDnE"}
@@ -0,0 +1,66 @@
1
+ import { useContext, useCallback, useState } from 'react';
2
+ import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ /**
4
+ * Hook for managing wallet capabilities
5
+ * @returns Wallet capabilities state and a fetch function to manually fetch capabilities
6
+ * @throws Error if used outside of ConnectionProvider
7
+ * @example
8
+ * ```tsx
9
+ * const { capabilities, networkCapabilities, isLoading, error, fetchCapabilities } = useWalletCapabilities()
10
+ *
11
+ * const handleFetchCapabilities = async () => {
12
+ * await fetchCapabilities()
13
+ * }
14
+ *
15
+ * if (isLoading) {
16
+ * return <div>Loading capabilities...</div>
17
+ * }
18
+ *
19
+ * if (capabilities?.['eip155:1']?.atomicBatching.supported) {
20
+ * console.log('Atomic batching is supported')
21
+ * }
22
+ * ```
23
+ */
24
+ export function useWalletCapabilities() {
25
+ const context = useContext(ConnectionContext);
26
+ if (!context) {
27
+ throw new Error('useWalletCapabilities must be used within a ConnectionProvider');
28
+ }
29
+ const { connector, session } = context;
30
+ const [isLoading, setIsLoading] = useState(false);
31
+ const [error, setError] = useState();
32
+ // Manual fetch function to be called from the app
33
+ const fetchCapabilities = useCallback(async () => {
34
+ // If no active session or address, clear capabilities
35
+ if (!session?.activeAddress || !session?.connectionMode) {
36
+ return;
37
+ }
38
+ setIsLoading(true);
39
+ setError(undefined);
40
+ try {
41
+ // Use provided network or find the active network from session
42
+ const networkToUse = connector
43
+ .getNetworks()
44
+ .find(n => n.id === session.activeNetwork?.id);
45
+ await connector.getWalletCapabilities(session.activeAddress, networkToUse);
46
+ }
47
+ catch (err) {
48
+ const walletError = err;
49
+ setError(walletError);
50
+ }
51
+ finally {
52
+ setIsLoading(false);
53
+ }
54
+ }, [
55
+ session?.activeAddress,
56
+ session?.connectionMode,
57
+ session?.activeNetwork,
58
+ connector
59
+ ]);
60
+ return {
61
+ isLoading,
62
+ error,
63
+ fetchCapabilities
64
+ };
65
+ }
66
+ //# sourceMappingURL=use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AAG,EAAE,CAAC;YACb,MAAM,WAAW,GAAG,GAAkB,CAAA;YACtC,QAAQ,CAAC,WAAW,CAAC,CAAA;QACvB,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACH,CAAC,EAAE;QACD,OAAO,EAAE,aAAa;QACtB,OAAO,EAAE,cAAc;QACvB,OAAO,EAAE,aAAa;QACtB,SAAS;KACV,CAAC,CAAA;IAEF,OAAO;QACL,SAAS;QACT,KAAK;QACL,iBAAiB;KAClB,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshconnect/uwc-react",
3
- "version": "0.3.17",
3
+ "version": "0.3.19",
4
4
  "description": "React hooks and components for Universal Wallet Connector",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,8 +16,8 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@meshconnect/uwc-core": "0.3.8",
20
- "@meshconnect/uwc-types": "0.4.0"
19
+ "@meshconnect/uwc-core": "0.3.10",
20
+ "@meshconnect/uwc-types": "0.4.2"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": "^18.0.0",
@@ -7,3 +7,4 @@ export * from './useWallet'
7
7
  export * from './useNetworks'
8
8
  export * from './useSignMessage'
9
9
  export * from './useTransaction'
10
+ export * from './useWalletCapabilities'
@@ -0,0 +1,78 @@
1
+ import { useContext, useCallback, useState } from 'react'
2
+ import { ConnectionContext } from '../providers/ConnectionProvider'
3
+ import type {
4
+ UseWalletCapabilitiesReturn,
5
+ WalletError
6
+ } from '@meshconnect/uwc-types'
7
+
8
+ /**
9
+ * Hook for managing wallet capabilities
10
+ * @returns Wallet capabilities state and a fetch function to manually fetch capabilities
11
+ * @throws Error if used outside of ConnectionProvider
12
+ * @example
13
+ * ```tsx
14
+ * const { capabilities, networkCapabilities, isLoading, error, fetchCapabilities } = useWalletCapabilities()
15
+ *
16
+ * const handleFetchCapabilities = async () => {
17
+ * await fetchCapabilities()
18
+ * }
19
+ *
20
+ * if (isLoading) {
21
+ * return <div>Loading capabilities...</div>
22
+ * }
23
+ *
24
+ * if (capabilities?.['eip155:1']?.atomicBatching.supported) {
25
+ * console.log('Atomic batching is supported')
26
+ * }
27
+ * ```
28
+ */
29
+ export function useWalletCapabilities(): UseWalletCapabilitiesReturn {
30
+ const context = useContext(ConnectionContext)
31
+
32
+ if (!context) {
33
+ throw new Error(
34
+ 'useWalletCapabilities must be used within a ConnectionProvider'
35
+ )
36
+ }
37
+
38
+ const { connector, session } = context
39
+
40
+ const [isLoading, setIsLoading] = useState(false)
41
+ const [error, setError] = useState<WalletError | undefined>()
42
+
43
+ // Manual fetch function to be called from the app
44
+ const fetchCapabilities = useCallback(async () => {
45
+ // If no active session or address, clear capabilities
46
+ if (!session?.activeAddress || !session?.connectionMode) {
47
+ return
48
+ }
49
+
50
+ setIsLoading(true)
51
+ setError(undefined)
52
+
53
+ try {
54
+ // Use provided network or find the active network from session
55
+ const networkToUse = connector
56
+ .getNetworks()
57
+ .find(n => n.id === session.activeNetwork?.id)
58
+
59
+ await connector.getWalletCapabilities(session.activeAddress, networkToUse)
60
+ } catch (err) {
61
+ const walletError = err as WalletError
62
+ setError(walletError)
63
+ } finally {
64
+ setIsLoading(false)
65
+ }
66
+ }, [
67
+ session?.activeAddress,
68
+ session?.connectionMode,
69
+ session?.activeNetwork,
70
+ connector
71
+ ])
72
+
73
+ return {
74
+ isLoading,
75
+ error,
76
+ fetchCapabilities
77
+ }
78
+ }