@liberfi.io/ui-trade 0.1.2 → 0.1.3
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/README.md +194 -3
- package/dist/index.d.mts +273 -2
- package/dist/index.d.ts +273 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -9
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import * as _liberfi_io_types from '@liberfi.io/types';
|
|
|
2
2
|
import { Chain, API, Token, Portfolio } from '@liberfi.io/types';
|
|
3
3
|
import { WalletAdapter } from '@liberfi.io/wallet-connector';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
import { PredefinedToken } from '@liberfi.io/utils';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Input parameters for the `swap()` function returned by {@link useSwap}.
|
|
@@ -61,6 +63,29 @@ interface UseSwapRoutePollingOptions {
|
|
|
61
63
|
/** Called when a route fetch fails. */
|
|
62
64
|
onError?: (error: Error) => void;
|
|
63
65
|
}
|
|
66
|
+
/** Configuration values for a single trade preset (slippage, fees, MEV). */
|
|
67
|
+
interface TradePresetValues {
|
|
68
|
+
/** Slippage tolerance, 0-100 (percent). `null` = use default. */
|
|
69
|
+
slippage: number | null;
|
|
70
|
+
/** Priority fee in native token units. `null` = use default. */
|
|
71
|
+
priorityFee: number | null;
|
|
72
|
+
/** Tip fee in native token units. `null` = use default. */
|
|
73
|
+
tipFee: number | null;
|
|
74
|
+
/** Whether automatic fee estimation is enabled. */
|
|
75
|
+
autoFee: boolean;
|
|
76
|
+
/** Maximum fee cap when auto-fee is on (native token units). */
|
|
77
|
+
maxAutoFee: number | null;
|
|
78
|
+
/** Anti-MEV protection level. */
|
|
79
|
+
antiMev: "off" | "reduced" | "secure";
|
|
80
|
+
/** Custom RPC endpoint URL. `null` = use default. */
|
|
81
|
+
customRPC: string | null;
|
|
82
|
+
}
|
|
83
|
+
/** Default preset values matching Solana-typical settings. */
|
|
84
|
+
declare const DEFAULT_TRADE_PRESET: TradePresetValues;
|
|
85
|
+
/** Default quick-buy amounts (native token units). */
|
|
86
|
+
declare const DEFAULT_BUY_AMOUNTS: number[];
|
|
87
|
+
/** Default quick-sell percentages. */
|
|
88
|
+
declare const DEFAULT_SELL_PERCENTAGES: number[];
|
|
64
89
|
/** Confirmation status of a tracked transaction. */
|
|
65
90
|
type TxConfirmationStatus = "idle" | "pending" | "confirmed" | "failed";
|
|
66
91
|
/** Options for the {@link useTxConfirmation} hook. */
|
|
@@ -317,6 +342,252 @@ declare function SwapUI({ fromToken, toToken, fromBalance, toBalance, amount, am
|
|
|
317
342
|
*/
|
|
318
343
|
declare function SwapPreviewModal({ isOpen, onOpenChange, fromToken, toToken, fromBalance, inputAmount, inputAmountInUsd, outputAmount, outputAmountInUsd, route, isRouting, routeError, onConfirm, isSwapping, }: SwapPreviewModalProps): react_jsx_runtime.JSX.Element;
|
|
319
344
|
|
|
345
|
+
/** Parameters for {@link useInstantTradeScript}. */
|
|
346
|
+
interface UseInstantTradeScriptParams {
|
|
347
|
+
/** Target chain */
|
|
348
|
+
chain: Chain;
|
|
349
|
+
/** Address of the token being traded (the non-native side) */
|
|
350
|
+
tokenAddress: string;
|
|
351
|
+
/** Called when a swap transaction is successfully submitted */
|
|
352
|
+
onSwapSubmitted?: (result: SwapResult) => void;
|
|
353
|
+
/** Called when a swap error occurs at any phase */
|
|
354
|
+
onSwapError?: (error: Error, phase: SwapPhase) => void;
|
|
355
|
+
}
|
|
356
|
+
/** Return value of {@link useInstantTradeScript}. */
|
|
357
|
+
interface UseInstantTradeScriptResult {
|
|
358
|
+
chain: Chain;
|
|
359
|
+
tokenAddress: string;
|
|
360
|
+
nativeToken: PredefinedToken | undefined;
|
|
361
|
+
tokenInfo: Token | null;
|
|
362
|
+
nativeBalance: Portfolio | null;
|
|
363
|
+
tokenBalance: Portfolio | null;
|
|
364
|
+
direction: "buy" | "sell";
|
|
365
|
+
setDirection: (d: "buy" | "sell") => void;
|
|
366
|
+
amount: number | undefined;
|
|
367
|
+
setAmount: (v: number | undefined) => void;
|
|
368
|
+
buyPreset: number;
|
|
369
|
+
setBuyPreset: (p: number) => void;
|
|
370
|
+
sellPreset: number;
|
|
371
|
+
setSellPreset: (p: number) => void;
|
|
372
|
+
currentPresetValues: TradePresetValues;
|
|
373
|
+
settings: InstantTradeSettings;
|
|
374
|
+
updateBuySettings: (s: BuySettings) => void;
|
|
375
|
+
updateSellSettings: (s: SellSettings) => void;
|
|
376
|
+
showSettings: boolean;
|
|
377
|
+
handlePresetClick: (preset: number) => void;
|
|
378
|
+
swap: () => Promise<void>;
|
|
379
|
+
isSwapping: boolean;
|
|
380
|
+
submitText: string;
|
|
381
|
+
isDisabled: boolean;
|
|
382
|
+
isLoading: boolean;
|
|
383
|
+
}
|
|
384
|
+
/** Props for {@link InstantTradeWidget}. */
|
|
385
|
+
interface InstantTradeWidgetProps {
|
|
386
|
+
/** Target chain */
|
|
387
|
+
chain: Chain;
|
|
388
|
+
/** Address of the token being traded */
|
|
389
|
+
tokenAddress: string;
|
|
390
|
+
/** Called when a swap transaction is submitted */
|
|
391
|
+
onSwapSubmitted?: (result: SwapResult) => void;
|
|
392
|
+
/** Called on swap error */
|
|
393
|
+
onSwapError?: (error: Error, phase: SwapPhase) => void;
|
|
394
|
+
/** Controlled settings (omit for localStorage fallback) */
|
|
395
|
+
settings?: InstantTradeSettings;
|
|
396
|
+
/** Called when settings change */
|
|
397
|
+
onSettingsChange?: (settings: InstantTradeSettings) => void;
|
|
398
|
+
/** Slot rendered next to trade-type tabs (e.g. wallet switcher) */
|
|
399
|
+
headerExtra?: ReactNode;
|
|
400
|
+
/** External style customization */
|
|
401
|
+
className?: string;
|
|
402
|
+
}
|
|
403
|
+
/** Props for {@link InstantTradeUI}. */
|
|
404
|
+
interface InstantTradeUIProps {
|
|
405
|
+
direction: "buy" | "sell";
|
|
406
|
+
onDirectionChange: (d: "buy" | "sell") => void;
|
|
407
|
+
amount: number | undefined;
|
|
408
|
+
onAmountChange: (v: number | undefined) => void;
|
|
409
|
+
customAmounts: (number | null)[];
|
|
410
|
+
customPercentages: (number | null)[];
|
|
411
|
+
onQuickAmountClick: (v: number) => void;
|
|
412
|
+
onQuickPercentageClick: (percent: number) => void;
|
|
413
|
+
onCustomAmountsEdit: (amounts: (number | null)[]) => void;
|
|
414
|
+
onCustomPercentagesEdit: (pcts: (number | null)[]) => void;
|
|
415
|
+
tokenSymbol?: string;
|
|
416
|
+
nativeSymbol?: string;
|
|
417
|
+
nativeDecimals?: number;
|
|
418
|
+
nativeBalance?: string;
|
|
419
|
+
tokenBalance?: string;
|
|
420
|
+
amountConversion?: string;
|
|
421
|
+
preset: number;
|
|
422
|
+
onPresetChange: (p: number) => void;
|
|
423
|
+
presetValues: TradePresetValues;
|
|
424
|
+
onPresetSettingsChange: (v: TradePresetValues) => void;
|
|
425
|
+
showSettings: boolean;
|
|
426
|
+
onPresetClick: (preset: number) => void;
|
|
427
|
+
submitText: string;
|
|
428
|
+
isDisabled: boolean;
|
|
429
|
+
isLoading: boolean;
|
|
430
|
+
onSubmit: () => void;
|
|
431
|
+
className?: string;
|
|
432
|
+
headerExtra?: ReactNode;
|
|
433
|
+
}
|
|
434
|
+
/** Value exposed by {@link InstantTradeContext}. */
|
|
435
|
+
interface InstantTradeContextValue {
|
|
436
|
+
chain: Chain;
|
|
437
|
+
tokenAddress: string;
|
|
438
|
+
nativeToken: PredefinedToken | undefined;
|
|
439
|
+
direction: "buy" | "sell";
|
|
440
|
+
setDirection: (d: "buy" | "sell") => void;
|
|
441
|
+
/** Quick-trade amount (native token units for buy, token units for sell). */
|
|
442
|
+
amount: number | undefined;
|
|
443
|
+
setAmount: (v: number | undefined) => void;
|
|
444
|
+
buyPreset: number;
|
|
445
|
+
setBuyPreset: (p: number) => void;
|
|
446
|
+
sellPreset: number;
|
|
447
|
+
setSellPreset: (p: number) => void;
|
|
448
|
+
settings: InstantTradeSettings;
|
|
449
|
+
updateBuySettings: (s: BuySettings) => void;
|
|
450
|
+
updateSellSettings: (s: SellSettings) => void;
|
|
451
|
+
currentPresetValues: TradePresetValues;
|
|
452
|
+
}
|
|
453
|
+
/** Props for {@link InstantTradeProvider}. */
|
|
454
|
+
interface InstantTradeProviderProps {
|
|
455
|
+
/** Target chain */
|
|
456
|
+
chain: Chain;
|
|
457
|
+
/** Address of the token being traded */
|
|
458
|
+
tokenAddress: string;
|
|
459
|
+
/** Controlled settings (omit for built-in localStorage persistence) */
|
|
460
|
+
settings?: InstantTradeSettings;
|
|
461
|
+
/** Called when settings change */
|
|
462
|
+
onSettingsChange?: (settings: InstantTradeSettings) => void;
|
|
463
|
+
children: ReactNode;
|
|
464
|
+
}
|
|
465
|
+
/** Props for {@link InstantTradeAmountInput}. */
|
|
466
|
+
interface InstantTradeAmountInputProps {
|
|
467
|
+
amount?: number;
|
|
468
|
+
onAmountChange: (amount?: number) => void;
|
|
469
|
+
preset?: number;
|
|
470
|
+
onPresetChange?: (preset: number) => void;
|
|
471
|
+
/** Called when an already-selected preset is clicked (e.g. open settings) */
|
|
472
|
+
onPresetClick?: (preset: number) => void;
|
|
473
|
+
variant?: "default" | "bordered";
|
|
474
|
+
radius?: "full" | "lg" | "md" | "sm";
|
|
475
|
+
size?: "sm" | "lg";
|
|
476
|
+
fullWidth?: boolean;
|
|
477
|
+
className?: string;
|
|
478
|
+
}
|
|
479
|
+
/** Props for {@link InstantTradeButton}. */
|
|
480
|
+
interface InstantTradeButtonProps {
|
|
481
|
+
className?: string;
|
|
482
|
+
children?: ReactNode;
|
|
483
|
+
}
|
|
484
|
+
/** Props for {@link PresetFormUI}. */
|
|
485
|
+
interface PresetFormUIProps {
|
|
486
|
+
value: TradePresetValues;
|
|
487
|
+
onChange: (value: TradePresetValues) => void;
|
|
488
|
+
nativeSymbol?: string;
|
|
489
|
+
nativeDecimals?: number;
|
|
490
|
+
className?: string;
|
|
491
|
+
}
|
|
492
|
+
/** Props for {@link PresetFormWidget}. */
|
|
493
|
+
interface PresetFormWidgetProps {
|
|
494
|
+
value: TradePresetValues;
|
|
495
|
+
onChange: (value: TradePresetValues) => void;
|
|
496
|
+
chain: Chain;
|
|
497
|
+
className?: string;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** Buy-side trade settings. */
|
|
501
|
+
interface BuySettings {
|
|
502
|
+
/** Four customizable quick-amount buttons (native token units) */
|
|
503
|
+
customAmounts: (number | null)[];
|
|
504
|
+
/** Three preset configurations */
|
|
505
|
+
presets: TradePresetValues[];
|
|
506
|
+
}
|
|
507
|
+
/** Sell-side trade settings. */
|
|
508
|
+
interface SellSettings {
|
|
509
|
+
/** Four customizable quick-percentage buttons (0-100) */
|
|
510
|
+
customPercentages: (number | null)[];
|
|
511
|
+
/** Three preset configurations */
|
|
512
|
+
presets: TradePresetValues[];
|
|
513
|
+
}
|
|
514
|
+
/** Combined buy + sell settings for instant trade. */
|
|
515
|
+
interface InstantTradeSettings {
|
|
516
|
+
buy: BuySettings;
|
|
517
|
+
sell: SellSettings;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
declare const DEFAULT_INSTANT_TRADE_SETTINGS: InstantTradeSettings;
|
|
521
|
+
/** Access the nearest {@link InstantTradeProvider}. Throws if none found. */
|
|
522
|
+
declare function useInstantTrade(): InstantTradeContextValue;
|
|
523
|
+
/**
|
|
524
|
+
* Provides instant-trade state to descendant components.
|
|
525
|
+
*
|
|
526
|
+
* Settings follow a controlled / uncontrolled pattern:
|
|
527
|
+
* - **Controlled**: pass `settings` + `onSettingsChange` props.
|
|
528
|
+
* - **Uncontrolled** (default): settings auto-persist to localStorage keyed by chain.
|
|
529
|
+
*/
|
|
530
|
+
declare function InstantTradeProvider({ chain, tokenAddress, settings: controlledSettings, onSettingsChange, children, }: InstantTradeProviderProps): react_jsx_runtime.JSX.Element;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Script hook that encapsulates all data and state for the instant trade form.
|
|
534
|
+
*
|
|
535
|
+
* Must be used inside an {@link InstantTradeProvider}.
|
|
536
|
+
* Pure TypeScript — no JSX, no UI imports.
|
|
537
|
+
*/
|
|
538
|
+
declare function useInstantTradeScript(params: UseInstantTradeScriptParams): UseInstantTradeScriptResult;
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Full instant-trade widget — thin orchestration layer.
|
|
542
|
+
*
|
|
543
|
+
* Wraps `InstantTradeProvider`, calls `useInstantTradeScript` to get all data,
|
|
544
|
+
* and renders `InstantTradeUI` as the presentational layer.
|
|
545
|
+
*
|
|
546
|
+
* For custom UIs, use `useInstantTradeScript` directly inside an
|
|
547
|
+
* `InstantTradeProvider` with your own presentation.
|
|
548
|
+
*/
|
|
549
|
+
declare function InstantTradeWidget({ chain, tokenAddress, onSwapSubmitted, onSwapError, settings, onSettingsChange, headerExtra, className, }: InstantTradeWidgetProps): react_jsx_runtime.JSX.Element;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Preset form widget — thin orchestration layer.
|
|
553
|
+
*
|
|
554
|
+
* Manages local state initialized from `value`, resolves chain-specific
|
|
555
|
+
* native token info, and syncs changes upward via `onChange`.
|
|
556
|
+
*/
|
|
557
|
+
declare function PresetFormWidget({ value, onChange, chain, className, }: PresetFormWidgetProps): react_jsx_runtime.JSX.Element;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Pure presentational component for the instant trade form.
|
|
561
|
+
*
|
|
562
|
+
* Receives all data and callbacks via props — no API calls, no context access.
|
|
563
|
+
* Consumers can replace this component while reusing `useInstantTradeScript`.
|
|
564
|
+
*/
|
|
565
|
+
declare function InstantTradeUI({ direction, onDirectionChange, amount, onAmountChange, customAmounts, customPercentages, onQuickAmountClick, onQuickPercentageClick, onCustomAmountsEdit, onCustomPercentagesEdit, tokenSymbol, nativeSymbol, nativeDecimals, nativeBalance, tokenBalance, amountConversion, preset, onPresetChange, presetValues, onPresetSettingsChange, showSettings, onPresetClick, submitText, isDisabled, isLoading, onSubmit, className, headerExtra, }: InstantTradeUIProps): react_jsx_runtime.JSX.Element;
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Pure presentational preset-settings form.
|
|
569
|
+
*
|
|
570
|
+
* Renders inputs for slippage, priority fee, tip fee, auto fee,
|
|
571
|
+
* max auto fee, anti-MEV and custom RPC. All data via props.
|
|
572
|
+
*/
|
|
573
|
+
declare function PresetFormUI({ value, onChange, nativeSymbol, nativeDecimals, className, }: PresetFormUIProps): react_jsx_runtime.JSX.Element;
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Compact amount input with preset selector buttons.
|
|
577
|
+
*
|
|
578
|
+
* Designed for inline/header usage (e.g. token detail page).
|
|
579
|
+
* Must be rendered inside an {@link InstantTradeProvider}.
|
|
580
|
+
*/
|
|
581
|
+
declare function InstantTradeAmountInput({ amount, onAmountChange, preset, onPresetChange, onPresetClick, variant, radius, size, fullWidth, className, }: InstantTradeAmountInputProps): react_jsx_runtime.JSX.Element;
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Trade execution button that reads state from {@link InstantTradeProvider}.
|
|
585
|
+
*
|
|
586
|
+
* Resolves wallet, token addresses, converts amounts, applies preset
|
|
587
|
+
* settings, and calls `useSwap` from the SDK.
|
|
588
|
+
*/
|
|
589
|
+
declare function InstantTradeButton({ className, children, }: InstantTradeButtonProps): react_jsx_runtime.JSX.Element;
|
|
590
|
+
|
|
320
591
|
declare global {
|
|
321
592
|
interface Window {
|
|
322
593
|
__LIBERFI_VERSION__?: {
|
|
@@ -324,6 +595,6 @@ declare global {
|
|
|
324
595
|
};
|
|
325
596
|
}
|
|
326
597
|
}
|
|
327
|
-
declare const _default: "0.1.
|
|
598
|
+
declare const _default: "0.1.3";
|
|
328
599
|
|
|
329
|
-
export { type SwapInput, type SwapPhase, SwapPreviewModal, type SwapPreviewModalProps, type SwapResult, SwapUI, type SwapUIProps, SwapWidget, type SwapWidgetProps, type TxConfirmationStatus, type UseSwapOptions, type UseSwapRoutePollingOptions, type UseSwapScriptParams, type UseSwapScriptResult, type UseTxConfirmationOptions, useSwap, useSwapRoutePolling, useSwapScript, useTxConfirmation, _default as version };
|
|
600
|
+
export { type BuySettings, DEFAULT_BUY_AMOUNTS, DEFAULT_INSTANT_TRADE_SETTINGS, DEFAULT_SELL_PERCENTAGES, DEFAULT_TRADE_PRESET, InstantTradeAmountInput, type InstantTradeAmountInputProps, InstantTradeButton, type InstantTradeButtonProps, type InstantTradeContextValue, InstantTradeProvider, type InstantTradeProviderProps, type InstantTradeSettings, InstantTradeUI, type InstantTradeUIProps, InstantTradeWidget, type InstantTradeWidgetProps, PresetFormUI, type PresetFormUIProps, PresetFormWidget, type PresetFormWidgetProps, type SellSettings, type SwapInput, type SwapPhase, SwapPreviewModal, type SwapPreviewModalProps, type SwapResult, SwapUI, type SwapUIProps, SwapWidget, type SwapWidgetProps, type TradePresetValues, type TxConfirmationStatus, type UseInstantTradeScriptParams, type UseInstantTradeScriptResult, type UseSwapOptions, type UseSwapRoutePollingOptions, type UseSwapScriptParams, type UseSwapScriptResult, type UseTxConfirmationOptions, useInstantTrade, useInstantTradeScript, useSwap, useSwapRoutePolling, useSwapScript, useTxConfirmation, _default as version };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var react$1=require('react'),react=require('@liberfi.io/react'),types=require('@liberfi.io/types'),walletConnector=require('@liberfi.io/wallet-connector'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime');function Fe(e){let t=atob(e),u=new Uint8Array(t.length);for(let i=0;i<t.length;i++)u[i]=t.charCodeAt(i);return u}function Me(e){let t="";for(let u=0;u<e.length;u++)t+=String.fromCharCode(e[u]);return btoa(t)}function ie(e){let{client:t}=react.useDexClient(),[u,i]=react$1.useState(false),a=react$1.useRef(e);a.current=e;let n=react$1.useCallback(async d=>{let{wallet:m,chain:p,...r}=d;i(true);try{let l;try{l=await t.swapRoute({chain:p,userAddress:m.address,input:r.input,output:r.output,mode:r.mode??types.API.SwapMode.EXACT_IN,amount:r.amount,slippage:r.slippage,priorityFee:r.priorityFee,tipFee:r.tipFee,isAntiMev:r.isAntiMev,permit:r.permit,deadline:r.deadline});}catch(s){let S=s instanceof Error?s:new Error(String(s));throw a.current?.onError?.(S,"route"),S}let h;try{let s=Fe(l.serializedTx);h=await m.signTransaction(s);}catch(s){let S=s instanceof Error?s:new Error(String(s));throw a.current?.onError?.(S,"sign"),S}let f;try{let s=Me(h);f=await t.sendTx({chain:p,serializedTx:s});}catch(s){let S=s instanceof Error?s:new Error(String(s));throw a.current?.onError?.(S,"send"),S}let w={txHash:f.txHash,extra:f.extra};return a.current?.onSubmitted?.(w),w}finally{i(false);}},[t]);return react$1.useMemo(()=>({swap:n,isSwapping:u}),[n,u])}var Le=12e3;function ae(e,t){let u=t?.interval??Le,i=t?.paused??false,a=react$1.useRef(t);a.current=t;let d=!!e.chain&&!!e.userAddress&&!!e.input&&!!e.output&&!!e.amount&&!i,m=react.useSwapRouteQuery(e,{enabled:d,refetchInterval:d?u:false,retry:false});return react$1.useEffect(()=>{m.error&&a.current?.onError?.(m.error);},[m.error]),react$1.useMemo(()=>({route:m.data,isRouting:m.isFetching,error:m.error}),[m.data,m.isFetching,m.error])}var je=6e4;function ue(e){let{client:t}=react.useDexClient(),[u,i]=react$1.useState(()=>new Map),a=react$1.useRef(e);a.current=e;let n=react$1.useCallback((r,l)=>{i(h=>{let f=h.get(r);if(!f||f.status===l)return h;let w=new Map(h);return w.set(r,{...f,status:l}),w});},[]),d=react$1.useCallback((r,l)=>{i(f=>{if(f.has(l))return f;let w=new Map(f);return w.set(l,{chain:r,txHash:l,status:"pending"}),w});let h=a.current?.timeout??je;t.checkTxSuccess(r,l,h).then(f=>{if(f)n(l,"confirmed"),a.current?.onConfirmed?.(l);else {let w=new Error("Transaction failed on-chain");n(l,"failed"),a.current?.onFailed?.(l,w);}}).catch(f=>{let w=f instanceof Error?f:new Error(String(f));n(l,"failed"),a.current?.onFailed?.(l,w);});},[t,n]),m=react$1.useCallback(r=>{i(l=>{if(!l.has(r))return l;let h=new Map(l);return h.delete(r),h});},[]),p=react$1.useCallback(()=>{i(r=>r.size===0?r:new Map);},[]);return react$1.useMemo(()=>({track:d,clear:m,clearAll:p,transactions:u}),[d,m,p,u])}var Qe=new Set([types.Chain.SOLANA,types.Chain.SOLANA_TESTNET,types.Chain.SOLANA_DEVNET]);function Ke(e){return Qe.has(e)?types.ChainNamespace.SOLANA:types.ChainNamespace.EVM}var Xe=1e4,qe=15e3;function Ge(e,t){if(e.length===0)return;let i=e[e.length-1].outputAmount;if(!i||i==="0")return "0";let a=i.padStart(t+1,"0"),n=a.slice(0,a.length-t)||"0",m=a.slice(a.length-t).replace(/0+$/,"");return m?`${n}.${m}`:n}function j(e){let{chain:t}=e,u=walletConnector.useWallets(),i=Ke(t),a=react$1.useMemo(()=>u.find(o=>o.chainNamespace===i&&o.isConnected),[u,i]),n=a?.address??"",[d,m]=react$1.useState(e.from??""),[p,r]=react$1.useState(e.to??""),l=react$1.useRef(e.from),h=react$1.useRef(e.to);react$1.useEffect(()=>{e.from!==l.current&&(l.current=e.from,e.from&&m(e.from));},[e.from]),react$1.useEffect(()=>{e.to!==h.current&&(h.current=e.to,e.to&&r(e.to));},[e.to]);let f=react$1.useMemo(()=>[d,p].filter(Boolean),[d,p]),w=react.useTokensQuery({chain:t,addresses:f},{enabled:f.length>0,refetchInterval:Xe}),s=react$1.useMemo(()=>w.data?.find(o=>o.address===d)??null,[w.data,d]),S=react$1.useMemo(()=>w.data?.find(o=>o.address===p)??null,[w.data,p]),C=react.useWalletPortfoliosByTokensQuery({chain:t,address:n,tokenAddresses:f},{enabled:!!n&&f.length>0,refetchInterval:qe}),b=react$1.useMemo(()=>C.data?.find(o=>o.address===d)??null,[C.data,d]),g=react$1.useMemo(()=>C.data?.find(o=>o.address===p)??null,[C.data,p]),[A,T]=react$1.useState(void 0),P=react$1.useMemo(()=>{if(!A||s?.decimals==null)return;let o=A.split("."),I=o[0]??"0",ye=(o[1]??"").slice(0,s.decimals).padEnd(s.decimals,"0");return (I+ye).replace(/^0+/,"")||"0"},[A,s?.decimals]),X=react$1.useMemo(()=>{if(!A||!s?.marketData?.priceInUsd)return;let o=Number(s.marketData.priceInUsd),I=Number(A)*o;return Number.isFinite(I)?I.toString():void 0},[A,s?.marketData?.priceInUsd]),q=react$1.useCallback(()=>{if(!b)return;let o=Number(b.amount);if(!Number.isFinite(o)||o<=0)return;let I=o/2,oe=s?.decimals??9;T(I.toLocaleString("en-US",{useGrouping:false,maximumFractionDigits:oe}));},[b,s?.decimals]),G=react$1.useCallback(()=>{if(!b)return;let o=Number(b.amount);if(!Number.isFinite(o)||o<=0)return;let I=s?.decimals??9;T(o.toLocaleString("en-US",{useGrouping:false,maximumFractionDigits:I}));},[b,s?.decimals]),be=react$1.useMemo(()=>({chain:t,userAddress:n||void 0,input:d||void 0,output:p||void 0,mode:types.API.SwapMode.EXACT_IN,amount:P}),[t,n,d,p,P]),Z=react$1.useRef(false),{route:U,isRouting:H,error:J}=ae(be,{paused:Z.current}),F=react$1.useMemo(()=>U&&S?Ge(U.plans,S.decimals):void 0,[U,S]),Y=react$1.useMemo(()=>{if(!F||!S?.marketData?.priceInUsd)return;let o=Number(S.marketData.priceInUsd),I=Number(F)*o;return Number.isFinite(I)?I.toString():void 0},[F,S?.marketData?.priceInUsd]),{swap:ee,isSwapping:k}=ie();Z.current=k;let L=react$1.useRef(e.onComplete);L.current=e.onComplete;let{track:te,transactions:D}=ue({onConfirmed:o=>{L.current?.({success:true,txHash:o});},onFailed:o=>{L.current?.({success:false,txHash:o});}}),ne=react$1.useMemo(()=>{if(D.size===0)return "idle";let o=Array.from(D.values());return o[o.length-1].status},[D]),re=react$1.useCallback(async()=>{if(!(!a||!U||!d||!p||!P))try{let o=await ee({chain:t,wallet:a,input:d,output:p,amount:P,mode:types.API.SwapMode.EXACT_IN});te(t,o.txHash);}catch{}},[a,U,t,d,p,P,ee,te]),se=w.isPending||C.isPending;return react$1.useMemo(()=>({fromTokenAddress:d,toTokenAddress:p,setFromTokenAddress:m,setToTokenAddress:r,fromToken:s,toToken:S,fromBalance:b,toBalance:g,amount:A,setAmount:T,setHalfAmount:q,setMaxAmount:G,amountInDecimals:P,amountInUsd:X,outputAmount:F,outputAmountInUsd:Y,route:U,isRouting:H,routeError:J,swap:re,isSwapping:k,txStatus:ne,isLoading:se}),[d,p,s,S,b,g,A,q,G,P,X,F,Y,U,H,J,re,k,ne,se])}function V({isOpen:e,onOpenChange:t,fromToken:u,toToken:i,fromBalance:a,inputAmount:n,inputAmountInUsd:d,outputAmount:m,outputAmountInUsd:p,route:r,isRouting:l,routeError:h,onConfirm:f,isSwapping:w}){let[s,S]=react$1.useState(false),C=react$1.useCallback(()=>S(g=>!g),[]),b=react$1.useMemo(()=>r?r.plans.map((g,A)=>({key:`plan-${A}`,name:g.name,input:g.input,inputAmount:g.inputAmount,output:g.output,outputAmount:g.outputAmount,feeQuote:g.feeQuote,feeAmount:g.feeAmount})):[],[r]);return jsxRuntime.jsx(ui.Modal,{isOpen:e,onOpenChange:t,hideCloseButton:true,scrollBehavior:"inside",backdrop:"blur",children:jsxRuntime.jsxs(ui.ModalContent,{className:"bg-content2 rounded-lg",children:[jsxRuntime.jsx(ui.ModalHeader,{children:"Preview"}),jsxRuntime.jsx(ui.ModalBody,{children:jsxRuntime.jsxs("div",{className:"flex w-full max-h-[70vh] flex-1 flex-col overflow-y-auto py-2",children:[jsxRuntime.jsxs("div",{className:"mb-5",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"From"}),jsxRuntime.jsxs("div",{className:"bg-content3 mt-3 flex w-full items-center gap-3 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-3",children:[u?.image&&jsxRuntime.jsx(ui.Avatar,{size:"sm",src:u.image,name:u.symbol,className:"h-6 w-6"}),jsxRuntime.jsxs("div",{className:"flex flex-col items-start justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:u?.symbol??"\u2014"}),a&&jsxRuntime.jsxs("div",{className:"text-neutral flex items-center gap-1 text-[10px]",children:[jsxRuntime.jsx(at,{}),jsxRuntime.jsxs("span",{children:[$(a.amount)," ",u?.symbol]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex-0 flex flex-col items-end justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:$(n)}),jsxRuntime.jsxs("div",{className:"text-neutral text-[10px]",children:["$",fe(d)]})]})]})]}),jsxRuntime.jsxs("div",{className:"mb-5",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"Estimated Receive"}),jsxRuntime.jsxs("div",{className:"bg-content3 mt-3 flex w-full items-center gap-3 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-3",children:[i?.image&&jsxRuntime.jsx(ui.Avatar,{size:"sm",src:i.image,name:i.symbol,className:"h-6 w-6"}),jsxRuntime.jsxs("div",{className:"flex flex-col items-start justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:i?.symbol??"\u2014"}),jsxRuntime.jsx("div",{className:"text-neutral text-[10px]",children:E(i?.address)})]})]}),jsxRuntime.jsxs("div",{className:"flex-0 flex flex-col items-end justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:$(m)}),jsxRuntime.jsxs("div",{className:"text-neutral text-[10px]",children:["$",fe(p)]})]})]})]}),s&&b.length>0&&jsxRuntime.jsxs("div",{className:"my-3",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"Route Details"}),jsxRuntime.jsx("div",{className:"mt-3 flex flex-col gap-3",children:b.map(g=>jsxRuntime.jsxs("div",{className:"bg-content3 flex w-full flex-col items-center gap-2 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"DEX"}),jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:g.name})]}),jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"Swap"}),jsxRuntime.jsxs("div",{className:"text-foreground flex items-center gap-2 text-xs",children:[jsxRuntime.jsxs("span",{children:[z(g.inputAmount)," ",E(g.input)]}),jsxRuntime.jsx(ui.TradeIcon,{width:12,height:12,className:"text-foreground"}),jsxRuntime.jsxs("span",{children:[z(g.outputAmount)," ",E(g.output)]})]})]}),g.feeAmount&&jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"Fee"}),jsxRuntime.jsxs("div",{className:"text-foreground text-xs",children:[z(g.feeAmount)," ",E(g.feeQuote)]})]})]},g.key))})]}),b.length>0&&jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx(ui.Button,{size:"sm",className:"text-neutral flex bg-transparent text-xs",endContent:s?jsxRuntime.jsx(ui.ChevronUpIcon,{width:12,height:12}):jsxRuntime.jsx(ui.ChevronDownIcon,{width:12,height:12}),disableRipple:true,onPress:C,children:s?"Show Less":"Show More"})})]})}),jsxRuntime.jsx(ui.ModalFooter,{children:jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"primary",className:"flex rounded-lg",disableRipple:true,isDisabled:!r||!!h,isLoading:!r&&l||w,onPress:f,children:"Confirm"})})]})})}function at(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"text-neutral",children:[jsxRuntime.jsx("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),jsxRuntime.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),jsxRuntime.jsx("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})]})}function fe(e){if(!e)return "0.00";let t=Number(e);return Number.isFinite(t)?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}):"0.00"}function $(e){if(!e)return "0";let t=Number(e);return Number.isFinite(t)?t>=1e6?(t/1e6).toLocaleString("en-US",{maximumFractionDigits:2})+"M":t>=1e3?(t/1e3).toLocaleString("en-US",{maximumFractionDigits:2})+"K":t.toLocaleString("en-US",{maximumFractionDigits:6}):"0"}function z(e){if(!e||e==="0")return "0";let t=Number(e);return Number.isFinite(t)?t>=1e12?(t/1e12).toFixed(2)+"T":t>=1e9?(t/1e9).toFixed(2)+"B":t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":e:e}function E(e){return e?e.length<=10?e:`${e.slice(0,4)}...${e.slice(-4)}`:"\u2014"}function K({fromToken:e,toToken:t,fromBalance:u,toBalance:i,amount:a,amountInUsd:n,onAmountChange:d,onHalfAmount:m,onMaxAmount:p,outputAmount:r,outputAmountInUsd:l,onFromTokenSelect:h,onToTokenSelect:f,route:w,isRouting:s,routeError:S,onPreview:C,isSwapping:b,className:g}){return jsxRuntime.jsxs("div",{className:ui.cn("px-4 pb-4 lg:pb-8",g),children:[jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-neutral text-sm font-medium",children:"From"}),jsxRuntime.jsxs("div",{className:"bg-content1 flex flex-col rounded-lg px-3.5 pb-2.5 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx(ui.Input,{type:"number",value:a??"",onChange:A=>d(A.target.value||void 0),placeholder:"0",classNames:{inputWrapper:ui.cn("h-10 p-0 bg-transparent","data-[hover=true]:bg-transparent group-data-[focus=true]:bg-transparent","group-data-[focus-visible=true]:ring-offset-transparent group-data-[focus-visible=true]:ring-transparent"),input:ui.cn("w-full h-full caret-primary text-3xl font-medium","placeholder:text-placeholder placeholder:text-3xl placeholder:font-medium","scrollbar-hide overflow-hidden text-ellipsis whitespace-nowrap")}})}),jsxRuntime.jsx("div",{className:"flex-0 flex h-full items-center justify-center",children:jsxRuntime.jsx(ui.Button,{className:ui.cn("flex min-w-0 h-8 min-h-8 pl-3 pr-2 bg-content3 rounded-full",e?"text-foreground":"text-neutral"),disableRipple:true,startContent:e?.image?jsxRuntime.jsx(ui.Avatar,{size:"sm",src:e.image,name:e.symbol,className:"h-6 w-6"}):null,endContent:jsxRuntime.jsx(ui.ChevronDownIcon,{width:16,height:16,className:"text-neutral"}),onPress:()=>h(""),children:e?e.symbol:"Select token"})})]}),jsxRuntime.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"text-neutral flex-1 text-xs",children:["\u2248 $",Se(n)]}),u&&jsxRuntime.jsxs("div",{className:"flex-0 flex items-center gap-2 pr-3 text-xs",children:[jsxRuntime.jsx(ve,{}),jsxRuntime.jsxs("span",{className:"text-neutral",children:[he(u.amount)," ",u.symbol]}),m&&jsxRuntime.jsx("span",{className:"text-primary cursor-pointer",onClick:m,children:"Half"}),p&&jsxRuntime.jsx("span",{className:"text-primary cursor-pointer",onClick:p,children:"Max"})]})]}),S&&jsxRuntime.jsx("p",{className:"mt-1 break-words text-xs text-danger-500",children:S.message})]})]}),jsxRuntime.jsxs("div",{className:"mt-4 space-y-3",children:[jsxRuntime.jsx("p",{className:"text-neutral text-sm font-medium",children:"To"}),jsxRuntime.jsxs("div",{className:"bg-content1 flex flex-col rounded-lg px-3.5 pb-2.5 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx(ui.Input,{type:"number",value:r??"",disabled:true,placeholder:"0",classNames:{inputWrapper:ui.cn("h-10 p-0 bg-transparent","data-[hover=true]:bg-transparent group-data-[focus=true]:bg-transparent","group-data-[focus-visible=true]:ring-offset-transparent group-data-[focus-visible=true]:ring-transparent"),input:ui.cn("w-full h-full caret-primary text-3xl font-medium","placeholder:text-placeholder placeholder:text-3xl placeholder:font-medium","scrollbar-hide overflow-hidden text-ellipsis whitespace-nowrap")}})}),jsxRuntime.jsx("div",{className:"flex-0 flex h-full items-center justify-center",children:jsxRuntime.jsx(ui.Button,{className:ui.cn("flex min-w-0 h-8 min-h-8 pl-3 pr-2 bg-content3 rounded-full",t?"text-foreground":"text-neutral"),disableRipple:true,startContent:t?.image?jsxRuntime.jsx(ui.Avatar,{size:"sm",src:t.image,name:t.symbol,className:"h-6 w-6"}):null,endContent:jsxRuntime.jsx(ui.ChevronDownIcon,{width:16,height:16,className:"text-neutral"}),onPress:()=>f(""),children:t?t.symbol:"Select token"})})]}),jsxRuntime.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"text-neutral flex-1 text-xs",children:["\u2248 $",Se(l)]}),i&&jsxRuntime.jsxs("div",{className:"flex-0 flex items-center gap-2 pr-3 text-xs",children:[jsxRuntime.jsx(ve,{}),jsxRuntime.jsxs("span",{className:"text-neutral",children:[he(i.amount)," ",i.symbol]})]})]})]})]}),jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"primary",className:"mt-8 flex rounded-lg",disableRipple:true,isDisabled:!w,isLoading:!w&&s,onPress:C,children:b?"Swapping...":s?"Finding route...":"Swap"})]})}function ve(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"text-neutral",children:[jsxRuntime.jsx("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),jsxRuntime.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),jsxRuntime.jsx("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})]})}function Se(e){if(!e)return "0.00";let t=Number(e);return Number.isFinite(t)?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}):"0.00"}function he(e){if(!e)return "0";let t=Number(e);return Number.isFinite(t)?t>=1e6?(t/1e6).toLocaleString("en-US",{maximumFractionDigits:2})+"M":t>=1e3?(t/1e3).toLocaleString("en-US",{maximumFractionDigits:2})+"K":t.toLocaleString("en-US",{maximumFractionDigits:6}):"0"}function ct({chain:e,from:t,to:u,onComplete:i,className:a}){let n=j({chain:e,from:t,to:u,onComplete:i}),{isOpen:d,onOpen:m,onOpenChange:p,onClose:r}=ui.useDisclosure(),l=react$1.useCallback(async()=>{await n.swap(),r();},[n,r]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(K,{fromToken:n.fromToken,toToken:n.toToken,fromBalance:n.fromBalance,toBalance:n.toBalance,amount:n.amount,amountInUsd:n.amountInUsd,onAmountChange:n.setAmount,onHalfAmount:n.setHalfAmount,onMaxAmount:n.setMaxAmount,outputAmount:n.outputAmount,outputAmountInUsd:n.outputAmountInUsd,onFromTokenSelect:n.setFromTokenAddress,onToTokenSelect:n.setToTokenAddress,route:n.route,isRouting:n.isRouting,routeError:n.routeError,onPreview:m,isSwapping:n.isSwapping,className:a}),jsxRuntime.jsx(V,{isOpen:d,onOpenChange:p,fromToken:n.fromToken,toToken:n.toToken,fromBalance:n.fromBalance,inputAmount:n.amount,inputAmountInUsd:n.amountInUsd,outputAmount:n.outputAmount,outputAmountInUsd:n.outputAmountInUsd,route:n.route,isRouting:n.isRouting,routeError:n.routeError,onConfirm:l,isSwapping:n.isSwapping})]})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-trade"]="0.1.2");var pt="0.1.2";
|
|
2
|
-
exports.SwapPreviewModal=
|
|
1
|
+
'use strict';var react=require('react'),react$1=require('@liberfi.io/react'),types=require('@liberfi.io/types'),walletConnector=require('@liberfi.io/wallet-connector'),ui=require('@liberfi.io/ui'),jsxRuntime=require('react/jsx-runtime'),utils=require('@liberfi.io/utils'),ne=require('bignumber.js'),hooks=require('@liberfi.io/hooks');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ne__default=/*#__PURE__*/_interopDefault(ne);function Pt(e){let t=atob(e),r=new Uint8Array(t.length);for(let o=0;o<t.length;o++)r[o]=t.charCodeAt(o);return r}function Tt(e){let t="";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return btoa(t)}function te(e){let{client:t}=react$1.useDexClient(),[r,o]=react.useState(false),i=react.useRef(e);i.current=e;let s=react.useCallback(async n=>{let{wallet:l,chain:p,...u}=n;o(true);try{let d;try{d=await t.swapRoute({chain:p,userAddress:l.address,input:u.input,output:u.output,mode:u.mode??types.API.SwapMode.EXACT_IN,amount:u.amount,slippage:u.slippage,priorityFee:u.priorityFee,tipFee:u.tipFee,isAntiMev:u.isAntiMev,permit:u.permit,deadline:u.deadline});}catch(a){let m=a instanceof Error?a:new Error(String(a));throw i.current?.onError?.(m,"route"),m}let g;try{let a=Pt(d.serializedTx);g=await l.signTransaction(a);}catch(a){let m=a instanceof Error?a:new Error(String(a));throw i.current?.onError?.(m,"sign"),m}let f;try{let a=Tt(g);f=await t.sendTx({chain:p,serializedTx:a});}catch(a){let m=a instanceof Error?a:new Error(String(a));throw i.current?.onError?.(m,"send"),m}let x={txHash:f.txHash,extra:f.extra};return i.current?.onSubmitted?.(x),x}finally{o(false);}},[t]);return react.useMemo(()=>({swap:s,isSwapping:r}),[s,r])}var Ft=12e3;function Ke(e,t){let r=t?.interval??Ft,o=t?.paused??false,i=react.useRef(t);i.current=t;let n=!!e.chain&&!!e.userAddress&&!!e.input&&!!e.output&&!!e.amount&&!o,l=react$1.useSwapRouteQuery(e,{enabled:n,refetchInterval:n?r:false,retry:false});return react.useEffect(()=>{l.error&&i.current?.onError?.(l.error);},[l.error]),react.useMemo(()=>({route:l.data,isRouting:l.isFetching,error:l.error}),[l.data,l.isFetching,l.error])}var Bt=6e4;function He(e){let{client:t}=react$1.useDexClient(),[r,o]=react.useState(()=>new Map),i=react.useRef(e);i.current=e;let s=react.useCallback((u,d)=>{o(g=>{let f=g.get(u);if(!f||f.status===d)return g;let x=new Map(g);return x.set(u,{...f,status:d}),x});},[]),n=react.useCallback((u,d)=>{o(f=>{if(f.has(d))return f;let x=new Map(f);return x.set(d,{chain:u,txHash:d,status:"pending"}),x});let g=i.current?.timeout??Bt;t.checkTxSuccess(u,d,g).then(f=>{if(f)s(d,"confirmed"),i.current?.onConfirmed?.(d);else {let x=new Error("Transaction failed on-chain");s(d,"failed"),i.current?.onFailed?.(d,x);}}).catch(f=>{let x=f instanceof Error?f:new Error(String(f));s(d,"failed"),i.current?.onFailed?.(d,x);});},[t,s]),l=react.useCallback(u=>{o(d=>{if(!d.has(u))return d;let g=new Map(d);return g.delete(u),g});},[]),p=react.useCallback(()=>{o(u=>u.size===0?u:new Map);},[]);return react.useMemo(()=>({track:n,clear:l,clearAll:p,transactions:r}),[n,l,p,r])}var Ot=new Set([types.Chain.SOLANA,types.Chain.SOLANA_TESTNET,types.Chain.SOLANA_DEVNET]);function Wt(e){return Ot.has(e)?types.ChainNamespace.SOLANA:types.ChainNamespace.EVM}var Vt=1e4,zt=15e3;function $t(e,t){if(e.length===0)return;let o=e[e.length-1].outputAmount;if(!o||o==="0")return "0";let i=o.padStart(t+1,"0"),s=i.slice(0,i.length-t)||"0",l=i.slice(i.length-t).replace(/0+$/,"");return l?`${s}.${l}`:s}function Ie(e){let{chain:t}=e,r=walletConnector.useWallets(),o=Wt(t),i=react.useMemo(()=>r.find(S=>S.chainNamespace===o&&S.isConnected),[r,o]),s=i?.address??"",[n,l]=react.useState(e.from??""),[p,u]=react.useState(e.to??""),d=react.useRef(e.from),g=react.useRef(e.to);react.useEffect(()=>{e.from!==d.current&&(d.current=e.from,e.from&&l(e.from));},[e.from]),react.useEffect(()=>{e.to!==g.current&&(g.current=e.to,e.to&&u(e.to));},[e.to]);let f=react.useMemo(()=>[n,p].filter(Boolean),[n,p]),x=react$1.useTokensQuery({chain:t,addresses:f},{enabled:f.length>0,refetchInterval:Vt}),a=react.useMemo(()=>x.data?.find(S=>S.address===n)??null,[x.data,n]),m=react.useMemo(()=>x.data?.find(S=>S.address===p)??null,[x.data,p]),N=react$1.useWalletPortfoliosByTokensQuery({chain:t,address:s,tokenAddresses:f},{enabled:!!s&&f.length>0,refetchInterval:zt}),v=react.useMemo(()=>N.data?.find(S=>S.address===n)??null,[N.data,n]),h=react.useMemo(()=>N.data?.find(S=>S.address===p)??null,[N.data,p]),[T,D]=react.useState(void 0),C=react.useMemo(()=>{if(!T||a?.decimals==null)return;let S=T.split("."),W=S[0]??"0",ht=(S[1]??"").slice(0,a.decimals).padEnd(a.decimals,"0");return (W+ht).replace(/^0+/,"")||"0"},[T,a?.decimals]),O=react.useMemo(()=>{if(!T||!a?.marketData?.priceInUsd)return;let S=Number(a.marketData.priceInUsd),W=Number(T)*S;return Number.isFinite(W)?W.toString():void 0},[T,a?.marketData?.priceInUsd]),A=react.useCallback(()=>{if(!v)return;let S=Number(v.amount);if(!Number.isFinite(S)||S<=0)return;let W=S/2,je=a?.decimals??9;D(W.toLocaleString("en-US",{useGrouping:false,maximumFractionDigits:je}));},[v,a?.decimals]),V=react.useCallback(()=>{if(!v)return;let S=Number(v.amount);if(!Number.isFinite(S)||S<=0)return;let W=a?.decimals??9;D(S.toLocaleString("en-US",{useGrouping:false,maximumFractionDigits:W}));},[v,a?.decimals]),$=react.useMemo(()=>({chain:t,userAddress:s||void 0,input:n||void 0,output:p||void 0,mode:types.API.SwapMode.EXACT_IN,amount:C}),[t,s,n,p,C]),X=react.useRef(false),{route:B,isRouting:Z,error:ae}=Ke($,{paused:X.current}),Q=react.useMemo(()=>B&&m?$t(B.plans,m.decimals):void 0,[B,m]),w=react.useMemo(()=>{if(!Q||!m?.marketData?.priceInUsd)return;let S=Number(m.marketData.priceInUsd),W=Number(Q)*S;return Number.isFinite(W)?W.toString():void 0},[Q,m?.marketData?.priceInUsd]),{swap:R,isSwapping:_}=te();X.current=_;let j=react.useRef(e.onComplete);j.current=e.onComplete;let{track:oe,transactions:K}=He({onConfirmed:S=>{j.current?.({success:true,txHash:S});},onFailed:S=>{j.current?.({success:false,txHash:S});}}),H=react.useMemo(()=>{if(K.size===0)return "idle";let S=Array.from(K.values());return S[S.length-1].status},[K]),q=react.useCallback(async()=>{if(!(!i||!B||!n||!p||!C))try{let S=await R({chain:t,wallet:i,input:n,output:p,amount:C,mode:types.API.SwapMode.EXACT_IN});oe(t,S.txHash);}catch{}},[i,B,t,n,p,C,R,oe]),me=x.isPending||N.isPending;return react.useMemo(()=>({fromTokenAddress:n,toTokenAddress:p,setFromTokenAddress:l,setToTokenAddress:u,fromToken:a,toToken:m,fromBalance:v,toBalance:h,amount:T,setAmount:D,setHalfAmount:A,setMaxAmount:V,amountInDecimals:C,amountInUsd:O,outputAmount:Q,outputAmountInUsd:w,route:B,isRouting:Z,routeError:ae,swap:q,isSwapping:_,txStatus:H,isLoading:me}),[n,p,a,m,v,h,T,A,V,C,O,Q,w,B,Z,ae,q,_,H,me])}function Ee({isOpen:e,onOpenChange:t,fromToken:r,toToken:o,fromBalance:i,inputAmount:s,inputAmountInUsd:n,outputAmount:l,outputAmountInUsd:p,route:u,isRouting:d,routeError:g,onConfirm:f,isSwapping:x}){let[a,m]=react.useState(false),N=react.useCallback(()=>m(h=>!h),[]),v=react.useMemo(()=>u?u.plans.map((h,T)=>({key:`plan-${T}`,name:h.name,input:h.input,inputAmount:h.inputAmount,output:h.output,outputAmount:h.outputAmount,feeQuote:h.feeQuote,feeAmount:h.feeAmount})):[],[u]);return jsxRuntime.jsx(ui.Modal,{isOpen:e,onOpenChange:t,hideCloseButton:true,scrollBehavior:"inside",backdrop:"blur",children:jsxRuntime.jsxs(ui.ModalContent,{className:"bg-content2 rounded-lg",children:[jsxRuntime.jsx(ui.ModalHeader,{children:"Preview"}),jsxRuntime.jsx(ui.ModalBody,{children:jsxRuntime.jsxs("div",{className:"flex w-full max-h-[70vh] flex-1 flex-col overflow-y-auto py-2",children:[jsxRuntime.jsxs("div",{className:"mb-5",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"From"}),jsxRuntime.jsxs("div",{className:"bg-content3 mt-3 flex w-full items-center gap-3 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-3",children:[r?.image&&jsxRuntime.jsx(ui.Avatar,{size:"sm",src:r.image,name:r.symbol,className:"h-6 w-6"}),jsxRuntime.jsxs("div",{className:"flex flex-col items-start justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:r?.symbol??"\u2014"}),i&&jsxRuntime.jsxs("div",{className:"text-neutral flex items-center gap-1 text-[10px]",children:[jsxRuntime.jsx(tn,{}),jsxRuntime.jsxs("span",{children:[Ae(i.amount)," ",r?.symbol]})]})]})]}),jsxRuntime.jsxs("div",{className:"flex-0 flex flex-col items-end justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:Ae(s)}),jsxRuntime.jsxs("div",{className:"text-neutral text-[10px]",children:["$",Ye(n)]})]})]})]}),jsxRuntime.jsxs("div",{className:"mb-5",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"Estimated Receive"}),jsxRuntime.jsxs("div",{className:"bg-content3 mt-3 flex w-full items-center gap-3 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-1 items-center gap-3",children:[o?.image&&jsxRuntime.jsx(ui.Avatar,{size:"sm",src:o.image,name:o.symbol,className:"h-6 w-6"}),jsxRuntime.jsxs("div",{className:"flex flex-col items-start justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:o?.symbol??"\u2014"}),jsxRuntime.jsx("div",{className:"text-neutral text-[10px]",children:fe(o?.address)})]})]}),jsxRuntime.jsxs("div",{className:"flex-0 flex flex-col items-end justify-center gap-0.5",children:[jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:Ae(l)}),jsxRuntime.jsxs("div",{className:"text-neutral text-[10px]",children:["$",Ye(p)]})]})]})]}),a&&v.length>0&&jsxRuntime.jsxs("div",{className:"my-3",children:[jsxRuntime.jsx("div",{className:"text-neutral flex items-center justify-between text-xs font-medium",children:"Route Details"}),jsxRuntime.jsx("div",{className:"mt-3 flex flex-col gap-3",children:v.map(h=>jsxRuntime.jsxs("div",{className:"bg-content3 flex w-full flex-col items-center gap-2 rounded-lg px-4 py-3",children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"DEX"}),jsxRuntime.jsx("div",{className:"text-foreground text-xs",children:h.name})]}),jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"Swap"}),jsxRuntime.jsxs("div",{className:"text-foreground flex items-center gap-2 text-xs",children:[jsxRuntime.jsxs("span",{children:[Ce(h.inputAmount)," ",fe(h.input)]}),jsxRuntime.jsx(ui.TradeIcon,{width:12,height:12,className:"text-foreground"}),jsxRuntime.jsxs("span",{children:[Ce(h.outputAmount)," ",fe(h.output)]})]})]}),h.feeAmount&&jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("div",{className:"text-neutral text-xs",children:"Fee"}),jsxRuntime.jsxs("div",{className:"text-foreground text-xs",children:[Ce(h.feeAmount)," ",fe(h.feeQuote)]})]})]},h.key))})]}),v.length>0&&jsxRuntime.jsx("div",{className:"flex justify-center",children:jsxRuntime.jsx(ui.Button,{size:"sm",className:"text-neutral flex bg-transparent text-xs",endContent:a?jsxRuntime.jsx(ui.ChevronUpIcon,{width:12,height:12}):jsxRuntime.jsx(ui.ChevronDownIcon,{width:12,height:12}),disableRipple:true,onPress:N,children:a?"Show Less":"Show More"})})]})}),jsxRuntime.jsx(ui.ModalFooter,{children:jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"primary",className:"flex rounded-lg",disableRipple:true,isDisabled:!u||!!g,isLoading:!u&&d||x,onPress:f,children:"Confirm"})})]})})}function tn(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"text-neutral",children:[jsxRuntime.jsx("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),jsxRuntime.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),jsxRuntime.jsx("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})]})}function Ye(e){if(!e)return "0.00";let t=Number(e);return Number.isFinite(t)?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}):"0.00"}function Ae(e){if(!e)return "0";let t=Number(e);return Number.isFinite(t)?t>=1e6?(t/1e6).toLocaleString("en-US",{maximumFractionDigits:2})+"M":t>=1e3?(t/1e3).toLocaleString("en-US",{maximumFractionDigits:2})+"K":t.toLocaleString("en-US",{maximumFractionDigits:6}):"0"}function Ce(e){if(!e||e==="0")return "0";let t=Number(e);return Number.isFinite(t)?t>=1e12?(t/1e12).toFixed(2)+"T":t>=1e9?(t/1e9).toFixed(2)+"B":t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":e:e}function fe(e){return e?e.length<=10?e:`${e.slice(0,4)}...${e.slice(-4)}`:"\u2014"}function ke({fromToken:e,toToken:t,fromBalance:r,toBalance:o,amount:i,amountInUsd:s,onAmountChange:n,onHalfAmount:l,onMaxAmount:p,outputAmount:u,outputAmountInUsd:d,onFromTokenSelect:g,onToTokenSelect:f,route:x,isRouting:a,routeError:m,onPreview:N,isSwapping:v,className:h}){return jsxRuntime.jsxs("div",{className:ui.cn("px-4 pb-4 lg:pb-8",h),children:[jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-neutral text-sm font-medium",children:"From"}),jsxRuntime.jsxs("div",{className:"bg-content1 flex flex-col rounded-lg px-3.5 pb-2.5 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx(ui.Input,{type:"number",value:i??"",onChange:T=>n(T.target.value||void 0),placeholder:"0",classNames:{inputWrapper:ui.cn("h-10 p-0 bg-transparent","data-[hover=true]:bg-transparent group-data-[focus=true]:bg-transparent","group-data-[focus-visible=true]:ring-offset-transparent group-data-[focus-visible=true]:ring-transparent"),input:ui.cn("w-full h-full caret-primary text-3xl font-medium","placeholder:text-placeholder placeholder:text-3xl placeholder:font-medium","scrollbar-hide overflow-hidden text-ellipsis whitespace-nowrap")}})}),jsxRuntime.jsx("div",{className:"flex-0 flex h-full items-center justify-center",children:jsxRuntime.jsx(ui.Button,{className:ui.cn("flex min-w-0 h-8 min-h-8 pl-3 pr-2 bg-content3 rounded-full",e?"text-foreground":"text-neutral"),disableRipple:true,startContent:e?.image?jsxRuntime.jsx(ui.Avatar,{size:"sm",src:e.image,name:e.symbol,className:"h-6 w-6"}):null,endContent:jsxRuntime.jsx(ui.ChevronDownIcon,{width:16,height:16,className:"text-neutral"}),onPress:()=>g(""),children:e?e.symbol:"Select token"})})]}),jsxRuntime.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"text-neutral flex-1 text-xs",children:["\u2248 $",rt(s)]}),r&&jsxRuntime.jsxs("div",{className:"flex-0 flex items-center gap-2 pr-3 text-xs",children:[jsxRuntime.jsx(st,{}),jsxRuntime.jsxs("span",{className:"text-neutral",children:[at(r.amount)," ",r.symbol]}),l&&jsxRuntime.jsx("span",{className:"text-primary cursor-pointer",onClick:l,children:"Half"}),p&&jsxRuntime.jsx("span",{className:"text-primary cursor-pointer",onClick:p,children:"Max"})]})]}),m&&jsxRuntime.jsx("p",{className:"mt-1 break-words text-xs text-danger-500",children:m.message})]})]}),jsxRuntime.jsxs("div",{className:"mt-4 space-y-3",children:[jsxRuntime.jsx("p",{className:"text-neutral text-sm font-medium",children:"To"}),jsxRuntime.jsxs("div",{className:"bg-content1 flex flex-col rounded-lg px-3.5 pb-2.5 pt-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx("div",{className:"flex-1",children:jsxRuntime.jsx(ui.Input,{type:"number",value:u??"",disabled:true,placeholder:"0",classNames:{inputWrapper:ui.cn("h-10 p-0 bg-transparent","data-[hover=true]:bg-transparent group-data-[focus=true]:bg-transparent","group-data-[focus-visible=true]:ring-offset-transparent group-data-[focus-visible=true]:ring-transparent"),input:ui.cn("w-full h-full caret-primary text-3xl font-medium","placeholder:text-placeholder placeholder:text-3xl placeholder:font-medium","scrollbar-hide overflow-hidden text-ellipsis whitespace-nowrap")}})}),jsxRuntime.jsx("div",{className:"flex-0 flex h-full items-center justify-center",children:jsxRuntime.jsx(ui.Button,{className:ui.cn("flex min-w-0 h-8 min-h-8 pl-3 pr-2 bg-content3 rounded-full",t?"text-foreground":"text-neutral"),disableRipple:true,startContent:t?.image?jsxRuntime.jsx(ui.Avatar,{size:"sm",src:t.image,name:t.symbol,className:"h-6 w-6"}):null,endContent:jsxRuntime.jsx(ui.ChevronDownIcon,{width:16,height:16,className:"text-neutral"}),onPress:()=>f(""),children:t?t.symbol:"Select token"})})]}),jsxRuntime.jsxs("div",{className:"mt-3 flex items-center justify-between gap-4",children:[jsxRuntime.jsxs("div",{className:"text-neutral flex-1 text-xs",children:["\u2248 $",rt(d)]}),o&&jsxRuntime.jsxs("div",{className:"flex-0 flex items-center gap-2 pr-3 text-xs",children:[jsxRuntime.jsx(st,{}),jsxRuntime.jsxs("span",{className:"text-neutral",children:[at(o.amount)," ",o.symbol]})]})]})]})]}),jsxRuntime.jsx(ui.Button,{fullWidth:true,color:"primary",className:"mt-8 flex rounded-lg",disableRipple:true,isDisabled:!x,isLoading:!x&&a,onPress:N,children:v?"Swapping...":a?"Finding route...":"Swap"})]})}function st(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"text-neutral",children:[jsxRuntime.jsx("path",{d:"M21 12V7H5a2 2 0 0 1 0-4h14v4"}),jsxRuntime.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h16v-5"}),jsxRuntime.jsx("path",{d:"M18 12a2 2 0 0 0 0 4h4v-4Z"})]})}function rt(e){if(!e)return "0.00";let t=Number(e);return Number.isFinite(t)?t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2}):"0.00"}function at(e){if(!e)return "0";let t=Number(e);return Number.isFinite(t)?t>=1e6?(t/1e6).toLocaleString("en-US",{maximumFractionDigits:2})+"M":t>=1e3?(t/1e3).toLocaleString("en-US",{maximumFractionDigits:2})+"K":t.toLocaleString("en-US",{maximumFractionDigits:6}):"0"}function rn({chain:e,from:t,to:r,onComplete:o,className:i}){let s=Ie({chain:e,from:t,to:r,onComplete:o}),{isOpen:n,onOpen:l,onOpenChange:p,onClose:u}=ui.useDisclosure(),d=react.useCallback(async()=>{await s.swap(),u();},[s,u]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ke,{fromToken:s.fromToken,toToken:s.toToken,fromBalance:s.fromBalance,toBalance:s.toBalance,amount:s.amount,amountInUsd:s.amountInUsd,onAmountChange:s.setAmount,onHalfAmount:s.setHalfAmount,onMaxAmount:s.setMaxAmount,outputAmount:s.outputAmount,outputAmountInUsd:s.outputAmountInUsd,onFromTokenSelect:s.setFromTokenAddress,onToTokenSelect:s.setToTokenAddress,route:s.route,isRouting:s.isRouting,routeError:s.routeError,onPreview:l,isSwapping:s.isSwapping,className:i}),jsxRuntime.jsx(Ee,{isOpen:n,onOpenChange:p,fromToken:s.fromToken,toToken:s.toToken,fromBalance:s.fromBalance,inputAmount:s.amount,inputAmountInUsd:s.amountInUsd,outputAmount:s.outputAmount,outputAmountInUsd:s.outputAmountInUsd,route:s.route,isRouting:s.isRouting,routeError:s.routeError,onConfirm:d,isSwapping:s.isSwapping})]})}var E={slippage:20,priorityFee:.001,tipFee:.001,autoFee:false,maxAutoFee:.1,antiMev:"off",customRPC:null},Sr=[.01,.1,1,10],wr=[10,25,50,100];var mn={customAmounts:[.01,.1,1,10],presets:[{...E},{...E},{...E}]},cn={customPercentages:[10,25,50,100],presets:[{...E},{...E},{...E}]},Ue={buy:mn,sell:cn};function it(e){return `liberfi.instant-trade.settings.${e}`}function pn(e){try{let t=localStorage.getItem(it(e));if(t)return JSON.parse(t)}catch{}return Ue}function fn(e,t){try{localStorage.setItem(it(e),JSON.stringify(t));}catch{}}var lt=react.createContext(null);function Y(){let e=react.useContext(lt);if(!e)throw new Error("useInstantTrade must be used within an InstantTradeProvider");return e}function Be({chain:e,tokenAddress:t,settings:r,onSettingsChange:o,children:i}){let s=react.useMemo(()=>utils.getNativeToken(e),[e]),n=r!==void 0,[l,p]=react.useState(()=>n?Ue:pn(String(e))),u=n?r:l,d=react.useCallback(A=>{n?o?.(A):(p(A),fn(String(e),A));},[n,o,e]),g=react.useCallback(A=>d({...u,buy:A}),[u,d]),f=react.useCallback(A=>d({...u,sell:A}),[u,d]),[x,a]=react.useState("buy"),[m,N]=react.useState(),[v,h]=react.useState(0),[T,D]=react.useState(0),C=react.useMemo(()=>{let A=x==="buy"?v:T;return (x==="buy"?u.buy.presets:u.sell.presets)[A]??E},[x,v,T,u]),O=react.useMemo(()=>({chain:e,tokenAddress:t,nativeToken:s,direction:x,setDirection:a,amount:m,setAmount:N,buyPreset:v,setBuyPreset:h,sellPreset:T,setSellPreset:D,settings:u,updateBuySettings:g,updateSellSettings:f,currentPresetValues:C}),[e,t,s,x,m,v,T,u,g,f,C]);return jsxRuntime.jsx(lt.Provider,{value:O,children:i})}var Nn=new Set([types.Chain.SOLANA,types.Chain.SOLANA_TESTNET,types.Chain.SOLANA_DEVNET]);function Pn(e){return Nn.has(e)?types.ChainNamespace.SOLANA:types.ChainNamespace.EVM}var Tn=15e3,In=1e4;function De(e){let{chain:t,tokenAddress:r,onSwapSubmitted:o,onSwapError:i}=e,s=Y(),n=react.useMemo(()=>utils.getNativeToken(t),[t]),l=react.useMemo(()=>utils.getWrappedToken(t),[t]),p=walletConnector.useWallets(),u=Pn(t),d=react.useMemo(()=>p.find(w=>w.chainNamespace===u&&w.isConnected),[p,u]),g=d?.address??"",f=react.useMemo(()=>{let w=[r];return n&&w.push(n.address),l&&w.push(l.address),w.filter(Boolean)},[r,n,l]),x=react$1.useTokensQuery({chain:t,addresses:f},{enabled:f.length>0,refetchInterval:In}),a=react.useMemo(()=>x.data?.find(w=>w.address===r)??null,[x.data,r]),m=react$1.useWalletPortfoliosByTokensQuery({chain:t,address:g,tokenAddresses:f},{enabled:!!g&&f.length>0,refetchInterval:Tn}),N=n?.address??l?.address??"",v=react.useMemo(()=>m.data?.find(w=>w.address===N)??null,[m.data,N]),h=react.useMemo(()=>m.data?.find(w=>w.address===r)??null,[m.data,r]),[T,D]=react.useState(false),C=react.useRef(null),O=react.useCallback(w=>{let R=C.current;C.current=w,D(_=>R===null||R!==w?true:!_);},[]),A=react.useRef(o);A.current=o;let V=react.useRef(i);V.current=i;let{swap:$,isSwapping:X}=te({onSubmitted:w=>A.current?.(w),onError:(w,R)=>V.current?.(w,R)}),B=react.useCallback(async()=>{if(!s.amount||!d||!r)return;let w=n?.decimals??9,R=l?.address??n?.address??"",_=s.direction==="buy",j=_?R:r,oe=_?r:R,K=_?w:a?.decimals??9,H=new ne__default.default(s.amount).shiftedBy(K).decimalPlaces(0).toString(),q=s.currentPresetValues,me=new ne__default.default(q.priorityFee??E.priorityFee).shiftedBy(w).decimalPlaces(0).toString(),S=new ne__default.default(q.tipFee??E.tipFee).shiftedBy(w).decimalPlaces(0).toString();try{await $({chain:t,wallet:d,input:j,output:oe,amount:H,slippage:q.slippage??E.slippage,priorityFee:me,tipFee:S,isAntiMev:q.antiMev!=="off"}),s.setAmount(void 0);}catch{}},[s,d,r,n,l,a,t,$]),Z=react.useMemo(()=>{let w=s.direction==="buy"?"Buy":"Sell";if(!s.amount)return w;if(s.direction==="buy"){let _=v?.amount;if(_&&new ne__default.default(_).lt(s.amount))return `${w} (Insufficient balance)`;let j=n?.symbol??"";a?.marketData?.priceInUsd?Number(a.marketData.priceInUsd):null;let K=x.data?.find(H=>H.address===N)?.marketData?.priceInUsd;if(K){let H=utils.formatAmountUSD(new ne__default.default(s.amount).times(Number(K)));return `${w} ${s.amount} ${j} (${H})`}return `${w} ${s.amount} ${j}`}let R=h?.amount;return R&&new ne__default.default(R).lt(s.amount)?`${w} (Insufficient balance)`:w},[s.direction,s.amount,v,h,n,a,x.data,N]),ae=!s.amount||!d||!r,Q=x.isPending||m.isPending;return react.useMemo(()=>({chain:t,tokenAddress:r,nativeToken:n,tokenInfo:a,nativeBalance:v,tokenBalance:h,direction:s.direction,setDirection:s.setDirection,amount:s.amount,setAmount:s.setAmount,buyPreset:s.buyPreset,setBuyPreset:s.setBuyPreset,sellPreset:s.sellPreset,setSellPreset:s.setSellPreset,currentPresetValues:s.currentPresetValues,settings:s.settings,updateBuySettings:s.updateBuySettings,updateSellSettings:s.updateSellSettings,showSettings:T,handlePresetClick:O,swap:B,isSwapping:X,submitText:Z,isDisabled:ae,isLoading:Q}),[t,r,n,a,v,h,s,T,O,B,X,Z,ae,Q])}function le({value:e,onChange:t,nativeSymbol:r="SOL",nativeDecimals:o=9,className:i}){let s=react.useCallback(n=>t({...e,...n}),[e,t]);return jsxRuntime.jsxs("div",{className:ui.cn("space-y-1.5",i),children:[jsxRuntime.jsx(kn,{value:e.slippage,onChange:n=>s({slippage:n})}),jsxRuntime.jsx(Rn,{value:e.priorityFee,onChange:n=>s({priorityFee:n}),symbol:r,decimals:o}),jsxRuntime.jsx(Mn,{value:e.tipFee,onChange:n=>s({tipFee:n}),symbol:r,decimals:o}),jsxRuntime.jsx(Un,{value:e.autoFee,onChange:n=>s({autoFee:n})}),e.autoFee&&jsxRuntime.jsx(Bn,{value:e.maxAutoFee,onChange:n=>s({maxAutoFee:n}),symbol:r}),jsxRuntime.jsx(_n,{value:e.antiMev,onChange:n=>s({antiMev:n})}),jsxRuntime.jsx(Ln,{value:e.customRPC,onChange:n=>s({customRPC:n})})]})}var ue={inputWrapper:"bg-content2 data-[hover=true]:bg-content3 group-data-[focus=true]:bg-content3 h-8 min-h-0 py-0",input:"text-xs"};function ve(e){return react.useCallback(t=>{typeof t=="number"&&e(isNaN(t)?null:t);},[e])}function kn({value:e,onChange:t}){let r=ve(t);return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsx("div",{className:"text-xs text-neutral",children:"Slippage"}),jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:e===null?void 0:e,onChange:r,hideStepper:true,minValue:0,maxValue:100,step:1,endContent:jsxRuntime.jsx("span",{className:"text-xs text-neutral",children:"%"}),classNames:ue,"aria-label":"Slippage"})]})}function Rn({value:e,onChange:t,symbol:r,decimals:o}){let i=ve(t);return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsxs("div",{className:"text-xs text-neutral flex items-center gap-1",children:["Priority Fee",jsxRuntime.jsx(ui.Tooltip,{content:"Extra fee paid to validators to prioritize your transaction.",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{isIconOnly:true,className:"bg-transparent min-w-0 w-4 min-h-0 h-4 p-0",size:"sm",disableRipple:true,children:jsxRuntime.jsx(ui.InfoIcon,{width:13,height:13,className:"text-neutral"})})})]}),jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:e===null?void 0:e,onChange:i,hideStepper:true,minValue:0,formatOptions:{maximumFractionDigits:o},endContent:jsxRuntime.jsx("span",{className:"text-xs text-neutral",children:r}),classNames:ue,"aria-label":"Priority Fee"})]})}function Mn({value:e,onChange:t,symbol:r,decimals:o}){let i=ve(t);return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsxs("div",{className:"text-xs text-neutral flex items-center gap-1",children:["Tip Fee",jsxRuntime.jsx(ui.Tooltip,{content:"Additional tip sent alongside the transaction (e.g. Jito tip).",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{isIconOnly:true,className:"bg-transparent min-w-0 w-4 min-h-0 h-4 p-0",size:"sm",disableRipple:true,children:jsxRuntime.jsx(ui.InfoIcon,{width:13,height:13,className:"text-neutral"})})})]}),jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:e===null?void 0:e,onChange:i,hideStepper:true,minValue:0,formatOptions:{maximumFractionDigits:o},endContent:jsxRuntime.jsx("span",{className:"text-xs text-neutral",children:r}),classNames:ue,"aria-label":"Tip Fee"})]})}function Un({value:e,onChange:t}){return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsxs("div",{className:"text-xs text-neutral flex items-center gap-1",children:["Auto Fee",jsxRuntime.jsx(ui.Tooltip,{content:"Automatically estimate optimal fee based on network conditions.",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{isIconOnly:true,className:"bg-transparent min-w-0 w-4 min-h-0 h-4 p-0",size:"sm",disableRipple:true,children:jsxRuntime.jsx(ui.InfoIcon,{width:13,height:13,className:"text-neutral"})})})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(ui.Switch,{isSelected:e,onValueChange:t,color:"primary",size:"sm","aria-label":"Auto Fee"})})]})}function Bn({value:e,onChange:t,symbol:r}){let o=ve(t);return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsx("div",{className:"text-xs text-neutral",children:"Max Auto Fee"}),jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:e===null?void 0:e,onChange:o,hideStepper:true,minValue:0,endContent:jsxRuntime.jsx("span",{className:"text-xs text-neutral",children:r}),classNames:ue,"aria-label":"Max Auto Fee"})]})}function _n({value:e,onChange:t}){return jsxRuntime.jsxs("div",{className:"w-full grid grid-cols-2 gap-2 items-center",children:[jsxRuntime.jsxs("div",{className:"text-xs text-neutral flex items-center gap-1",children:["Anti-MEV",jsxRuntime.jsx(ui.Tooltip,{content:"MEV protection shields your transaction from sandwich attacks.",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{isIconOnly:true,className:"bg-transparent min-w-0 w-4 min-h-0 h-4 p-0",size:"sm",disableRipple:true,children:jsxRuntime.jsx(ui.InfoIcon,{width:13,height:13,className:"text-neutral"})})})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsxs(ui.Tabs,{variant:"bordered",color:"primary",size:"sm",disableAnimation:true,radius:"lg",classNames:{tabList:"border-border border-1 gap-0",tab:"min-h-0 h-5 px-2"},selectedKey:e,onSelectionChange:t,"aria-label":"Anti-MEV",children:[jsxRuntime.jsx(ui.Tab,{title:"Off"},"off"),jsxRuntime.jsx(ui.Tab,{title:"Reduced"},"reduced"),jsxRuntime.jsx(ui.Tab,{title:"Secure"},"secure")]})})]})}function Ln({value:e,onChange:t}){return jsxRuntime.jsxs("div",{className:"w-full flex gap-4 items-center",children:[jsxRuntime.jsx("div",{className:"flex-none text-xs text-neutral",children:"Custom RPC"}),jsxRuntime.jsx("div",{className:"flex-auto",children:jsxRuntime.jsx(ui.Input,{fullWidth:true,value:e??"",onValueChange:r=>t(r||null),classNames:ue,placeholder:"https://...","aria-label":"Custom RPC"})})]})}function ze({direction:e,onDirectionChange:t,amount:r,onAmountChange:o,customAmounts:i,customPercentages:s,onQuickAmountClick:n,onQuickPercentageClick:l,onCustomAmountsEdit:p,onCustomPercentagesEdit:u,tokenSymbol:d,nativeSymbol:g,nativeDecimals:f,nativeBalance:x,tokenBalance:a,amountConversion:m,preset:N,onPresetChange:v,presetValues:h,onPresetSettingsChange:T,showSettings:D,onPresetClick:C,submitText:O,isDisabled:A,isLoading:V,onSubmit:$,className:X,headerExtra:B}){return jsxRuntime.jsxs("div",{className:ui.cn("flex-none sm:px-3 py-3 bg-content1 rounded-lg",X),children:[jsxRuntime.jsxs(ui.Tabs,{fullWidth:true,size:"sm",selectedKey:e,onSelectionChange:t,classNames:{tabList:"bg-content2",tab:"data-[selected=true]:bg-content3 h-6"},disableAnimation:true,children:[jsxRuntime.jsx(ui.Tab,{title:"Buy"},"buy"),jsxRuntime.jsx(ui.Tab,{title:"Sell"},"sell")]}),jsxRuntime.jsxs("div",{className:"mt-2.5 h-8 flex items-center justify-between",children:[jsxRuntime.jsx(ui.Tabs,{size:"sm",variant:"underlined",classNames:{tabList:"gap-0",tab:"px-1.5"},selectedKey:"market",disableAnimation:true,children:jsxRuntime.jsx(ui.Tab,{title:"Market"},"market")}),B]}),jsxRuntime.jsx("div",{className:"mt-2.5",children:e==="buy"?jsxRuntime.jsx(Hn,{amount:r,onAmountChange:o,customAmounts:i,onQuickAmountClick:n,onCustomAmountsEdit:p,nativeSymbol:g,nativeDecimals:f}):jsxRuntime.jsx(Gn,{amount:r,onAmountChange:o,customPercentages:s,onQuickPercentageClick:l,onCustomPercentagesEdit:u,tokenSymbol:d})}),jsxRuntime.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"text-xs text-neutral space-x-1",children:[jsxRuntime.jsx("span",{children:"Balance:"}),jsxRuntime.jsx("span",{children:e==="buy"?x?`${x} ${g??""}`:"--":a?`${a} ${d??""}`:"--"})]}),m&&jsxRuntime.jsx("div",{className:"text-xs text-neutral",children:m})]}),jsxRuntime.jsx("div",{className:"mt-4",children:jsxRuntime.jsx(Xn,{values:h})}),jsxRuntime.jsx("div",{className:"mt-2",children:jsxRuntime.jsxs(ui.Tabs,{variant:"bordered",size:"sm",fullWidth:true,classNames:{tabList:"border-content3 border-1 gap-0 p-0.5",tab:"min-h-0 h-6 px-2 py-1 text-xs data-[selected=true]:bg-content3",tabContent:"text-neutral"},selectedKey:`${N}`,onSelectionChange:Z=>v(Number(Z)),disableAnimation:true,"aria-label":"Presets",children:[jsxRuntime.jsx(ui.Tab,{title:"Preset 1",onClick:()=>C(0)},0),jsxRuntime.jsx(ui.Tab,{title:"Preset 2",onClick:()=>C(1)},1),jsxRuntime.jsx(ui.Tab,{title:"Preset 3",onClick:()=>C(2)},2)]})}),D&&jsxRuntime.jsx("div",{className:"mt-2.5",children:jsxRuntime.jsx(le,{value:h,onChange:T,nativeSymbol:g,nativeDecimals:f})}),jsxRuntime.jsx(ui.Button,{fullWidth:true,size:"sm",color:e==="buy"?"primary":"secondary",className:"mt-2 rounded-lg",disableRipple:true,isDisabled:A,isLoading:V,onPress:$,children:O})]})}function Hn({amount:e,onAmountChange:t,customAmounts:r,onQuickAmountClick:o,onCustomAmountsEdit:i,nativeSymbol:s,nativeDecimals:n}){let l=react.useCallback(p=>{typeof p=="number"&&t(isNaN(p)?void 0:p);},[t]);return jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsx(ui.NumberInput,{min:0,value:e,onChange:l,fullWidth:true,hideStepper:true,startContent:jsxRuntime.jsx("span",{className:"flex-none text-xs text-neutral",children:"Amount"}),endContent:jsxRuntime.jsx("span",{className:"flex-none text-xs text-neutral",children:s??""}),formatOptions:{maximumFractionDigits:n??9},classNames:{inputWrapper:ui.cn("h-8 min-h-0 py-0 rounded-lg rounded-b-none shadow-none","bg-content2 data-[hover=true]:bg-content3 group-data-[focus=true]:bg-content3"),input:"text-xs"}}),jsxRuntime.jsx(ft,{values:r,onSelect:o,onEdit:i})]})}function Gn({amount:e,onAmountChange:t,customPercentages:r,onQuickPercentageClick:o,onCustomPercentagesEdit:i,tokenSymbol:s}){let n=react.useCallback(l=>{typeof l=="number"&&t(isNaN(l)?void 0:l);},[t]);return jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsx(ui.NumberInput,{min:0,value:e,onChange:n,fullWidth:true,hideStepper:true,startContent:jsxRuntime.jsx("span",{className:"flex-none text-xs text-neutral",children:"Amount"}),endContent:jsxRuntime.jsx("span",{className:"flex-none text-xs text-neutral",children:s??""}),classNames:{inputWrapper:ui.cn("h-8 min-h-0 py-0 rounded-lg rounded-b-none shadow-none","bg-content2 data-[hover=true]:bg-content3 group-data-[focus=true]:bg-content3"),input:"text-xs"}}),jsxRuntime.jsx(ft,{values:r,onSelect:o,onEdit:i,suffix:"%"})]})}function ft({values:e,onSelect:t,onEdit:r,suffix:o}){let[i,s]=react.useState(false),[n,l]=react.useState([]),p=react.useCallback(()=>{l([...e]),s(true);},[e]),u=react.useCallback(()=>{s(false),r(n);},[r,n]);return jsxRuntime.jsxs("div",{className:"flex gap-0.5",children:[jsxRuntime.jsx("div",{className:"flex-auto grid grid-cols-4 gap-0.5",children:Array.from({length:4}).map((d,g)=>jsxRuntime.jsx("div",{className:ui.cn("h-6 bg-content2 flex items-center justify-center",g===0&&"rounded-bl-lg"),children:i?jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:n[g]===null||n[g]===void 0?void 0:n[g],onChange:f=>{if(typeof f=="number"){let x=isNaN(f)?null:f;l(a=>{let m=[...a];return m[g]=x,m});}},min:0,hideStepper:true,classNames:{inputWrapper:ui.cn("p-0 h-6 min-h-0 rounded-none flex shadow-none","bg-content2 data-[hover=true]:bg-content3 group-data-[focus=true]:bg-content3",g===0&&"rounded-bl-lg"),innerWrapper:"pb-0",input:"text-xs text-center"}}):jsxRuntime.jsx(ui.Button,{className:"min-w-0 w-full min-h-0 h-full p-0 bg-transparent text-xs",size:"sm",disableRipple:true,onPress:()=>e[g]!=null&&t(e[g]),endContent:o?jsxRuntime.jsx("span",{className:"text-xs text-neutral",children:o}):null,children:e[g]??""})},g))}),jsxRuntime.jsx("div",{className:"flex-none bg-content2 rounded-br-lg overflow-hidden",children:i?jsxRuntime.jsx(ui.Button,{size:"sm",isIconOnly:true,className:"bg-transparent h-6 min-h-6 p-0",disableRipple:true,onPress:u,children:jsxRuntime.jsx(ui.CheckIcon,{width:12,height:12})}):jsxRuntime.jsx(ui.Button,{size:"sm",isIconOnly:true,className:"bg-transparent h-6 min-h-6 p-0",disableRipple:true,onPress:p,children:jsxRuntime.jsx(ui.EditIcon,{width:12,height:12})})})]})}function Xn({values:e}){return jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(ui.Tooltip,{content:"Slippage",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{size:"sm",className:"bg-transparent p-0 h-5 min-h-0 w-auto min-w-0 gap-0.5 text-xs text-neutral",disableRipple:true,startContent:jsxRuntime.jsx(ui.SlippageIcon,{width:14,height:14}),children:utils.formatPercent((e.slippage??0)/100)})}),jsxRuntime.jsx(ui.Tooltip,{content:"Priority Fee",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{size:"sm",className:"bg-transparent p-0 h-5 min-h-0 w-auto min-w-0 gap-0.5 text-xs text-neutral",disableRipple:true,startContent:jsxRuntime.jsx(ui.ZapFastIcon,{width:14,height:14}),children:utils.formatPrice(e.priorityFee??0)})}),jsxRuntime.jsx(ui.Tooltip,{content:"Tip Fee",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsx(ui.Button,{size:"sm",className:"bg-transparent p-0 h-5 min-h-0 w-auto min-w-0 gap-0.5 text-xs text-neutral",disableRipple:true,startContent:jsxRuntime.jsx(ui.CoinsIcon,{width:14,height:14}),children:utils.formatPrice(e.tipFee??0)})}),jsxRuntime.jsx(ui.Tooltip,{content:"Anti-MEV",classNames:{content:"text-xs text-neutral py-2 px-4 max-w-xs"},children:jsxRuntime.jsxs(ui.Button,{size:"sm",className:"bg-transparent p-0 h-5 min-h-0 w-auto min-w-0 gap-0.5 text-xs text-neutral",disableRipple:true,startContent:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[(!e.antiMev||e.antiMev==="off")&&jsxRuntime.jsx(ui.ShieldOffIcon,{width:14,height:14,className:"text-neutral"}),e.antiMev==="reduced"&&jsxRuntime.jsx(ui.ShieldIcon,{width:14,height:14,className:"text-neutral"}),e.antiMev==="secure"&&jsxRuntime.jsx(ui.ShieldPlusIcon,{width:14,height:14,className:"text-neutral"})]}),children:[(!e.antiMev||e.antiMev==="off")&&"Off",e.antiMev==="reduced"&&"Reduced",e.antiMev==="secure"&&"Secure"]})})]})}function Jn({chain:e,tokenAddress:t,onSwapSubmitted:r,onSwapError:o,settings:i,onSettingsChange:s,headerExtra:n,className:l}){return jsxRuntime.jsx(Be,{chain:e,tokenAddress:t,settings:i,onSettingsChange:s,children:jsxRuntime.jsx(Yn,{chain:e,tokenAddress:t,onSwapSubmitted:r,onSwapError:o,headerExtra:n,className:l})})}function Yn({chain:e,tokenAddress:t,onSwapSubmitted:r,onSwapError:o,headerExtra:i,className:s}){let n=De({chain:e,tokenAddress:t,onSwapSubmitted:r,onSwapError:o}),l=react.useCallback(a=>n.setAmount(a),[n]),p=react.useCallback(a=>{let m=n.tokenBalance?.amount;if(!m)return;let N=new ne__default.default(m).times(a).div(100).toNumber();n.setAmount(N);},[n]),u=react.useCallback(a=>{n.updateBuySettings({...n.settings.buy,customAmounts:a});},[n]),d=react.useCallback(a=>{n.updateSellSettings({...n.settings.sell,customPercentages:a});},[n]),g=react.useCallback(a=>{let m=n.direction==="buy",N=m?n.buyPreset:n.sellPreset;if(m){let v=n.settings.buy,h=[...v.presets];h[N]=a,n.updateBuySettings({...v,presets:h});}else {let v=n.settings.sell,h=[...v.presets];h[N]=a,n.updateSellSettings({...v,presets:h});}},[n]),f=react.useCallback(a=>{n.direction==="buy"?n.setBuyPreset(a):n.setSellPreset(a);},[n]),x=n.direction==="buy"?n.buyPreset:n.sellPreset;return jsxRuntime.jsx(ze,{direction:n.direction,onDirectionChange:n.setDirection,amount:n.amount,onAmountChange:n.setAmount,customAmounts:n.settings.buy.customAmounts,customPercentages:n.settings.sell.customPercentages,onQuickAmountClick:l,onQuickPercentageClick:p,onCustomAmountsEdit:u,onCustomPercentagesEdit:d,tokenSymbol:n.tokenInfo?.symbol,nativeSymbol:n.nativeToken?.symbol,nativeDecimals:n.nativeToken?.decimals,nativeBalance:n.nativeBalance?.amount,tokenBalance:n.tokenBalance?.amount,amountConversion:void 0,preset:x,onPresetChange:f,presetValues:n.currentPresetValues,onPresetSettingsChange:g,showSettings:n.showSettings,onPresetClick:n.handlePresetClick,submitText:n.submitText,isDisabled:n.isDisabled,isLoading:n.isSwapping,onSubmit:n.swap,className:s,headerExtra:i})}function os({value:e,onChange:t,chain:r,className:o}){let i=react.useMemo(()=>utils.getNativeToken(r),[r]),s=hooks.useCallbackRef(t),[n,l]=react.useState(e);react.useEffect(()=>{l(e);},[e]);let p=react.useCallback(u=>{l(u),s(u);},[s]);return jsxRuntime.jsx(le,{value:n,onChange:p,nativeSymbol:i?.symbol,nativeDecimals:i?.decimals,className:o})}function Ss({amount:e,onAmountChange:t,preset:r=0,onPresetChange:o,onPresetClick:i,variant:s="default",radius:n="full",size:l="sm",fullWidth:p=false,className:u}){let{nativeToken:d,settings:g}=Y(),f=react.useCallback(a=>{typeof a=="number"&&t(isNaN(a)?void 0:a);},[t]),x=react.useCallback(a=>{r===a?i?.(a):o?.(a);},[r,o,i]);return jsxRuntime.jsxs("div",{className:ui.cn("flex items-center gap-1.5 overflow-hidden px-3",n==="full"&&"rounded-full",n==="lg"&&"rounded-lg",n==="md"&&"rounded-md",n==="sm"&&"rounded-sm",s==="bordered"&&"border-1 border-border",s==="default"&&"bg-content2",u),children:[jsxRuntime.jsx("div",{className:ui.cn(p?"w-full":"w-20"),children:jsxRuntime.jsx(ui.NumberInput,{fullWidth:true,value:e,onChange:f,hideStepper:true,minValue:0,formatOptions:{maximumFractionDigits:d?.decimals??9},startContent:jsxRuntime.jsx(ui.LightningIcon,{width:12,height:12,className:"text-neutral flex-none"}),endContent:d?jsxRuntime.jsx(ui.Avatar,{className:"w-4 h-4 bg-transparent flex-none",name:d.symbol}):null,classNames:{inputWrapper:ui.cn("bg-transparent data-[hover=true]:bg-transparent group-data-[focus=true]:bg-transparent","w-full min-w-0 min-h-0 p-0 rounded-none",l==="sm"&&"h-6",l==="lg"&&"h-8"),input:"text-sm"},placeholder:"0.0","aria-label":"Instant trade amount"})}),jsxRuntime.jsx("div",{className:"w-px bg-border h-4"}),jsxRuntime.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:3}).map((a,m)=>jsxRuntime.jsx(ui.Tooltip,{content:jsxRuntime.jsx(ws,{values:g.buy.presets[m]??E}),placement:"bottom",children:jsxRuntime.jsx(ui.Button,{className:ui.cn("w-auto min-w-0 h-auto min-h-0 px-1 py-0.5 text-xs bg-transparent rounded",{"text-primary hover:bg-primary/20":m===r,"text-neutral hover:bg-content3":m!==r}),disableRipple:true,onPress:()=>x(m),children:`P${m+1}`})},m))})]})}function ws({values:e}){return jsxRuntime.jsxs("div",{className:"px-1 py-0.5 flex flex-col gap-1.5 text-xs text-neutral",children:[jsxRuntime.jsxs("div",{className:"w-full flex items-center justify-between gap-3",children:[jsxRuntime.jsx(ui.SlippageIcon,{width:14,height:14}),jsxRuntime.jsx("span",{children:utils.formatPercent((e.slippage??0)/100)})]}),jsxRuntime.jsxs("div",{className:"w-full flex items-center justify-between gap-3",children:[jsxRuntime.jsx(ui.ZapFastIcon,{width:14,height:14}),jsxRuntime.jsx("span",{children:utils.formatPrice(e.priorityFee??0)})]}),jsxRuntime.jsxs("div",{className:"w-full flex items-center justify-between gap-3",children:[jsxRuntime.jsx(ui.CoinsIcon,{width:14,height:14}),jsxRuntime.jsx("span",{children:utils.formatPrice(e.tipFee??0)})]}),jsxRuntime.jsxs("div",{className:"w-full flex items-center justify-between gap-3",children:[(!e.antiMev||e.antiMev==="off")&&jsxRuntime.jsx(ui.ShieldOffIcon,{width:14,height:14}),e.antiMev==="reduced"&&jsxRuntime.jsx(ui.ShieldIcon,{width:14,height:14}),e.antiMev==="secure"&&jsxRuntime.jsx(ui.ShieldPlusIcon,{width:14,height:14}),jsxRuntime.jsxs("span",{children:[(!e.antiMev||e.antiMev==="off")&&"Off",e.antiMev==="reduced"&&"Reduced",e.antiMev==="secure"&&"Secure"]})]})]})}function Cs({className:e,children:t}){let{chain:r,tokenAddress:o,nativeToken:i,direction:s,amount:n,setAmount:l,currentPresetValues:p}=Y(),d=walletConnector.useWallets()[0]??null,g=react.useMemo(()=>utils.getWrappedToken(r),[r]),{swap:f,isSwapping:x}=te(),a=!n||!d||!o,m=react.useCallback(async()=>{if(!n||!d||!o)return;let N=i??utils.getNativeToken(r),v=N?.decimals??9,h=g?.address??N?.address??"",T=s==="buy",D=T?h:o,C=T?o:h,O=new ne__default.default(n).shiftedBy(v).decimalPlaces(0).toString(),A=p,V=new ne__default.default(A.priorityFee??E.priorityFee).shiftedBy(v).decimalPlaces(0).toString(),$=new ne__default.default(A.tipFee??E.tipFee).shiftedBy(v).decimalPlaces(0).toString();try{await f({chain:r,wallet:d,input:D,output:C,amount:O,slippage:A.slippage??E.slippage,priorityFee:V,tipFee:$,isAntiMev:A.antiMev!=="off"}),l(void 0);}catch{}},[n,d,o,i,g,r,s,p,f,l]);return jsxRuntime.jsx(ui.Button,{fullWidth:true,size:"sm",color:s==="buy"?"primary":"secondary",className:e,disableRipple:true,isDisabled:a,isLoading:x,onPress:m,children:t??(s==="buy"?"Buy":"Sell")})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/ui-trade"]="0.1.3");var Fs="0.1.3";
|
|
2
|
+
exports.DEFAULT_BUY_AMOUNTS=Sr;exports.DEFAULT_INSTANT_TRADE_SETTINGS=Ue;exports.DEFAULT_SELL_PERCENTAGES=wr;exports.DEFAULT_TRADE_PRESET=E;exports.InstantTradeAmountInput=Ss;exports.InstantTradeButton=Cs;exports.InstantTradeProvider=Be;exports.InstantTradeUI=ze;exports.InstantTradeWidget=Jn;exports.PresetFormUI=le;exports.PresetFormWidget=os;exports.SwapPreviewModal=Ee;exports.SwapUI=ke;exports.SwapWidget=rn;exports.useInstantTrade=Y;exports.useInstantTradeScript=De;exports.useSwap=te;exports.useSwapRoutePolling=Ke;exports.useSwapScript=Ie;exports.useTxConfirmation=He;exports.version=Fs;//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|