@meshconnect/uwc-react 0.2.3 → 0.2.4
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,14 @@
|
|
|
1
|
+
import type { WalletMetadata } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing a specific wallet configuration
|
|
4
|
+
* @param {string} walletId - The ID of the wallet to access
|
|
5
|
+
* @returns {WalletMetadata} The wallet configuration
|
|
6
|
+
* @throws {Error} when used outside of ConnectionProvider
|
|
7
|
+
* @throws {Error} when wallet with given id is not found
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const wallet = useWallet('metamask')
|
|
11
|
+
* console.log(wallet.name) // 'MetaMask'
|
|
12
|
+
*/
|
|
13
|
+
export declare function useWallet(walletId: string): WalletMetadata;
|
|
14
|
+
//# sourceMappingURL=useWallet.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { ConnectionContext } from '../providers/ConnectionProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for accessing a specific wallet configuration
|
|
5
|
+
* @param {string} walletId - The ID of the wallet to access
|
|
6
|
+
* @returns {WalletMetadata} The wallet configuration
|
|
7
|
+
* @throws {Error} when used outside of ConnectionProvider
|
|
8
|
+
* @throws {Error} when wallet with given id is not found
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const wallet = useWallet('metamask')
|
|
12
|
+
* console.log(wallet.name) // 'MetaMask'
|
|
13
|
+
*/
|
|
14
|
+
export function useWallet(walletId) {
|
|
15
|
+
const context = useContext(ConnectionContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('useWallet must be used within a ConnectionProvider');
|
|
18
|
+
}
|
|
19
|
+
const selectedWallet = context.wallets.find((wallet) => wallet.id === walletId);
|
|
20
|
+
if (!selectedWallet) {
|
|
21
|
+
throw new Error(`Wallet with id '${walletId}' not found`);
|
|
22
|
+
}
|
|
23
|
+
return selectedWallet;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=useWallet.js.map
|
|
@@ -0,0 +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,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACvE,CAAC;IAED,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CACzC,CAAC,MAAsB,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,QAAQ,CACnD,CAAA;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,aAAa,CAAC,CAAA;IAC3D,CAAC;IAED,OAAO,cAAc,CAAA;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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-
|
|
20
|
-
"@meshconnect/uwc-
|
|
19
|
+
"@meshconnect/uwc-types": "0.2.2",
|
|
20
|
+
"@meshconnect/uwc-core": "0.2.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"react": "^18.0.0",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ConnectionContext } from '../providers/ConnectionProvider'
|
|
3
|
+
import type { WalletMetadata } from '@meshconnect/uwc-types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Hook for accessing a specific wallet configuration
|
|
7
|
+
* @param {string} walletId - The ID of the wallet to access
|
|
8
|
+
* @returns {WalletMetadata} The wallet configuration
|
|
9
|
+
* @throws {Error} when used outside of ConnectionProvider
|
|
10
|
+
* @throws {Error} when wallet with given id is not found
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const wallet = useWallet('metamask')
|
|
14
|
+
* console.log(wallet.name) // 'MetaMask'
|
|
15
|
+
*/
|
|
16
|
+
export function useWallet(walletId: string): WalletMetadata {
|
|
17
|
+
const context = useContext(ConnectionContext)
|
|
18
|
+
|
|
19
|
+
if (!context) {
|
|
20
|
+
throw new Error('useWallet must be used within a ConnectionProvider')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const selectedWallet = context.wallets.find(
|
|
24
|
+
(wallet: WalletMetadata) => wallet.id === walletId
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
if (!selectedWallet) {
|
|
28
|
+
throw new Error(`Wallet with id '${walletId}' not found`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return selectedWallet
|
|
32
|
+
}
|