@caatinga/cli 2.1.0 → 2.2.1

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,64 +0,0 @@
1
- import {
2
- createContext,
3
- useCallback,
4
- useContext,
5
- useMemo,
6
- useState,
7
- type ReactNode
8
- } from "react";
9
- import { stellarWalletAdapter } from "../wallet.js";
10
-
11
- interface WalletContextValue {
12
- publicKey: string | null;
13
- loading: boolean;
14
- error: string | null;
15
- connect: () => Promise<void>;
16
- disconnect: () => Promise<void>;
17
- }
18
-
19
- const WalletContext = createContext<WalletContextValue | null>(null);
20
-
21
- export function WalletProvider({ children }: { children: ReactNode }) {
22
- const [publicKey, setPublicKey] = useState<string | null>(null);
23
- const [loading, setLoading] = useState(false);
24
- const [error, setError] = useState<string | null>(null);
25
-
26
- const connect = useCallback(async () => {
27
- setLoading(true);
28
- setError(null);
29
-
30
- try {
31
- // openModal lists only installed/available wallets and resolves with the
32
- // chosen account address (rejects if the user dismisses the modal).
33
- const address = await stellarWalletAdapter.openModal();
34
- setPublicKey(address);
35
- } catch (caught) {
36
- const message = caught instanceof Error ? caught.message : String(caught);
37
- setError(message);
38
- } finally {
39
- setLoading(false);
40
- }
41
- }, []);
42
-
43
- const disconnect = useCallback(async () => {
44
- await stellarWalletAdapter.disconnect();
45
- setPublicKey(null);
46
- setError(null);
47
- }, []);
48
-
49
- const value = useMemo<WalletContextValue>(
50
- () => ({ publicKey, loading, error, connect, disconnect }),
51
- [publicKey, loading, error, connect, disconnect]
52
- );
53
-
54
- return <WalletContext.Provider value={value}>{children}</WalletContext.Provider>;
55
- }
56
-
57
- export function useWallet(): WalletContextValue {
58
- const context = useContext(WalletContext);
59
- if (!context) {
60
- throw new Error("useWallet must be used within a WalletProvider");
61
- }
62
-
63
- return context;
64
- }