@cfxdevkit/react 1.0.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 @@
1
+ {"version":3,"sources":["../../src/hooks/useBalance.ts","../../src/providers/DevKitProvider.tsx","../../src/hooks/useContract.ts","../../src/providers/WalletProvider.tsx","../../src/hooks/useTransaction.ts"],"sourcesContent":["/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * useBalance Hook\n *\n * Fetches and tracks balance for an address\n */\n\nimport type { ChainType } from '@cfxdevkit/core';\nimport { useCallback, useEffect, useState } from 'react';\nimport { useDevKitContext } from '../providers/DevKitProvider.js';\n\nexport interface UseBalanceOptions {\n address?: string;\n chain: ChainType;\n enabled?: boolean;\n refreshInterval?: number;\n}\n\nexport interface UseBalanceReturn {\n balance?: string;\n isLoading: boolean;\n error?: Error;\n refetch: () => Promise<void>;\n}\n\n/**\n * Hook to fetch and track address balance\n *\n * @example\n * ```tsx\n * const { balance, isLoading } = useBalance({\n * address: '0x...',\n * chain: 'evm'\n * });\n * ```\n */\nexport function useBalance(options: UseBalanceOptions): UseBalanceReturn {\n const { address, enabled = true, refreshInterval } = options;\n useDevKitContext(); // ensure provider is present; apiUrl and chain used in production impl\n\n const [balance, setBalance] = useState<string>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n const fetchBalance = useCallback(async () => {\n if (!address || !enabled) return;\n\n setIsLoading(true);\n setError(undefined);\n\n try {\n // In production, call backend API with `chain` to select Core vs eSpace\n // For now, simulate balance fetch\n const mockBalance = '1000000000000000000'; // 1 token\n setBalance(mockBalance);\n } catch (err) {\n setError(\n err instanceof Error ? err : new Error('Failed to fetch balance')\n );\n } finally {\n setIsLoading(false);\n }\n }, [address, enabled]);\n\n useEffect(() => {\n void fetchBalance();\n\n // Set up refresh interval if provided\n if (refreshInterval) {\n const interval = setInterval(() => {\n void fetchBalance();\n }, refreshInterval);\n return () => clearInterval(interval);\n }\n }, [fetchBalance, refreshInterval]);\n\n return {\n balance,\n isLoading,\n error,\n refetch: fetchBalance,\n };\n}\n","/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * DevKit Provider\n *\n * Provides DevKit instance and configuration to all child components\n */\n\nimport { createContext, type ReactNode, useContext } from 'react';\n\nexport interface DevKitContextValue {\n /** Backend API URL */\n apiUrl: string;\n /** WebSocket URL */\n wsUrl?: string;\n /** Current network */\n network: 'local' | 'testnet' | 'mainnet';\n /** Enable debug mode */\n debug?: boolean;\n}\n\nconst DevKitContext = createContext<DevKitContextValue | undefined>(undefined);\n\nexport interface DevKitProviderProps {\n apiUrl: string;\n wsUrl?: string;\n network?: 'local' | 'testnet' | 'mainnet';\n debug?: boolean;\n children: ReactNode;\n}\n\n/**\n * DevKit Provider Component\n *\n * Wrap your app with this provider to enable DevKit functionality\n *\n * @example\n * ```tsx\n * <DevKitProvider apiUrl=\"http://localhost:3000\" network=\"local\">\n * <App />\n * </DevKitProvider>\n * ```\n */\nexport function DevKitProvider({\n apiUrl,\n wsUrl,\n network = 'local',\n debug = false,\n children,\n}: DevKitProviderProps) {\n const value: DevKitContextValue = {\n apiUrl,\n wsUrl,\n network,\n debug,\n };\n\n return (\n <DevKitContext.Provider value={value}>{children}</DevKitContext.Provider>\n );\n}\n\n/**\n * Hook to access DevKit context\n *\n * @throws Error if used outside DevKitProvider\n */\nexport function useDevKitContext() {\n const context = useContext(DevKitContext);\n if (!context) {\n throw new Error('useDevKitContext must be used within DevKitProvider');\n }\n return context;\n}\n","/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * useContract Hook\n *\n * Interact with smart contracts (read and write)\n */\n\nimport type { ChainType } from '@cfxdevkit/core';\nimport { useState } from 'react';\nimport { useDevKitContext } from '../providers/DevKitProvider.js';\nimport { useWalletContext } from '../providers/WalletProvider.js';\n\nexport interface ReadContractOptions {\n address: string;\n abi: unknown[];\n functionName: string;\n args?: unknown[];\n chain: ChainType;\n}\n\nexport interface WriteContractOptions extends ReadContractOptions {\n value?: string;\n}\n\nexport interface UseContractReturn {\n read: <T = unknown>(options: ReadContractOptions) => Promise<T>;\n write: (options: WriteContractOptions) => Promise<string>;\n isLoading: boolean;\n error?: Error;\n}\n\n/**\n * Hook to interact with smart contracts\n *\n * @example\n * ```tsx\n * const { read, write, isLoading } = useContract();\n *\n * // Read contract\n * const balance = await read({\n * address: '0x...',\n * abi: ERC20_ABI,\n * functionName: 'balanceOf',\n * args: ['0x...'],\n * chain: 'evm'\n * });\n *\n * // Write contract\n * const hash = await write({\n * address: '0x...',\n * abi: ERC20_ABI,\n * functionName: 'transfer',\n * args: ['0x...', '1000000000000000000'],\n * chain: 'evm'\n * });\n * ```\n */\nexport function useContract(): UseContractReturn {\n useDevKitContext(); // ensure provider is present; apiUrl used in production impl\n const { accountIndex } = useWalletContext();\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n const read = async <T = unknown>(\n _options: ReadContractOptions\n ): Promise<T> => {\n setIsLoading(true);\n setError(undefined);\n\n try {\n // In production, call backend API\n // For now, return mock data\n return {} as T;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error('Contract read failed');\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n };\n\n const write = async (_options: WriteContractOptions): Promise<string> => {\n if (accountIndex === undefined) {\n throw new Error('Wallet not connected');\n }\n\n setIsLoading(true);\n setError(undefined);\n\n try {\n // In production, call backend API\n // For now, return mock hash\n const hash = `0x${Array.from({ length: 64 }, () =>\n Math.floor(Math.random() * 16).toString(16)\n ).join('')}`;\n\n return hash;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error('Contract write failed');\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n };\n\n return {\n read,\n write,\n isLoading,\n error,\n };\n}\n","/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Wallet Provider\n *\n * Manages wallet connection state and provides wallet-related functionality\n */\n\nimport type { ChainType } from '@cfxdevkit/core';\nimport { createContext, type ReactNode, useContext, useState } from 'react';\n\nexport interface WalletContextValue {\n isConnected: boolean;\n address?: string;\n coreAddress?: string;\n evmAddress?: string;\n chain?: ChainType;\n accountIndex?: number;\n connect: (accountIndex: number) => Promise<void>;\n disconnect: () => void;\n switchChain: (chain: ChainType) => void;\n}\n\nconst WalletContext = createContext<WalletContextValue | undefined>(undefined);\n\nexport interface WalletProviderProps {\n children: ReactNode;\n}\n\n/**\n * Wallet Provider Component\n *\n * Manages wallet connection state\n *\n * @example\n * ```tsx\n * <WalletProvider>\n * <ConnectButton />\n * <AccountCard />\n * </WalletProvider>\n * ```\n */\nexport function WalletProvider({ children }: WalletProviderProps) {\n const [isConnected, setIsConnected] = useState(false);\n const [coreAddress, setCoreAddress] = useState<string>();\n const [evmAddress, setEvmAddress] = useState<string>();\n const [chain, setChain] = useState<ChainType>('evm');\n const [accountIndex, setAccountIndex] = useState<number>();\n\n const connect = async (index: number) => {\n // In production, this would fetch account info from backend\n // For now, simulate connection\n setAccountIndex(index);\n setCoreAddress(`cfx:account${index}`);\n setEvmAddress(`0xaccount${index}`);\n setIsConnected(true);\n };\n\n const disconnect = () => {\n setIsConnected(false);\n setCoreAddress(undefined);\n setEvmAddress(undefined);\n setAccountIndex(undefined);\n };\n\n const switchChain = (newChain: ChainType) => {\n setChain(newChain);\n };\n\n const value: WalletContextValue = {\n isConnected,\n address: chain === 'core' ? coreAddress : evmAddress,\n coreAddress,\n evmAddress,\n chain,\n accountIndex,\n connect,\n disconnect,\n switchChain,\n };\n\n return (\n <WalletContext.Provider value={value}>{children}</WalletContext.Provider>\n );\n}\n\n/**\n * Hook to access Wallet context\n *\n * @throws Error if used outside WalletProvider\n */\nexport function useWalletContext() {\n const context = useContext(WalletContext);\n if (!context) {\n throw new Error('useWalletContext must be used within WalletProvider');\n }\n return context;\n}\n","/*\n * Copyright 2025 Conflux DevKit Team\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * useTransaction Hook\n *\n * Sends transactions and tracks their status\n */\n\nimport type { ChainType } from '@cfxdevkit/core';\nimport { useState } from 'react';\nimport { useDevKitContext } from '../providers/DevKitProvider.js';\nimport { useWalletContext } from '../providers/WalletProvider.js';\n\nexport interface SendTransactionOptions {\n to: string;\n value?: string;\n data?: string;\n chain?: ChainType;\n}\n\nexport interface TransactionResult {\n hash: string;\n status: 'pending' | 'success' | 'failed';\n}\n\nexport interface UseTransactionReturn {\n send: (options: SendTransactionOptions) => Promise<TransactionResult>;\n isLoading: boolean;\n error?: Error;\n transaction?: TransactionResult;\n reset: () => void;\n}\n\n/**\n * Hook to send transactions\n *\n * @example\n * ```tsx\n * const { send, isLoading, transaction } = useTransaction();\n *\n * const handleSend = async () => {\n * const result = await send({\n * to: '0x...',\n * value: '1000000000000000000',\n * chain: 'evm'\n * });\n * };\n * ```\n */\nexport function useTransaction(): UseTransactionReturn {\n useDevKitContext(); // ensure provider is present; apiUrl used in production impl\n const { accountIndex } = useWalletContext();\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n const [transaction, setTransaction] = useState<TransactionResult>();\n\n const send = async (\n _options: SendTransactionOptions\n ): Promise<TransactionResult> => {\n if (accountIndex === undefined) {\n throw new Error('Wallet not connected');\n }\n\n setIsLoading(true);\n setError(undefined);\n\n try {\n // In production, call backend API to send transaction\n // For now, simulate transaction\n const result: TransactionResult = {\n hash: `0x${Array.from({ length: 64 }, () =>\n Math.floor(Math.random() * 16).toString(16)\n ).join('')}`,\n status: 'pending',\n };\n\n setTransaction(result);\n\n // Simulate confirmation\n setTimeout(() => {\n setTransaction({ ...result, status: 'success' });\n }, 2000);\n\n return result;\n } catch (err) {\n const errorObj =\n err instanceof Error ? err : new Error('Transaction failed');\n setError(errorObj);\n throw errorObj;\n } finally {\n setIsLoading(false);\n }\n };\n\n const reset = () => {\n setTransaction(undefined);\n setError(undefined);\n };\n\n return {\n send,\n isLoading,\n error,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AAC,iBAAgB;AAwClB,SAAS,iBAAuC;AACrD,mBAAiB;AACjB,QAAM,EAAE,aAAa,IAAI,iBAAiB;AAE1C,QAAM,CAAC,WAAW,YAAY,IAAIC,UAAS,KAAK;AAChD,QAAM,CAAC,OAAO,QAAQ,IAAIA,UAAgB;AAC1C,QAAM,CAAC,aAAa,cAAc,IAAIA,UAA4B;AAElE,QAAM,OAAO,OACX,aAC+B;AAC/B,QAAI,iBAAiB,QAAW;AAC9B,YAAM,IAAI,MAAM,sBAAsB;AAAA,IACxC;AAEA,iBAAa,IAAI;AACjB,aAAS,MAAS;AAElB,QAAI;AAGF,YAAM,SAA4B;AAAA,QAChC,MAAM,KAAK,MAAM;AAAA,UAAK,EAAE,QAAQ,GAAG;AAAA,UAAG,MACpC,KAAK,MAAM,KAAK,OAAO,IAAI,EAAE,EAAE,SAAS,EAAE;AAAA,QAC5C,EAAE,KAAK,EAAE,CAAC;AAAA,QACV,QAAQ;AAAA,MACV;AAEA,qBAAe,MAAM;AAGrB,iBAAW,MAAM;AACf,uBAAe,EAAE,GAAG,QAAQ,QAAQ,UAAU,CAAC;AAAA,MACjD,GAAG,GAAI;AAEP,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,YAAM,WACJ,eAAe,QAAQ,MAAM,IAAI,MAAM,oBAAoB;AAC7D,eAAS,QAAQ;AACjB,YAAM;AAAA,IACR,UAAE;AACA,mBAAa,KAAK;AAAA,IACpB;AAAA,EACF;AAEA,QAAM,QAAQ,MAAM;AAClB,mBAAe,MAAS;AACxB,aAAS,MAAS;AAAA,EACpB;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["useState","createContext","useContext","useState","jsx","useContext","useState","useState","useState"]}
@@ -0,0 +1,233 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
3
+ import { ChainType } from '@cfxdevkit/core';
4
+
5
+ /**
6
+ * UI Headless Types
7
+ */
8
+
9
+ interface WalletConnection {
10
+ isConnected: boolean;
11
+ address?: string;
12
+ chainType?: ChainType;
13
+ balance?: string;
14
+ }
15
+ interface NetworkInfo {
16
+ chainId: number;
17
+ name: string;
18
+ type: 'local' | 'testnet' | 'mainnet';
19
+ rpcUrl: string;
20
+ }
21
+ interface ContractDeployment {
22
+ address: string;
23
+ transactionHash: string;
24
+ chain: ChainType;
25
+ }
26
+ interface TransactionResult {
27
+ hash: string;
28
+ status: 'pending' | 'success' | 'failed';
29
+ blockNumber?: bigint;
30
+ }
31
+ type RenderPropChild<T> = (props: T) => React.ReactNode;
32
+ interface BaseComponentProps {
33
+ className?: string;
34
+ }
35
+
36
+ interface AccountCardRenderProps {
37
+ isConnected: boolean;
38
+ coreAddress?: string;
39
+ evmAddress?: string;
40
+ coreBalance?: string;
41
+ evmBalance?: string;
42
+ isLoadingBalance: boolean;
43
+ }
44
+ interface AccountCardProps extends BaseComponentProps {
45
+ showBalance?: boolean;
46
+ children?: RenderPropChild<AccountCardRenderProps> | React$1.ReactNode;
47
+ }
48
+ /**
49
+ * AccountCard Component
50
+ *
51
+ * Headless account information display. Use render prop pattern for custom UI.
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * // With render prop
56
+ * <AccountCard showBalance>
57
+ * {({ coreAddress, evmAddress, coreBalance, evmBalance }) => (
58
+ * <div>
59
+ * <p>Core: {coreAddress}</p>
60
+ * <p>EVM: {evmAddress}</p>
61
+ * <p>Balance: {coreBalance}</p>
62
+ * </div>
63
+ * )}
64
+ * </AccountCard>
65
+ *
66
+ * // With default styling
67
+ * <AccountCard showBalance className="p-4 bg-gray-100 rounded" />
68
+ * ```
69
+ */
70
+ declare function AccountCard({ showBalance, children, className, }: AccountCardProps): react_jsx_runtime.JSX.Element | null;
71
+
72
+ interface ConnectButtonRenderProps {
73
+ isConnected: boolean;
74
+ address?: string;
75
+ connect: () => Promise<void>;
76
+ disconnect: () => void;
77
+ isLoading: boolean;
78
+ }
79
+ interface ConnectButtonProps extends BaseComponentProps {
80
+ accountIndex?: number;
81
+ onConnect?: () => void;
82
+ onDisconnect?: () => void;
83
+ children?: RenderPropChild<ConnectButtonRenderProps> | React$1.ReactNode;
84
+ }
85
+ /**
86
+ * ConnectButton Component
87
+ *
88
+ * Headless wallet connection button. Use render prop pattern for custom UI.
89
+ *
90
+ * @example
91
+ * ```tsx
92
+ * // With render prop (full control)
93
+ * <ConnectButton>
94
+ * {({ isConnected, address, connect, disconnect }) => (
95
+ * <button onClick={isConnected ? disconnect : connect}>
96
+ * {isConnected ? `Connected: ${address}` : 'Connect Wallet'}
97
+ * </button>
98
+ * )}
99
+ * </ConnectButton>
100
+ *
101
+ * // With default styling
102
+ * <ConnectButton className="px-4 py-2 bg-blue-500 text-white rounded" />
103
+ * ```
104
+ */
105
+ declare function ConnectButton({ accountIndex, onConnect, onDisconnect, children, className, }: ConnectButtonProps): react_jsx_runtime.JSX.Element;
106
+
107
+ interface ContractReaderRenderProps<T = unknown> {
108
+ read: (args?: unknown[]) => Promise<void>;
109
+ result?: T;
110
+ isLoading: boolean;
111
+ error?: Error;
112
+ }
113
+ interface ContractReaderProps<T = unknown> extends BaseComponentProps {
114
+ address: string;
115
+ abi: unknown[];
116
+ functionName: string;
117
+ chain: ChainType;
118
+ children?: RenderPropChild<ContractReaderRenderProps<T>> | React$1.ReactNode;
119
+ }
120
+ /**
121
+ * ContractReader Component
122
+ *
123
+ * Headless contract read component. Use render prop for custom UI.
124
+ *
125
+ * @example
126
+ * ```tsx
127
+ * <ContractReader
128
+ * address="0x..."
129
+ * abi={ERC20_ABI}
130
+ * functionName="balanceOf"
131
+ * chain="evm"
132
+ * >
133
+ * {({ read, result, isLoading }) => (
134
+ * <div>
135
+ * <button onClick={() => read(['0x...'])}>Get Balance</button>
136
+ * {isLoading && <p>Loading...</p>}
137
+ * {result && <p>Balance: {result}</p>}
138
+ * </div>
139
+ * )}
140
+ * </ContractReader>
141
+ * ```
142
+ */
143
+ declare function ContractReader<T = unknown>({ address, abi, functionName, chain, children, className, }: ContractReaderProps<T>): react_jsx_runtime.JSX.Element;
144
+
145
+ interface ContractWriterRenderProps {
146
+ write: (args?: unknown[], value?: string) => Promise<void>;
147
+ hash?: string;
148
+ isLoading: boolean;
149
+ error?: Error;
150
+ reset: () => void;
151
+ }
152
+ interface ContractWriterProps extends BaseComponentProps {
153
+ address: string;
154
+ abi: unknown[];
155
+ functionName: string;
156
+ chain: ChainType;
157
+ onSuccess?: (hash: string) => void;
158
+ children?: RenderPropChild<ContractWriterRenderProps> | React$1.ReactNode;
159
+ }
160
+ /**
161
+ * ContractWriter Component
162
+ *
163
+ * Headless contract write component. Use render prop for custom UI.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * <ContractWriter
168
+ * address="0x..."
169
+ * abi={ERC20_ABI}
170
+ * functionName="transfer"
171
+ * chain="evm"
172
+ * onSuccess={(hash) => console.log('Success:', hash)}
173
+ * >
174
+ * {({ write, hash, isLoading }) => (
175
+ * <div>
176
+ * <button onClick={() => write(['0x...', '1000000000000000000'])}>
177
+ * Transfer
178
+ * </button>
179
+ * {isLoading && <p>Sending...</p>}
180
+ * {hash && <p>TX: {hash}</p>}
181
+ * </div>
182
+ * )}
183
+ * </ContractWriter>
184
+ * ```
185
+ */
186
+ declare function ContractWriter({ address, abi, functionName, chain, onSuccess, children, className, }: ContractWriterProps): react_jsx_runtime.JSX.Element;
187
+
188
+ interface SwapQuote {
189
+ amountIn: string;
190
+ amountOut: string;
191
+ amountOutMin: string;
192
+ priceImpact: string;
193
+ slippage: number;
194
+ }
195
+ interface SwapWidgetRenderProps {
196
+ getQuote: (tokenIn: string, tokenOut: string, amountIn: string) => Promise<void>;
197
+ executeSwap: () => Promise<void>;
198
+ quote?: SwapQuote;
199
+ isLoadingQuote: boolean;
200
+ isExecutingSwap: boolean;
201
+ error?: Error;
202
+ hash?: string;
203
+ }
204
+ interface SwapWidgetProps extends BaseComponentProps {
205
+ defaultSlippage?: number;
206
+ onSuccess?: (hash: string) => void;
207
+ children?: RenderPropChild<SwapWidgetRenderProps> | React$1.ReactNode;
208
+ }
209
+ /**
210
+ * SwapWidget Component
211
+ *
212
+ * Headless swap interface for Swappi DEX. Use render prop for custom UI.
213
+ *
214
+ * @example
215
+ * ```tsx
216
+ * <SwapWidget defaultSlippage={0.5}>
217
+ * {({ getQuote, executeSwap, quote, isLoadingQuote }) => (
218
+ * <div>
219
+ * <button onClick={() => getQuote('WCFX', 'USDT', '1.0')}>
220
+ * Get Quote
221
+ * </button>
222
+ * {quote && <p>You get: {quote.amountOut}</p>}
223
+ * <button onClick={executeSwap} disabled={!quote}>
224
+ * Swap
225
+ * </button>
226
+ * </div>
227
+ * )}
228
+ * </SwapWidget>
229
+ * ```
230
+ */
231
+ declare function SwapWidget({ defaultSlippage, onSuccess, children, className, }: SwapWidgetProps): react_jsx_runtime.JSX.Element;
232
+
233
+ export { AccountCard as A, type BaseComponentProps as B, ConnectButton as C, type NetworkInfo as N, type RenderPropChild as R, type SwapQuote as S, type TransactionResult as T, type WalletConnection as W, type AccountCardProps as a, type AccountCardRenderProps as b, type ConnectButtonProps as c, type ConnectButtonRenderProps as d, type ContractDeployment as e, ContractReader as f, type ContractReaderProps as g, type ContractReaderRenderProps as h, ContractWriter as i, type ContractWriterProps as j, type ContractWriterRenderProps as k, SwapWidget as l, type SwapWidgetProps as m, type SwapWidgetRenderProps as n };
@@ -0,0 +1,233 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1 from 'react';
3
+ import { ChainType } from '@cfxdevkit/core';
4
+
5
+ /**
6
+ * UI Headless Types
7
+ */
8
+
9
+ interface WalletConnection {
10
+ isConnected: boolean;
11
+ address?: string;
12
+ chainType?: ChainType;
13
+ balance?: string;
14
+ }
15
+ interface NetworkInfo {
16
+ chainId: number;
17
+ name: string;
18
+ type: 'local' | 'testnet' | 'mainnet';
19
+ rpcUrl: string;
20
+ }
21
+ interface ContractDeployment {
22
+ address: string;
23
+ transactionHash: string;
24
+ chain: ChainType;
25
+ }
26
+ interface TransactionResult {
27
+ hash: string;
28
+ status: 'pending' | 'success' | 'failed';
29
+ blockNumber?: bigint;
30
+ }
31
+ type RenderPropChild<T> = (props: T) => React.ReactNode;
32
+ interface BaseComponentProps {
33
+ className?: string;
34
+ }
35
+
36
+ interface AccountCardRenderProps {
37
+ isConnected: boolean;
38
+ coreAddress?: string;
39
+ evmAddress?: string;
40
+ coreBalance?: string;
41
+ evmBalance?: string;
42
+ isLoadingBalance: boolean;
43
+ }
44
+ interface AccountCardProps extends BaseComponentProps {
45
+ showBalance?: boolean;
46
+ children?: RenderPropChild<AccountCardRenderProps> | React$1.ReactNode;
47
+ }
48
+ /**
49
+ * AccountCard Component
50
+ *
51
+ * Headless account information display. Use render prop pattern for custom UI.
52
+ *
53
+ * @example
54
+ * ```tsx
55
+ * // With render prop
56
+ * <AccountCard showBalance>
57
+ * {({ coreAddress, evmAddress, coreBalance, evmBalance }) => (
58
+ * <div>
59
+ * <p>Core: {coreAddress}</p>
60
+ * <p>EVM: {evmAddress}</p>
61
+ * <p>Balance: {coreBalance}</p>
62
+ * </div>
63
+ * )}
64
+ * </AccountCard>
65
+ *
66
+ * // With default styling
67
+ * <AccountCard showBalance className="p-4 bg-gray-100 rounded" />
68
+ * ```
69
+ */
70
+ declare function AccountCard({ showBalance, children, className, }: AccountCardProps): react_jsx_runtime.JSX.Element | null;
71
+
72
+ interface ConnectButtonRenderProps {
73
+ isConnected: boolean;
74
+ address?: string;
75
+ connect: () => Promise<void>;
76
+ disconnect: () => void;
77
+ isLoading: boolean;
78
+ }
79
+ interface ConnectButtonProps extends BaseComponentProps {
80
+ accountIndex?: number;
81
+ onConnect?: () => void;
82
+ onDisconnect?: () => void;
83
+ children?: RenderPropChild<ConnectButtonRenderProps> | React$1.ReactNode;
84
+ }
85
+ /**
86
+ * ConnectButton Component
87
+ *
88
+ * Headless wallet connection button. Use render prop pattern for custom UI.
89
+ *
90
+ * @example
91
+ * ```tsx
92
+ * // With render prop (full control)
93
+ * <ConnectButton>
94
+ * {({ isConnected, address, connect, disconnect }) => (
95
+ * <button onClick={isConnected ? disconnect : connect}>
96
+ * {isConnected ? `Connected: ${address}` : 'Connect Wallet'}
97
+ * </button>
98
+ * )}
99
+ * </ConnectButton>
100
+ *
101
+ * // With default styling
102
+ * <ConnectButton className="px-4 py-2 bg-blue-500 text-white rounded" />
103
+ * ```
104
+ */
105
+ declare function ConnectButton({ accountIndex, onConnect, onDisconnect, children, className, }: ConnectButtonProps): react_jsx_runtime.JSX.Element;
106
+
107
+ interface ContractReaderRenderProps<T = unknown> {
108
+ read: (args?: unknown[]) => Promise<void>;
109
+ result?: T;
110
+ isLoading: boolean;
111
+ error?: Error;
112
+ }
113
+ interface ContractReaderProps<T = unknown> extends BaseComponentProps {
114
+ address: string;
115
+ abi: unknown[];
116
+ functionName: string;
117
+ chain: ChainType;
118
+ children?: RenderPropChild<ContractReaderRenderProps<T>> | React$1.ReactNode;
119
+ }
120
+ /**
121
+ * ContractReader Component
122
+ *
123
+ * Headless contract read component. Use render prop for custom UI.
124
+ *
125
+ * @example
126
+ * ```tsx
127
+ * <ContractReader
128
+ * address="0x..."
129
+ * abi={ERC20_ABI}
130
+ * functionName="balanceOf"
131
+ * chain="evm"
132
+ * >
133
+ * {({ read, result, isLoading }) => (
134
+ * <div>
135
+ * <button onClick={() => read(['0x...'])}>Get Balance</button>
136
+ * {isLoading && <p>Loading...</p>}
137
+ * {result && <p>Balance: {result}</p>}
138
+ * </div>
139
+ * )}
140
+ * </ContractReader>
141
+ * ```
142
+ */
143
+ declare function ContractReader<T = unknown>({ address, abi, functionName, chain, children, className, }: ContractReaderProps<T>): react_jsx_runtime.JSX.Element;
144
+
145
+ interface ContractWriterRenderProps {
146
+ write: (args?: unknown[], value?: string) => Promise<void>;
147
+ hash?: string;
148
+ isLoading: boolean;
149
+ error?: Error;
150
+ reset: () => void;
151
+ }
152
+ interface ContractWriterProps extends BaseComponentProps {
153
+ address: string;
154
+ abi: unknown[];
155
+ functionName: string;
156
+ chain: ChainType;
157
+ onSuccess?: (hash: string) => void;
158
+ children?: RenderPropChild<ContractWriterRenderProps> | React$1.ReactNode;
159
+ }
160
+ /**
161
+ * ContractWriter Component
162
+ *
163
+ * Headless contract write component. Use render prop for custom UI.
164
+ *
165
+ * @example
166
+ * ```tsx
167
+ * <ContractWriter
168
+ * address="0x..."
169
+ * abi={ERC20_ABI}
170
+ * functionName="transfer"
171
+ * chain="evm"
172
+ * onSuccess={(hash) => console.log('Success:', hash)}
173
+ * >
174
+ * {({ write, hash, isLoading }) => (
175
+ * <div>
176
+ * <button onClick={() => write(['0x...', '1000000000000000000'])}>
177
+ * Transfer
178
+ * </button>
179
+ * {isLoading && <p>Sending...</p>}
180
+ * {hash && <p>TX: {hash}</p>}
181
+ * </div>
182
+ * )}
183
+ * </ContractWriter>
184
+ * ```
185
+ */
186
+ declare function ContractWriter({ address, abi, functionName, chain, onSuccess, children, className, }: ContractWriterProps): react_jsx_runtime.JSX.Element;
187
+
188
+ interface SwapQuote {
189
+ amountIn: string;
190
+ amountOut: string;
191
+ amountOutMin: string;
192
+ priceImpact: string;
193
+ slippage: number;
194
+ }
195
+ interface SwapWidgetRenderProps {
196
+ getQuote: (tokenIn: string, tokenOut: string, amountIn: string) => Promise<void>;
197
+ executeSwap: () => Promise<void>;
198
+ quote?: SwapQuote;
199
+ isLoadingQuote: boolean;
200
+ isExecutingSwap: boolean;
201
+ error?: Error;
202
+ hash?: string;
203
+ }
204
+ interface SwapWidgetProps extends BaseComponentProps {
205
+ defaultSlippage?: number;
206
+ onSuccess?: (hash: string) => void;
207
+ children?: RenderPropChild<SwapWidgetRenderProps> | React$1.ReactNode;
208
+ }
209
+ /**
210
+ * SwapWidget Component
211
+ *
212
+ * Headless swap interface for Swappi DEX. Use render prop for custom UI.
213
+ *
214
+ * @example
215
+ * ```tsx
216
+ * <SwapWidget defaultSlippage={0.5}>
217
+ * {({ getQuote, executeSwap, quote, isLoadingQuote }) => (
218
+ * <div>
219
+ * <button onClick={() => getQuote('WCFX', 'USDT', '1.0')}>
220
+ * Get Quote
221
+ * </button>
222
+ * {quote && <p>You get: {quote.amountOut}</p>}
223
+ * <button onClick={executeSwap} disabled={!quote}>
224
+ * Swap
225
+ * </button>
226
+ * </div>
227
+ * )}
228
+ * </SwapWidget>
229
+ * ```
230
+ */
231
+ declare function SwapWidget({ defaultSlippage, onSuccess, children, className, }: SwapWidgetProps): react_jsx_runtime.JSX.Element;
232
+
233
+ export { AccountCard as A, type BaseComponentProps as B, ConnectButton as C, type NetworkInfo as N, type RenderPropChild as R, type SwapQuote as S, type TransactionResult as T, type WalletConnection as W, type AccountCardProps as a, type AccountCardRenderProps as b, type ConnectButtonProps as c, type ConnectButtonRenderProps as d, type ContractDeployment as e, ContractReader as f, type ContractReaderProps as g, type ContractReaderRenderProps as h, ContractWriter as i, type ContractWriterProps as j, type ContractWriterRenderProps as k, SwapWidget as l, type SwapWidgetProps as m, type SwapWidgetRenderProps as n };