@meshconnect/uwc-react 0.2.12 → 0.3.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.
@@ -1,14 +1,17 @@
1
- import type { WalletMetadata } from '@meshconnect/uwc-types';
1
+ import type { UseWalletReturn } from '@meshconnect/uwc-types';
2
2
  /**
3
3
  * Hook for accessing a specific wallet configuration
4
4
  * @param {string} walletId - The ID of the wallet to access
5
- * @returns {WalletMetadata} The wallet configuration
5
+ * @returns {UseWalletReturn} Object containing the wallet metadata and error if no wallet was found
6
6
  * @throws {Error} when used outside of ConnectionProvider
7
- * @throws {Error} when wallet with given id is not found
8
7
  * @example
9
8
  * ```tsx
10
- * const wallet = useWallet('metamask')
11
- * console.log(wallet.name) // 'MetaMask'
9
+ * const { wallet, error } = useWallet('metamask')
10
+ * if (wallet) {
11
+ * console.log(wallet.name) // 'MetaMask'
12
+ * } else {
13
+ * console.log(error?.message) // 'Wallet not found'
14
+ * }
12
15
  */
13
- export declare function useWallet(walletId: string): WalletMetadata;
16
+ export declare function useWallet(walletId: string): UseWalletReturn;
14
17
  //# sourceMappingURL=useWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWallet.d.ts","sourceRoot":"","sources":["../../src/hooks/useWallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAgB1D"}
1
+ {"version":3,"file":"useWallet.d.ts","sourceRoot":"","sources":["../../src/hooks/useWallet.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,wBAAwB,CAAA;AAG/B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CAuB3D"}
@@ -1,25 +1,33 @@
1
- import { useContext } from 'react';
1
+ import { useContext, useState } from 'react';
2
2
  import { ConnectionContext } from '../providers/ConnectionProvider';
3
+ import { WalletConnectorError } from '@meshconnect/uwc-types';
3
4
  /**
4
5
  * Hook for accessing a specific wallet configuration
5
6
  * @param {string} walletId - The ID of the wallet to access
6
- * @returns {WalletMetadata} The wallet configuration
7
+ * @returns {UseWalletReturn} Object containing the wallet metadata and error if no wallet was found
7
8
  * @throws {Error} when used outside of ConnectionProvider
8
- * @throws {Error} when wallet with given id is not found
9
9
  * @example
10
10
  * ```tsx
11
- * const wallet = useWallet('metamask')
12
- * console.log(wallet.name) // 'MetaMask'
11
+ * const { wallet, error } = useWallet('metamask')
12
+ * if (wallet) {
13
+ * console.log(wallet.name) // 'MetaMask'
14
+ * } else {
15
+ * console.log(error?.message) // 'Wallet not found'
16
+ * }
13
17
  */
14
18
  export function useWallet(walletId) {
15
19
  const context = useContext(ConnectionContext);
16
20
  if (!context) {
17
21
  throw new Error('useWallet must be used within a ConnectionProvider');
18
22
  }
23
+ const [error, setError] = useState(undefined);
19
24
  const selectedWallet = context.wallets.find((wallet) => wallet.id === walletId);
20
25
  if (!selectedWallet) {
21
- throw new Error(`Wallet with id '${walletId}' not found`);
26
+ setError(new WalletConnectorError({
27
+ type: 'unknown',
28
+ message: `Wallet with id '${walletId}' not found`
29
+ }));
22
30
  }
23
- return selectedWallet;
31
+ return { wallet: selectedWallet, error };
24
32
  }
25
33
  //# sourceMappingURL=useWallet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWallet.js","sourceRoot":"","sources":["../../src/hooks/useWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAE7C,IAAI,CAAC,OAAO,EAAE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Ac,EAAE,KAAK,EAAE,CAAA;AAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshconnect/uwc-react",
3
- "version": "0.2.12",
3
+ "version": "0.3.0",
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-types": "0.2.3",
20
- "@meshconnect/uwc-core": "0.2.10"
19
+ "@meshconnect/uwc-types": "0.2.4",
20
+ "@meshconnect/uwc-core": "0.2.11"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "react": "^18.0.0",
@@ -1,32 +1,47 @@
1
- import { useContext } from 'react'
1
+ import { useContext, useState } from 'react'
2
2
  import { ConnectionContext } from '../providers/ConnectionProvider'
3
- import type { WalletMetadata } from '@meshconnect/uwc-types'
3
+ import type {
4
+ WalletMetadata,
5
+ WalletError,
6
+ UseWalletReturn
7
+ } from '@meshconnect/uwc-types'
8
+ import { WalletConnectorError } from '@meshconnect/uwc-types'
4
9
 
5
10
  /**
6
11
  * Hook for accessing a specific wallet configuration
7
12
  * @param {string} walletId - The ID of the wallet to access
8
- * @returns {WalletMetadata} The wallet configuration
13
+ * @returns {UseWalletReturn} Object containing the wallet metadata and error if no wallet was found
9
14
  * @throws {Error} when used outside of ConnectionProvider
10
- * @throws {Error} when wallet with given id is not found
11
15
  * @example
12
16
  * ```tsx
13
- * const wallet = useWallet('metamask')
14
- * console.log(wallet.name) // 'MetaMask'
17
+ * const { wallet, error } = useWallet('metamask')
18
+ * if (wallet) {
19
+ * console.log(wallet.name) // 'MetaMask'
20
+ * } else {
21
+ * console.log(error?.message) // 'Wallet not found'
22
+ * }
15
23
  */
16
- export function useWallet(walletId: string): WalletMetadata {
24
+ export function useWallet(walletId: string): UseWalletReturn {
17
25
  const context = useContext(ConnectionContext)
18
26
 
19
27
  if (!context) {
20
28
  throw new Error('useWallet must be used within a ConnectionProvider')
21
29
  }
22
30
 
31
+ const [error, setError] = useState<WalletError | undefined>(undefined)
32
+
23
33
  const selectedWallet = context.wallets.find(
24
34
  (wallet: WalletMetadata) => wallet.id === walletId
25
35
  )
26
36
 
27
37
  if (!selectedWallet) {
28
- throw new Error(`Wallet with id '${walletId}' not found`)
38
+ setError(
39
+ new WalletConnectorError({
40
+ type: 'unknown',
41
+ message: `Wallet with id '${walletId}' not found`
42
+ })
43
+ )
29
44
  }
30
45
 
31
- return selectedWallet
46
+ return { wallet: selectedWallet, error }
32
47
  }