@meshconnect/uwc-react 0.3.5 → 0.3.7
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.
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/useConnection.d.ts +22 -0
- package/dist/hooks/useDisconnect.d.ts +27 -0
- package/dist/hooks/useNetworks.d.ts +16 -0
- package/dist/hooks/useSession.d.ts +18 -0
- package/dist/hooks/useSignMessage.d.ts +22 -0
- package/dist/hooks/useSwitchNetwork.d.ts +28 -0
- package/dist/hooks/useTransaction.d.ts +25 -0
- package/dist/hooks/useWallet.d.ts +17 -0
- package/dist/hooks/useWallets.d.ts +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/providers/ConnectionProvider.d.ts +21 -0
- package/dist/providers/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './useConnection';
|
|
2
|
+
export * from './useSwitchNetwork';
|
|
3
|
+
export * from './useDisconnect';
|
|
4
|
+
export * from './useSession';
|
|
5
|
+
export * from './useWallets';
|
|
6
|
+
export * from './useWallet';
|
|
7
|
+
export * from './useNetworks';
|
|
8
|
+
export * from './useSignMessage';
|
|
9
|
+
export * from './useTransaction';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,27 @@
|
|
|
1
|
+
interface UseDisconnectReturn {
|
|
2
|
+
disconnect: () => 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,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,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,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,28 @@
|
|
|
1
|
+
import type { UseSwitchNetworkReturn } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for switching networks on the connected wallet
|
|
4
|
+
* @returns Network switching function and loading states
|
|
5
|
+
* @throws Error if used outside of ConnectionProvider
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const { switchNetwork, isLoading, isWaitingForUserApproval } = useSwitchNetwork()
|
|
9
|
+
*
|
|
10
|
+
* const handleSwitch = async () => {
|
|
11
|
+
* try {
|
|
12
|
+
* await switchNetwork('eip155:8453') // Switch to Base
|
|
13
|
+
* } catch (error) {
|
|
14
|
+
* console.error('Network switch failed:', error)
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Show loading UI
|
|
19
|
+
* if (isWaitingForUserApproval) {
|
|
20
|
+
* return <div>Please approve in your wallet...</div>
|
|
21
|
+
* }
|
|
22
|
+
* if (isLoading) {
|
|
23
|
+
* return <div>Switching network...</div>
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function useSwitchNetwork(): UseSwitchNetworkReturn;
|
|
28
|
+
//# sourceMappingURL=useSwitchNetwork.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UseTransactionReturn } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for sending transactions with the connected wallet
|
|
4
|
+
* @returns Object containing sendTransaction function, loading state, and transaction result
|
|
5
|
+
* @throws Error if used outside of ConnectionProvider
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const { sendTransaction, isLoading, transactionResult } = useTransaction()
|
|
9
|
+
*
|
|
10
|
+
* const handleSend = async () => {
|
|
11
|
+
* try {
|
|
12
|
+
* const result = await sendTransaction({
|
|
13
|
+
* to: '0x...',
|
|
14
|
+
* amount: BigInt('1000000000000000000'),
|
|
15
|
+
* from: session.activeAddress
|
|
16
|
+
* })
|
|
17
|
+
* console.log('Transaction hash:', result.hash)
|
|
18
|
+
* } catch (error) {
|
|
19
|
+
* console.error('Transaction failed:', error)
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useTransaction(): UseTransactionReturn;
|
|
25
|
+
//# sourceMappingURL=useTransaction.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { UseWalletReturn } 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 {UseWalletReturn} Object containing the wallet metadata and error if no wallet was found
|
|
6
|
+
* @throws {Error} when used outside of ConnectionProvider
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
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
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare function useWallet(walletId: string): UseWalletReturn;
|
|
17
|
+
//# sourceMappingURL=useWallet.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WalletMetadata } from '@meshconnect/uwc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing the list of configured wallets
|
|
4
|
+
* @returns Array of wallet metadata including names, IDs, and supported networks
|
|
5
|
+
* @throws Error if used outside of ConnectionProvider
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const wallets = useWallets()
|
|
9
|
+
*
|
|
10
|
+
* wallets.forEach(wallet => {
|
|
11
|
+
* console.log(`${wallet.name}: ${wallet.id}`)
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function useWallets(): WalletMetadata[];
|
|
16
|
+
//# sourceMappingURL=useWallets.d.ts.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UniversalWalletConnector } from '@meshconnect/uwc-core';
|
|
3
|
+
import type { Session, Network, WalletMetadata, WalletConnectConfig } from '@meshconnect/uwc-types';
|
|
4
|
+
interface ConnectionContextValue {
|
|
5
|
+
connector: UniversalWalletConnector;
|
|
6
|
+
session: Session;
|
|
7
|
+
wallets: WalletMetadata[];
|
|
8
|
+
networks: Network[];
|
|
9
|
+
isReady: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const ConnectionContext: React.Context<ConnectionContextValue | null>;
|
|
12
|
+
interface ConnectionProviderProps {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
networks: Network[];
|
|
15
|
+
wallets: WalletMetadata[];
|
|
16
|
+
usingIntegratedBrowser?: boolean;
|
|
17
|
+
walletConnectConfig?: WalletConnectConfig;
|
|
18
|
+
}
|
|
19
|
+
export declare function ConnectionProvider({ children, networks, wallets, usingIntegratedBrowser, walletConnectConfig }: ConnectionProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export { ConnectionContext };
|
|
21
|
+
//# sourceMappingURL=ConnectionProvider.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "React hooks and components for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@meshconnect/uwc-core": "0.2.
|
|
19
|
+
"@meshconnect/uwc-core": "0.2.17",
|
|
20
20
|
"@meshconnect/uwc-types": "0.2.7"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|