@wheelx-widget/widget 0.1.10 → 0.1.11

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,363 @@
1
+ import React from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { Fraction } from 'bi-fraction';
4
+ import * as _tanstack_react_query from '@tanstack/react-query';
5
+ import * as zustand from 'zustand';
6
+
7
+ interface TokenConfig {
8
+ chainId: number;
9
+ address: string;
10
+ decimals?: number;
11
+ symbol?: string;
12
+ name?: string;
13
+ logo?: string;
14
+ }
15
+ interface WidgetTheme {
16
+ defaultTextColor: string;
17
+ highlightTextColor: string;
18
+ weakTextColor: string;
19
+ defaultBgColor: string;
20
+ highlightBgColor: string;
21
+ assistBgColor: string;
22
+ defaultBorderColor: string;
23
+ highlightBorderColor: string;
24
+ highlightButtonBg: string;
25
+ highlightButtonText: string;
26
+ normalButtonBg: string;
27
+ normalButtonText: string;
28
+ disabledButtonBg: string;
29
+ disabledButtonText: string;
30
+ }
31
+ interface WidgetConfig {
32
+ theme?: Partial<WidgetTheme>;
33
+ from?: {
34
+ chains?: number[];
35
+ defaultChainId?: number;
36
+ chainTokens?: Record<number, TokenConfig[]>;
37
+ defaultToken?: {
38
+ chainId: number;
39
+ address: string;
40
+ };
41
+ };
42
+ to?: {
43
+ chains?: number[];
44
+ defaultChainId?: number;
45
+ chainTokens?: Record<number, TokenConfig[]>;
46
+ defaultToken?: {
47
+ chainId: number;
48
+ address: string;
49
+ };
50
+ };
51
+ routerCallback?: {
52
+ onPathnameChange?: (pathname: string) => void;
53
+ onRouteLeave?: () => void;
54
+ getCurrentPathname?: () => string;
55
+ };
56
+ dynamicEnvironmentId?: string;
57
+ }
58
+
59
+ interface WheelXProviderProps {
60
+ config?: WidgetConfig;
61
+ children: React.ReactNode;
62
+ }
63
+ declare const WheelXProvider: React.FC<WheelXProviderProps>;
64
+
65
+ interface routesItem {
66
+ name: string;
67
+ logo: string;
68
+ }
69
+ interface TxInfoProps {
70
+ priceImpact: {
71
+ bridgeFee: string;
72
+ dstGasFee: string;
73
+ swapFee: string;
74
+ before_discount_fee: string;
75
+ discount_percentage: string | undefined;
76
+ };
77
+ slippage: number;
78
+ minReceive: string;
79
+ estimatedTime: number;
80
+ recipient: string;
81
+ router: string;
82
+ points: number | string;
83
+ amountOut: string;
84
+ fromTokenInUsd?: Fraction;
85
+ router_type: string | null | undefined;
86
+ routes?: routesItem[] | undefined;
87
+ }
88
+
89
+ interface RefetchQuoteParams {
90
+ slippageValue?: string;
91
+ isAutoSlippage?: boolean;
92
+ }
93
+
94
+ interface QuoteRequest {
95
+ from_chain: number;
96
+ to_chain: number;
97
+ from_token: string;
98
+ to_token: string;
99
+ from_address: string;
100
+ to_address: string;
101
+ amount: string;
102
+ slippage?: number;
103
+ to_platform_id: number;
104
+ }
105
+ type QuoteErrorType = 'business_error' | 'http_error' | 'network_error' | 'timeout' | 'unknown_error';
106
+ interface QuoteMutationError extends Error {
107
+ httpStatus?: number;
108
+ hasResponseBody?: boolean;
109
+ errorType?: QuoteErrorType;
110
+ detail?: string;
111
+ code?: string;
112
+ }
113
+
114
+ type Tag = 'pin' | 'top' | 'cert' | 'native';
115
+ type FeeLevel = 'Group1' | 'Group2' | null;
116
+ interface TokenInfo {
117
+ name: string;
118
+ address: `0x${string}`;
119
+ chain_id: number;
120
+ decimals: number;
121
+ symbol: string;
122
+ logo: string;
123
+ tags: Tag[];
124
+ support_kline?: boolean;
125
+ token_type?: string;
126
+ categories?: string[];
127
+ chain_icon?: string;
128
+ platform_id?: number;
129
+ platform_type?: string[];
130
+ isSolana?: boolean;
131
+ fee_level?: FeeLevel;
132
+ }
133
+ interface TokenInfoWithBalance extends TokenInfo {
134
+ balance?: string;
135
+ usdPrice?: string;
136
+ }
137
+ type ChainInfo = {
138
+ name: string;
139
+ rpc_url: string;
140
+ rpc_fallback: string[];
141
+ chain_icon: string;
142
+ chain_id: number;
143
+ eth_token: `0x${string}`;
144
+ support_kline: boolean;
145
+ is_popular: boolean;
146
+ outbound: boolean;
147
+ inbound: boolean;
148
+ is_testnet?: boolean;
149
+ platform_id?: number;
150
+ };
151
+ interface Prediction {
152
+ chains: ChainInfo[];
153
+ tokens: TokenInfo[];
154
+ }
155
+ interface SlippagePolicy {
156
+ bridge: boolean;
157
+ from_fee_level: FeeLevel;
158
+ to_fee_level: FeeLevel;
159
+ default_slippage: number;
160
+ min_slippage: number;
161
+ max_slippage: number;
162
+ refresh_interval: number;
163
+ notice_rounds?: number;
164
+ }
165
+ interface ChainsAndTokens {
166
+ chains: ChainInfo[];
167
+ tokens: TokenInfo[];
168
+ slippage_policies?: SlippagePolicy[];
169
+ deposit_platforms: {
170
+ prediction: Prediction;
171
+ };
172
+ }
173
+ declare function getChainsAndTokens(): Promise<ChainsAndTokens>;
174
+ declare const useChainsAndTokens: (enabled?: boolean) => _tanstack_react_query.UseQueryResult<ChainsAndTokens, Error>;
175
+ declare function mergeTokensWithCompositeKey(arr1: TokenInfoWithBalance[], arr2: TokenInfoWithBalance[]): TokenInfoWithBalance[];
176
+
177
+ type WheelXWidgetProps = {
178
+ config?: WidgetConfig;
179
+ };
180
+
181
+ interface QuoteInfo {
182
+ isFetching: boolean;
183
+ error: string | null;
184
+ data: `0x${string}` | null;
185
+ contractAddress: `0x${string}` | null;
186
+ info: TxInfoProps | null;
187
+ request_id?: string | null;
188
+ gas?: bigint | null;
189
+ maxFeePerGas?: bigint | undefined;
190
+ maxPriorityFeePerGas?: bigint | undefined;
191
+ backApprove?: boolean;
192
+ router_type?: string | null;
193
+ tx_value?: string | null;
194
+ points?: number | 0 | string;
195
+ quote_message?: string | null;
196
+ routes?: routesItem[];
197
+ solanaTxMessage?: string;
198
+ solanaTxSender?: string;
199
+ }
200
+ interface QuoteRequestWithToTokenDecimals extends QuoteRequest {
201
+ toTokenDecimals: number;
202
+ isAutoRefetch?: boolean;
203
+ affiliation?: string | null;
204
+ }
205
+ declare const initialQuoteInfo: QuoteInfo;
206
+ declare const WheelXWidget: ({ config }: WheelXWidgetProps) => react_jsx_runtime.JSX.Element;
207
+
208
+ declare const defaultTheme: WidgetTheme;
209
+
210
+ interface WidgetThemeContextValue {
211
+ theme: WidgetTheme;
212
+ }
213
+ declare const useWidgetTheme: () => WidgetThemeContextValue;
214
+ interface WidgetThemeProviderProps {
215
+ theme?: Partial<WidgetTheme>;
216
+ children: React.ReactNode;
217
+ }
218
+ declare const WidgetThemeProvider: React.FC<WidgetThemeProviderProps>;
219
+
220
+ interface SwapState {
221
+ fromTokenInfo: TokenInfo;
222
+ toTokenInfo: TokenInfo;
223
+ fromAmount: string;
224
+ toAmount: string;
225
+ slippage?: string;
226
+ fromAmountToUsd?: string | null;
227
+ toAmountToUsd?: string | null;
228
+ isShortLink?: boolean;
229
+ shortLink?: string;
230
+ transactionType?: string;
231
+ autoSlippage?: number | undefined;
232
+ tradeType?: string | null;
233
+ }
234
+ interface SwapAndBridgeContextStore extends SwapState {
235
+ setFromTokenInfo: (tokenInfo: TokenInfo) => void;
236
+ setToTokenInfo: (tokenInfo: TokenInfo) => void;
237
+ setFromAmount: (amount: string) => void;
238
+ setToAmount: (amount: string) => void;
239
+ switchTokens: () => void;
240
+ resetState: () => void;
241
+ setAmounts: (fromAmount: string, toAmount: string) => void;
242
+ resetAmounts: () => void;
243
+ setSlippage: (slippage?: string) => void;
244
+ setFromAmountToUsd: (value: string | null) => void;
245
+ setToAmountToUsd: (value: string | null) => void;
246
+ setIsShortLink: (value: boolean) => void;
247
+ setShortLink: (value: string) => void;
248
+ setTransactionType: (value: string) => void;
249
+ setAutoSlippage: (value: number | undefined) => void;
250
+ }
251
+ declare const useSwapAndBridgeContextStore: zustand.UseBoundStore<zustand.StoreApi<SwapAndBridgeContextStore>>;
252
+ declare const useInitSwapAndBridgeState: (config?: WidgetConfig) => void;
253
+ declare const useResetSwapAndBridgeState: () => void;
254
+
255
+ interface TxStateContextStore {
256
+ fromTxHash: `0x${string}` | null;
257
+ toTxHash: `0x${string}` | null;
258
+ setFromTxHash: (fromTxHash: `0x${string}` | null) => void;
259
+ setToTxHash: (toTxHash: `0x${string}` | null) => void;
260
+ resetTxState: () => void;
261
+ startTrading: boolean;
262
+ setStartTrading: (startTrading: boolean) => void;
263
+ userCancelsTransaction: boolean;
264
+ setUserCancelsTransaction: (userCancelsTransaction: boolean) => void;
265
+ fromValue?: string | null;
266
+ setFromValue?: (fromValue: string | null) => void;
267
+ tryAgain?: boolean;
268
+ setTryAgain: (tryAgain: boolean) => void;
269
+ solanaFromTxHash: string | null;
270
+ setSolanaFromTxHash: (hash: string | null) => void;
271
+ isSolanaTransaction: boolean;
272
+ setIsSolanaTransaction: (isSolana: boolean) => void;
273
+ }
274
+ declare const useTxStateContextStore: zustand.UseBoundStore<zustand.StoreApi<TxStateContextStore>>;
275
+
276
+ declare const useGuardChain: (callback: () => void, requiredChainId: number) => {
277
+ isSwitching: boolean;
278
+ sendTx: () => Promise<void>;
279
+ };
280
+
281
+ declare const useRefreshLoading: () => {
282
+ isLoading: boolean;
283
+ startLoading: () => void;
284
+ };
285
+
286
+ interface Props {
287
+ chainId: number;
288
+ tokenAddress?: `0x${string}`;
289
+ connectAddress?: `0x${string}`;
290
+ }
291
+ interface BalanceResult {
292
+ decimals: number;
293
+ formatted: string;
294
+ symbol: string;
295
+ value: bigint;
296
+ }
297
+ declare const useTokenBalance: ({ chainId, tokenAddress, connectAddress }: Props) => BalanceResult | undefined;
298
+
299
+ interface ChainsStore {
300
+ chains: ChainInfo[] | null;
301
+ setChains: (chains: ChainInfo[]) => void;
302
+ isSelectPredictionChain: boolean;
303
+ setIsSelectPredictionChain: (isSelectPredictionChain: boolean) => void;
304
+ slippagePolicies: SlippagePolicy[] | null;
305
+ setSlippagePolicies: (policies: SlippagePolicy[]) => void;
306
+ }
307
+ interface TokenStore {
308
+ tokens: TokenInfo[] | null;
309
+ setTokens: (tokens: TokenInfo[]) => void;
310
+ }
311
+ declare const useChainsStore: zustand.UseBoundStore<zustand.StoreApi<ChainsStore>>;
312
+ declare const useTokensStore: zustand.UseBoundStore<zustand.StoreApi<TokenStore>>;
313
+
314
+ /**
315
+ * Hook to get EVM wallet address with fallback to saved address.
316
+ *
317
+ * Priority: saved evmWalletAddress > current wagmi address (only when store says connected).
318
+ *
319
+ * CRITICAL: The store is the single source of truth for connection state.
320
+ * After user disconnects, even if wagmi briefly shows connected (e.g. due to
321
+ * DynamicWagmiConnector reconnecting), we must NOT use wagmi's address as
322
+ * fallback — otherwise the UI will continue to show address/balance info
323
+ * after the user has explicitly disconnected.
324
+ *
325
+ * @returns The EVM wallet address, or undefined if not connected.
326
+ */
327
+ declare const useEvmAddress: () => `0x${string}` | undefined;
328
+
329
+ interface WalletStore {
330
+ isEthWalletConnected: boolean;
331
+ setIsEthWalletConnected: (isEthWalletConnected: boolean) => void;
332
+ isSolanaWalletConnected: boolean;
333
+ setIsSolanaWalletConnected: (isSolanaWalletConnected: boolean) => void;
334
+ totalConnectedWallets: number;
335
+ setTotalConnectedWallets: () => void;
336
+ totalWallets: number;
337
+ solanaWalletAddress: string | null;
338
+ setSolanaWalletAddress: (address: string | null) => void;
339
+ evmWalletAddress: string | null;
340
+ evmWalletConnectorId: string | null;
341
+ setEvmWalletInfo: (address: string | null, connectorId: string | null) => void;
342
+ isEvmWalletMetamask: boolean;
343
+ setIsEvmWalletMetamask: (isEvmWalletMetamask: boolean) => void;
344
+ isLoggingOut: boolean;
345
+ setIsLoggingOut: (isLoggingOut: boolean) => void;
346
+ /** Timestamp (ms) of the most recent manual disconnect. Used to guard
347
+ * against DynamicWagmiConnector auto-reconnecting right after logout. */
348
+ lastDisconnectTimestamp: number;
349
+ setLastDisconnectTimestamp: (ts: number) => void;
350
+ }
351
+ declare const useWalletConnectedStore: zustand.UseBoundStore<zustand.StoreApi<WalletStore>>;
352
+
353
+ interface DifferentAddressProp {
354
+ differentAddress: `0x${string}` | undefined | string;
355
+ setDifferentAddress: (address: `0x${string}` | undefined | string) => void;
356
+ isDepositPlatformToken: boolean;
357
+ setIsDepositPlatformToken: (isDepositPlatformToken: boolean) => void;
358
+ }
359
+ declare const useDifferentAddressStore: zustand.UseBoundStore<zustand.StoreApi<DifferentAddressProp>>;
360
+
361
+ declare const useSyncWalletConnectedStore: () => void;
362
+
363
+ export { type ChainInfo, type ChainsAndTokens, type FeeLevel, type QuoteErrorType, type QuoteInfo, type QuoteMutationError, type QuoteRequest, type QuoteRequestWithToTokenDecimals, type RefetchQuoteParams, type SlippagePolicy, type TokenConfig, type TokenInfo, type TxInfoProps, WheelXProvider, type WheelXProviderProps, WheelXWidget, type WheelXWidgetProps, type WidgetConfig, type WidgetTheme, WidgetThemeProvider, defaultTheme, getChainsAndTokens, initialQuoteInfo, mergeTokensWithCompositeKey, useChainsAndTokens, useChainsStore, useDifferentAddressStore, useEvmAddress, useGuardChain, useInitSwapAndBridgeState, useRefreshLoading, useResetSwapAndBridgeState, useSwapAndBridgeContextStore, useSyncWalletConnectedStore, useTokenBalance, useTokensStore, useTxStateContextStore, useWalletConnectedStore, useWidgetTheme };