use-stellar 0.1.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.
@@ -0,0 +1,180 @@
1
+ import React, { Dispatch, SetStateAction, ReactNode } from 'react';
2
+
3
+ type StellarNetwork = "testnet" | "mainnet";
4
+ interface NetworkConfig {
5
+ network: StellarNetwork;
6
+ horizonUrl: string;
7
+ sorobanUrl: string;
8
+ }
9
+ type WalletType = "freighter" | "albedo" | "rabet";
10
+ interface WalletState {
11
+ connected: boolean;
12
+ address: string | null;
13
+ network: StellarNetwork | null;
14
+ wallet: WalletType | null;
15
+ connecting: boolean;
16
+ error: string | null;
17
+ }
18
+ type NativeAsset = "XLM";
19
+ interface IssuedAsset {
20
+ code: string;
21
+ issuer: string;
22
+ }
23
+ type Asset = NativeAsset | IssuedAsset;
24
+ interface Balance {
25
+ asset: Asset;
26
+ balance: string;
27
+ limit?: string;
28
+ buying?: string;
29
+ selling?: string;
30
+ }
31
+ interface AccountInfo {
32
+ address: string;
33
+ sequence: string;
34
+ balances: Balance[];
35
+ subentryCount: number;
36
+ thresholds: {
37
+ lowThreshold: number;
38
+ medThreshold: number;
39
+ highThreshold: number;
40
+ };
41
+ signers: {
42
+ key: string;
43
+ weight: number;
44
+ type: string;
45
+ }[];
46
+ }
47
+ type TransactionStatus = "pending" | "success" | "failed" | "not_found";
48
+ interface TransactionResult {
49
+ hash: string;
50
+ status: TransactionStatus;
51
+ ledger?: number;
52
+ createdAt?: string;
53
+ fee?: string;
54
+ }
55
+ interface SendPaymentOptions {
56
+ to: string;
57
+ asset: Asset;
58
+ amount: string;
59
+ memo?: string;
60
+ }
61
+ interface SendPaymentResult {
62
+ hash: string;
63
+ status: TransactionStatus;
64
+ }
65
+ interface ContractCallOptions {
66
+ contractId: string;
67
+ method: string;
68
+ args?: unknown[];
69
+ }
70
+ interface StellarContextValue {
71
+ network: StellarNetwork;
72
+ networkConfig: NetworkConfig;
73
+ wallet: WalletState;
74
+ setWallet: Dispatch<SetStateAction<WalletState>>;
75
+ }
76
+
77
+ interface StellarProviderProps {
78
+ network?: StellarNetwork;
79
+ children: ReactNode;
80
+ }
81
+ declare function StellarProvider({ network, children, }: StellarProviderProps): React.JSX.Element;
82
+
83
+ interface UseWalletReturn extends WalletState {
84
+ connect: (wallet?: WalletType) => Promise<void>;
85
+ disconnect: () => void;
86
+ }
87
+ declare function useWallet(): UseWalletReturn;
88
+
89
+ interface UseBalanceOptions {
90
+ address?: string | null;
91
+ asset?: Asset;
92
+ watch?: boolean;
93
+ }
94
+ interface UseBalanceReturn {
95
+ balance: string | null;
96
+ balances: Balance[];
97
+ loading: boolean;
98
+ error: string | null;
99
+ refetch: () => void;
100
+ }
101
+ declare function useBalance({ address, asset, watch, }?: UseBalanceOptions): UseBalanceReturn;
102
+
103
+ interface UseAccountOptions {
104
+ address?: string | null;
105
+ }
106
+ interface UseAccountReturn {
107
+ account: AccountInfo | null;
108
+ loading: boolean;
109
+ error: string | null;
110
+ refetch: () => void;
111
+ }
112
+ declare function useAccount({ address }?: UseAccountOptions): UseAccountReturn;
113
+
114
+ interface UseSendPaymentReturn {
115
+ send: (options: SendPaymentOptions) => Promise<SendPaymentResult>;
116
+ loading: boolean;
117
+ error: string | null;
118
+ result: SendPaymentResult | null;
119
+ reset: () => void;
120
+ }
121
+ declare function useSendPayment(): UseSendPaymentReturn;
122
+
123
+ interface UseTransactionOptions {
124
+ hash: string | null;
125
+ watch?: boolean;
126
+ }
127
+ interface UseTransactionReturn {
128
+ transaction: TransactionResult | null;
129
+ loading: boolean;
130
+ error: string | null;
131
+ refetch: () => void;
132
+ }
133
+ declare function useTransaction({ hash, watch, }: UseTransactionOptions): UseTransactionReturn;
134
+
135
+ interface UseNetworkReturn {
136
+ network: StellarNetwork;
137
+ networkConfig: NetworkConfig;
138
+ isTestnet: boolean;
139
+ isMainnet: boolean;
140
+ }
141
+ declare function useNetwork(): UseNetworkReturn;
142
+
143
+ interface AssetInfo {
144
+ code: string;
145
+ issuer: string;
146
+ supply: string;
147
+ homeDomain?: string;
148
+ numAccounts: number;
149
+ flags: {
150
+ authRequired: boolean;
151
+ authRevocable: boolean;
152
+ authImmutable: boolean;
153
+ };
154
+ }
155
+ interface UseAssetOptions {
156
+ code: string;
157
+ issuer: string;
158
+ }
159
+ interface UseAssetReturn {
160
+ asset: AssetInfo | null;
161
+ loading: boolean;
162
+ error: string | null;
163
+ refetch: () => void;
164
+ }
165
+ declare function useAsset({ code, issuer }: UseAssetOptions): UseAssetReturn;
166
+
167
+ interface UseSorobanContractReturn {
168
+ data: unknown | null;
169
+ loading: boolean;
170
+ error: string | null;
171
+ refetch: () => void;
172
+ }
173
+ declare function useSorobanContract({ contractId, method, }: ContractCallOptions): UseSorobanContractReturn;
174
+
175
+ declare function formatAssetCode(asset: Asset): string;
176
+ declare function isValidStellarAddress(address: string): boolean;
177
+ declare function shortenAddress(address: string, chars?: number): string;
178
+ declare function formatAmount(amount: string, decimals?: number): string;
179
+
180
+ export { type AccountInfo, type Asset, type Balance, type ContractCallOptions, type IssuedAsset, type NativeAsset, type NetworkConfig, type SendPaymentOptions, type SendPaymentResult, type StellarContextValue, type StellarNetwork, StellarProvider, type TransactionResult, type TransactionStatus, type WalletState, type WalletType, formatAmount, formatAssetCode, isValidStellarAddress, shortenAddress, useAccount, useAsset, useBalance, useNetwork, useSendPayment, useSorobanContract, useTransaction, useWallet };
@@ -0,0 +1,180 @@
1
+ import React, { Dispatch, SetStateAction, ReactNode } from 'react';
2
+
3
+ type StellarNetwork = "testnet" | "mainnet";
4
+ interface NetworkConfig {
5
+ network: StellarNetwork;
6
+ horizonUrl: string;
7
+ sorobanUrl: string;
8
+ }
9
+ type WalletType = "freighter" | "albedo" | "rabet";
10
+ interface WalletState {
11
+ connected: boolean;
12
+ address: string | null;
13
+ network: StellarNetwork | null;
14
+ wallet: WalletType | null;
15
+ connecting: boolean;
16
+ error: string | null;
17
+ }
18
+ type NativeAsset = "XLM";
19
+ interface IssuedAsset {
20
+ code: string;
21
+ issuer: string;
22
+ }
23
+ type Asset = NativeAsset | IssuedAsset;
24
+ interface Balance {
25
+ asset: Asset;
26
+ balance: string;
27
+ limit?: string;
28
+ buying?: string;
29
+ selling?: string;
30
+ }
31
+ interface AccountInfo {
32
+ address: string;
33
+ sequence: string;
34
+ balances: Balance[];
35
+ subentryCount: number;
36
+ thresholds: {
37
+ lowThreshold: number;
38
+ medThreshold: number;
39
+ highThreshold: number;
40
+ };
41
+ signers: {
42
+ key: string;
43
+ weight: number;
44
+ type: string;
45
+ }[];
46
+ }
47
+ type TransactionStatus = "pending" | "success" | "failed" | "not_found";
48
+ interface TransactionResult {
49
+ hash: string;
50
+ status: TransactionStatus;
51
+ ledger?: number;
52
+ createdAt?: string;
53
+ fee?: string;
54
+ }
55
+ interface SendPaymentOptions {
56
+ to: string;
57
+ asset: Asset;
58
+ amount: string;
59
+ memo?: string;
60
+ }
61
+ interface SendPaymentResult {
62
+ hash: string;
63
+ status: TransactionStatus;
64
+ }
65
+ interface ContractCallOptions {
66
+ contractId: string;
67
+ method: string;
68
+ args?: unknown[];
69
+ }
70
+ interface StellarContextValue {
71
+ network: StellarNetwork;
72
+ networkConfig: NetworkConfig;
73
+ wallet: WalletState;
74
+ setWallet: Dispatch<SetStateAction<WalletState>>;
75
+ }
76
+
77
+ interface StellarProviderProps {
78
+ network?: StellarNetwork;
79
+ children: ReactNode;
80
+ }
81
+ declare function StellarProvider({ network, children, }: StellarProviderProps): React.JSX.Element;
82
+
83
+ interface UseWalletReturn extends WalletState {
84
+ connect: (wallet?: WalletType) => Promise<void>;
85
+ disconnect: () => void;
86
+ }
87
+ declare function useWallet(): UseWalletReturn;
88
+
89
+ interface UseBalanceOptions {
90
+ address?: string | null;
91
+ asset?: Asset;
92
+ watch?: boolean;
93
+ }
94
+ interface UseBalanceReturn {
95
+ balance: string | null;
96
+ balances: Balance[];
97
+ loading: boolean;
98
+ error: string | null;
99
+ refetch: () => void;
100
+ }
101
+ declare function useBalance({ address, asset, watch, }?: UseBalanceOptions): UseBalanceReturn;
102
+
103
+ interface UseAccountOptions {
104
+ address?: string | null;
105
+ }
106
+ interface UseAccountReturn {
107
+ account: AccountInfo | null;
108
+ loading: boolean;
109
+ error: string | null;
110
+ refetch: () => void;
111
+ }
112
+ declare function useAccount({ address }?: UseAccountOptions): UseAccountReturn;
113
+
114
+ interface UseSendPaymentReturn {
115
+ send: (options: SendPaymentOptions) => Promise<SendPaymentResult>;
116
+ loading: boolean;
117
+ error: string | null;
118
+ result: SendPaymentResult | null;
119
+ reset: () => void;
120
+ }
121
+ declare function useSendPayment(): UseSendPaymentReturn;
122
+
123
+ interface UseTransactionOptions {
124
+ hash: string | null;
125
+ watch?: boolean;
126
+ }
127
+ interface UseTransactionReturn {
128
+ transaction: TransactionResult | null;
129
+ loading: boolean;
130
+ error: string | null;
131
+ refetch: () => void;
132
+ }
133
+ declare function useTransaction({ hash, watch, }: UseTransactionOptions): UseTransactionReturn;
134
+
135
+ interface UseNetworkReturn {
136
+ network: StellarNetwork;
137
+ networkConfig: NetworkConfig;
138
+ isTestnet: boolean;
139
+ isMainnet: boolean;
140
+ }
141
+ declare function useNetwork(): UseNetworkReturn;
142
+
143
+ interface AssetInfo {
144
+ code: string;
145
+ issuer: string;
146
+ supply: string;
147
+ homeDomain?: string;
148
+ numAccounts: number;
149
+ flags: {
150
+ authRequired: boolean;
151
+ authRevocable: boolean;
152
+ authImmutable: boolean;
153
+ };
154
+ }
155
+ interface UseAssetOptions {
156
+ code: string;
157
+ issuer: string;
158
+ }
159
+ interface UseAssetReturn {
160
+ asset: AssetInfo | null;
161
+ loading: boolean;
162
+ error: string | null;
163
+ refetch: () => void;
164
+ }
165
+ declare function useAsset({ code, issuer }: UseAssetOptions): UseAssetReturn;
166
+
167
+ interface UseSorobanContractReturn {
168
+ data: unknown | null;
169
+ loading: boolean;
170
+ error: string | null;
171
+ refetch: () => void;
172
+ }
173
+ declare function useSorobanContract({ contractId, method, }: ContractCallOptions): UseSorobanContractReturn;
174
+
175
+ declare function formatAssetCode(asset: Asset): string;
176
+ declare function isValidStellarAddress(address: string): boolean;
177
+ declare function shortenAddress(address: string, chars?: number): string;
178
+ declare function formatAmount(amount: string, decimals?: number): string;
179
+
180
+ export { type AccountInfo, type Asset, type Balance, type ContractCallOptions, type IssuedAsset, type NativeAsset, type NetworkConfig, type SendPaymentOptions, type SendPaymentResult, type StellarContextValue, type StellarNetwork, StellarProvider, type TransactionResult, type TransactionStatus, type WalletState, type WalletType, formatAmount, formatAssetCode, isValidStellarAddress, shortenAddress, useAccount, useAsset, useBalance, useNetwork, useSendPayment, useSorobanContract, useTransaction, useWallet };