@liberfi.io/ui-trade 0.1.6 → 0.1.7
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 +98 -1
- package/dist/index.d.mts +246 -21
- package/dist/index.d.ts +246 -21
- 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 +17 -17
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The package is organized in three layers:
|
|
|
6
6
|
|
|
7
7
|
- **Hooks** (`useSwap`, `useSwapRoutePolling`, `useTxConfirmation`) — pure-logic building blocks with no UI side-effects, designed for IoC.
|
|
8
8
|
- **Swap Widget** (`SwapWidget` / `useSwapScript` / `SwapUI` / `SwapPreviewModal`) — a full swap form with preview-before-confirm flow, following the Script/Widget/UI three-layer architecture, composable at any level.
|
|
9
|
-
- **Instant Trade** (`InstantTradeWidget` / `InstantTradeProvider` / `MultiChainPresetFormWidget` / `PresetFormWidget`) — a configurable quick-trade form with buy/sell tabs, preset management, customizable quick-amount buttons, and trade settings (slippage, priority fee, tip fee, anti-MEV).
|
|
9
|
+
- **Instant Trade** (`InstantTradeWidget` / `InstantTradeProvider` / `MultiChainPresetFormWidget` / `PresetFormWidget`) — a configurable quick-trade form with buy/sell tabs, preset management, customizable quick-amount buttons, and trade settings (slippage, priority fee, tip fee, anti-MEV). Includes list-optimised variants (`InstantTradeSwapProvider` / `InstantTradeListButtonWidget`) that share a single set of context subscriptions across N buttons.
|
|
10
10
|
- **State atoms** (`presetAtomFamily` / `instantTradeAmountAtomFamily`) — Jotai-based persistent state for trade presets and amount/preset selection, storage-backend agnostic via `atomWithStorage`.
|
|
11
11
|
|
|
12
12
|
## Design Philosophy
|
|
@@ -567,6 +567,59 @@ Atom-backed widget that wraps `AmountPresetInputUI` with `atomWithStorage` persi
|
|
|
567
567
|
|
|
568
568
|
Trade execution button that reads state from `InstantTradeProvider`. Handles wallet resolution, amount conversion, and swap execution.
|
|
569
569
|
|
|
570
|
+
#### `InstantTradeSwapProvider`
|
|
571
|
+
|
|
572
|
+
Context provider that calls `useSwap`, `useConnectedWallet`, and `useAuthCallback` once and exposes a single **stable swap function** to descendant `InstantTradeListButtonWidget` components. Use this when rendering many trade buttons in a list to avoid N redundant context subscriptions.
|
|
573
|
+
|
|
574
|
+
```tsx
|
|
575
|
+
<InstantTradeSwapProvider
|
|
576
|
+
chain={Chain.SOLANA}
|
|
577
|
+
onSwapSubmitted={(r) => toast.success(`TX: ${r.txHash}`)}
|
|
578
|
+
onSwapError={(e, phase) => toast.error(`${phase}: ${e.message}`)}
|
|
579
|
+
>
|
|
580
|
+
{tokens.map((t) => (
|
|
581
|
+
<InstantTradeListButtonWidget key={t.address} ... />
|
|
582
|
+
))}
|
|
583
|
+
</InstantTradeSwapProvider>
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
**Props (`InstantTradeSwapProviderProps`):**
|
|
587
|
+
|
|
588
|
+
| Name | Type | Description |
|
|
589
|
+
| ------------------ | ------------------------------------------ | --------------------------------------------- |
|
|
590
|
+
| `chain` | `Chain` | Target chain. |
|
|
591
|
+
| `onSwapSubmitted?` | `(result: SwapResult) => void` | Called when a swap transaction is submitted. |
|
|
592
|
+
| `onSwapError?` | `(error: Error, phase: SwapPhase) => void` | Called when a swap error occurs at any phase. |
|
|
593
|
+
| `children` | `ReactNode` | Child components (buttons, inputs, etc.). |
|
|
594
|
+
|
|
595
|
+
#### `InstantTradeListButtonWidget`
|
|
596
|
+
|
|
597
|
+
Memoized trade button optimised for list rendering. Visually identical to `InstantTradeButtonWidget`, but reads the swap function from the nearest `InstantTradeSwapProvider` instead of creating its own `useSwap` / `useConnectedWallet` / `useAuthCallback` subscriptions. Each button only subscribes to its own Jotai atoms (amount + preset) and the stable context function, eliminating unnecessary re-renders when wallet or auth state changes.
|
|
598
|
+
|
|
599
|
+
Must be used inside an `InstantTradeSwapProvider`.
|
|
600
|
+
|
|
601
|
+
**Props (`InstantTradeListButtonWidgetProps`):**
|
|
602
|
+
|
|
603
|
+
| Name | Type | Description |
|
|
604
|
+
| ------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
|
605
|
+
| `id` | `string` | Business identifier for atom key (must match `AmountPresetInputWidget`). |
|
|
606
|
+
| `chain` | `Chain` | Target chain. |
|
|
607
|
+
| `token` | `PredefinedToken` | Payment token (decimals, symbol, address for atom key and swap input). |
|
|
608
|
+
| `output` | `string` | Output token address. |
|
|
609
|
+
| `storageKeyPrefix?` | `string` | Storage key prefix. Must match `AmountPresetInputWidget`. Default `"liberfi."`. |
|
|
610
|
+
| `size?` | `"xs" \| "sm" \| "md" \| "lg"` | Button size. Defaults to `"sm"`. |
|
|
611
|
+
| `radius?` | `"full" \| "lg" \| "md" \| "sm" \| "none"` | Button border radius. |
|
|
612
|
+
| `color?` | `"primary" \| "secondary" \| "success" \| "warning" \| "danger" \| "default"` | Button color. Defaults to `"primary"`. |
|
|
613
|
+
| `className?` | `string` | External style customization. |
|
|
614
|
+
|
|
615
|
+
#### `useInstantTradeListButtonScript(params)`
|
|
616
|
+
|
|
617
|
+
Lightweight script hook for the list button. Same return type as `useInstantTradeButtonScript` but without `useSwap` / `useConnectedWallet` / `useAuthCallback` subscriptions. Must be called inside an `InstantTradeSwapProvider`.
|
|
618
|
+
|
|
619
|
+
#### `useInstantTradeSwap()`
|
|
620
|
+
|
|
621
|
+
Returns the auth-guarded swap function from the nearest `InstantTradeSwapProvider`. Throws if called outside the provider. The returned function has type `InstantTradeSwapFn`.
|
|
622
|
+
|
|
570
623
|
#### `MultiChainPresetFormWidget`
|
|
571
624
|
|
|
572
625
|
Self-contained multi-chain preset editor. Combines chain switching (`ChainSelectMobileUI`), preset index tabs (P1/P2/P3), and a persisted `PresetFormWidget`.
|
|
@@ -844,6 +897,50 @@ function TradeSettings() {
|
|
|
844
897
|
}
|
|
845
898
|
```
|
|
846
899
|
|
|
900
|
+
### Token List with Shared Swap Provider
|
|
901
|
+
|
|
902
|
+
```tsx
|
|
903
|
+
import { Chain } from "@liberfi.io/types";
|
|
904
|
+
import {
|
|
905
|
+
InstantTradeSwapProvider,
|
|
906
|
+
AmountPresetInputWidget,
|
|
907
|
+
InstantTradeListButtonWidget,
|
|
908
|
+
} from "@liberfi.io/ui-trade";
|
|
909
|
+
import { SOLANA_TOKENS } from "@liberfi.io/utils";
|
|
910
|
+
|
|
911
|
+
function TokenList({
|
|
912
|
+
tokens,
|
|
913
|
+
}: {
|
|
914
|
+
tokens: { address: string; symbol: string }[];
|
|
915
|
+
}) {
|
|
916
|
+
return (
|
|
917
|
+
<InstantTradeSwapProvider
|
|
918
|
+
chain={Chain.SOLANA}
|
|
919
|
+
onSwapSubmitted={(r) => toast.success(`TX: ${r.txHash}`)}
|
|
920
|
+
onSwapError={(e, phase) => toast.error(`${phase}: ${e.message}`)}
|
|
921
|
+
>
|
|
922
|
+
{/* Shared amount input — one for all buttons */}
|
|
923
|
+
<AmountPresetInputWidget
|
|
924
|
+
id="token-list"
|
|
925
|
+
chain={Chain.SOLANA}
|
|
926
|
+
token={SOLANA_TOKENS.native}
|
|
927
|
+
/>
|
|
928
|
+
|
|
929
|
+
{/* N buttons — each only subscribes to its own atom + stable context */}
|
|
930
|
+
{tokens.map((t) => (
|
|
931
|
+
<InstantTradeListButtonWidget
|
|
932
|
+
key={t.address}
|
|
933
|
+
id="token-list"
|
|
934
|
+
chain={Chain.SOLANA}
|
|
935
|
+
token={SOLANA_TOKENS.native}
|
|
936
|
+
output={t.address}
|
|
937
|
+
/>
|
|
938
|
+
))}
|
|
939
|
+
</InstantTradeSwapProvider>
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
```
|
|
943
|
+
|
|
847
944
|
### Reading Preset Values from Atoms
|
|
848
945
|
|
|
849
946
|
```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import * as jotai from 'jotai';
|
|
|
5
5
|
import * as jotai_utils from 'jotai/utils';
|
|
6
6
|
import { WalletAdapter } from '@liberfi.io/wallet-connector';
|
|
7
7
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
|
+
import * as react from 'react';
|
|
8
9
|
import { ReactNode } from 'react';
|
|
9
10
|
import { PredefinedToken } from '@liberfi.io/utils';
|
|
10
11
|
|
|
@@ -569,8 +570,8 @@ interface AmountPresetInputUIProps {
|
|
|
569
570
|
radius?: "full" | "lg" | "md" | "sm" | "none";
|
|
570
571
|
className?: string;
|
|
571
572
|
}
|
|
572
|
-
/**
|
|
573
|
-
interface
|
|
573
|
+
/** Parameters for {@link useAmountPresetInputScript}. */
|
|
574
|
+
interface UseAmountPresetInputScriptParams {
|
|
574
575
|
/** Business identifier used as part of the storage key (e.g. `"token-detail"`, `"watchlist"`). */
|
|
575
576
|
id: string;
|
|
576
577
|
/** Target chain. */
|
|
@@ -585,15 +586,118 @@ interface AmountPresetInputWidgetProps {
|
|
|
585
586
|
onPresetChange?: (preset: number) => void;
|
|
586
587
|
/** Called when the user clicks the already-selected preset (e.g. open settings). */
|
|
587
588
|
onPresetClick?: (preset: number) => void;
|
|
589
|
+
}
|
|
590
|
+
/** Return value of {@link useAmountPresetInputScript}. */
|
|
591
|
+
interface UseAmountPresetInputScriptResult {
|
|
592
|
+
/** Payment token (forwarded from params). */
|
|
593
|
+
token: PredefinedToken;
|
|
594
|
+
/** Target chain (forwarded from params). */
|
|
595
|
+
chain: Chain;
|
|
596
|
+
/** Current amount value from the atom. */
|
|
597
|
+
amount: number | undefined;
|
|
598
|
+
/** Update the amount (persists to atom and fires onAmountChange). */
|
|
599
|
+
handleAmountChange: (amount?: number) => void;
|
|
600
|
+
/** Currently selected preset index. */
|
|
601
|
+
preset: number;
|
|
602
|
+
/** Update the preset (persists to atom and fires onPresetChange). */
|
|
603
|
+
handlePresetChange: (preset: number) => void;
|
|
604
|
+
/** Called when the user clicks the already-selected preset (forwarded from params). */
|
|
605
|
+
onPresetClick?: (preset: number) => void;
|
|
606
|
+
/** Resolved preset values for all three presets. */
|
|
607
|
+
presetValues: TradePresetValues[];
|
|
608
|
+
}
|
|
609
|
+
/** Props for {@link AmountPresetInputWidget}. */
|
|
610
|
+
interface AmountPresetInputWidgetProps extends UseAmountPresetInputScriptParams {
|
|
588
611
|
/** Controls overall component size. Defaults to `"sm"`. */
|
|
589
612
|
size?: "sm" | "md" | "lg";
|
|
590
613
|
radius?: "full" | "lg" | "md" | "sm";
|
|
591
614
|
className?: string;
|
|
592
615
|
}
|
|
593
|
-
/**
|
|
594
|
-
interface
|
|
616
|
+
/** Parameters for {@link useInstantTradeButton}. */
|
|
617
|
+
interface UseInstantTradeButtonParams {
|
|
618
|
+
/** Business identifier for atom key (e.g. `"token-detail"`, `"watchlist"`). */
|
|
619
|
+
id: string;
|
|
620
|
+
/** Target chain. */
|
|
621
|
+
chain: Chain;
|
|
622
|
+
/** Payment token — provides decimals, address (used as atom key and swap input). */
|
|
623
|
+
token: PredefinedToken;
|
|
624
|
+
/** Output token address (the token the user receives). */
|
|
625
|
+
output: string;
|
|
626
|
+
/** Storage key prefix. Must match the corresponding {@link AmountPresetInputWidget}. Defaults to `"liberfi."`. */
|
|
627
|
+
storageKeyPrefix?: string;
|
|
628
|
+
/** Called when a swap transaction is successfully submitted. */
|
|
629
|
+
onSwapSubmitted?: (result: SwapResult) => void;
|
|
630
|
+
/** Called when a swap error occurs at any phase. */
|
|
631
|
+
onSwapError?: (error: Error, phase: SwapPhase) => void;
|
|
632
|
+
}
|
|
633
|
+
/** Return value of {@link useInstantTradeButton}. */
|
|
634
|
+
interface UseInstantTradeButtonResult {
|
|
635
|
+
/** Current amount from the atom (user-facing units, e.g. 0.01). */
|
|
636
|
+
amount: number | undefined;
|
|
637
|
+
/** Payment token symbol (e.g. "SOL"). */
|
|
638
|
+
tokenSymbol: string;
|
|
639
|
+
/** Whether the button should be disabled (no amount or no output). */
|
|
640
|
+
isDisabled: boolean;
|
|
641
|
+
/** Whether a swap is currently in progress. */
|
|
642
|
+
isSwapping: boolean;
|
|
643
|
+
/** Auth-guarded swap handler — triggers sign-in if unauthenticated. */
|
|
644
|
+
handleSwap: () => Promise<void>;
|
|
645
|
+
}
|
|
646
|
+
/** Props for {@link InstantTradeButtonWidget}. */
|
|
647
|
+
interface InstantTradeButtonWidgetProps extends UseInstantTradeButtonParams {
|
|
648
|
+
/** Button size. Defaults to `"sm"`. */
|
|
649
|
+
size?: "xs" | "sm" | "md" | "lg";
|
|
650
|
+
/** Button border radius. Defaults to `"md"`. */
|
|
651
|
+
radius?: "full" | "lg" | "md" | "sm" | "none";
|
|
652
|
+
/** Button color. Defaults to `"primary"`. */
|
|
653
|
+
color?: "primary" | "secondary" | "success" | "warning" | "danger" | "default";
|
|
654
|
+
className?: string;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Swap function provided by {@link InstantTradeSwapProvider}.
|
|
658
|
+
*
|
|
659
|
+
* Auth-guarded and wallet-injected — the caller only supplies token
|
|
660
|
+
* addresses, amount, and trade settings. Returns `undefined` when the
|
|
661
|
+
* auth guard intercepts (user not authenticated).
|
|
662
|
+
*/
|
|
663
|
+
type InstantTradeSwapFn = (input: Omit<SwapInput, "wallet" | "chain">) => Promise<SwapResult | undefined>;
|
|
664
|
+
/** Props for {@link InstantTradeSwapProvider}. */
|
|
665
|
+
interface InstantTradeSwapProviderProps {
|
|
666
|
+
/** Target chain. */
|
|
667
|
+
chain: Chain;
|
|
668
|
+
/** Called when a swap transaction is successfully submitted. */
|
|
669
|
+
onSwapSubmitted?: (result: SwapResult) => void;
|
|
670
|
+
/** Called when a swap error occurs at any phase. */
|
|
671
|
+
onSwapError?: (error: Error, phase: SwapPhase) => void;
|
|
672
|
+
children: ReactNode;
|
|
673
|
+
}
|
|
674
|
+
/** Parameters for {@link useInstantTradeListButtonScript}. */
|
|
675
|
+
interface UseInstantTradeListButtonParams {
|
|
676
|
+
/** Business identifier for atom key (e.g. `"token-detail"`, `"watchlist"`). */
|
|
677
|
+
id: string;
|
|
678
|
+
/** Target chain. */
|
|
679
|
+
chain: Chain;
|
|
680
|
+
/** Payment token — provides decimals, symbol, address (used as atom key and swap input). */
|
|
681
|
+
token: PredefinedToken;
|
|
682
|
+
/** Output token address (the token the user receives). */
|
|
683
|
+
output: string;
|
|
684
|
+
/** Storage key prefix. Must match the corresponding {@link AmountPresetInputWidget}. Defaults to `"liberfi."`. */
|
|
685
|
+
storageKeyPrefix?: string;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Return value of {@link useInstantTradeListButtonScript}.
|
|
689
|
+
* Same shape as {@link UseInstantTradeButtonResult}.
|
|
690
|
+
*/
|
|
691
|
+
type UseInstantTradeListButtonResult = UseInstantTradeButtonResult;
|
|
692
|
+
/** Props for {@link InstantTradeListButtonWidget}. */
|
|
693
|
+
interface InstantTradeListButtonWidgetProps extends UseInstantTradeListButtonParams {
|
|
694
|
+
/** Button size. Defaults to `"sm"`. */
|
|
695
|
+
size?: "xs" | "sm" | "md" | "lg";
|
|
696
|
+
/** Button border radius. */
|
|
697
|
+
radius?: "full" | "lg" | "md" | "sm" | "none";
|
|
698
|
+
/** Button color. Defaults to `"primary"`. */
|
|
699
|
+
color?: "primary" | "secondary" | "success" | "warning" | "danger" | "default";
|
|
595
700
|
className?: string;
|
|
596
|
-
children?: ReactNode;
|
|
597
701
|
}
|
|
598
702
|
/** Props for {@link PresetFormUI}. */
|
|
599
703
|
interface PresetFormUIProps {
|
|
@@ -604,8 +708,8 @@ interface PresetFormUIProps {
|
|
|
604
708
|
disableAnimation?: boolean;
|
|
605
709
|
className?: string;
|
|
606
710
|
}
|
|
607
|
-
/**
|
|
608
|
-
interface
|
|
711
|
+
/** Parameters for {@link usePresetFormScript}. */
|
|
712
|
+
interface UsePresetFormScriptParams {
|
|
609
713
|
/** Target chain — determines default values and visible fields. */
|
|
610
714
|
chain: Chain;
|
|
611
715
|
/** Preset index (0, 1, or 2). Defaults to 0. */
|
|
@@ -614,17 +718,45 @@ interface PresetFormWidgetProps {
|
|
|
614
718
|
storageKeyPrefix?: string;
|
|
615
719
|
/** Notification callback when value changes (does not control state). */
|
|
616
720
|
onChange?: (direction: "buy" | "sell", value: TradePresetValues) => void;
|
|
721
|
+
}
|
|
722
|
+
/** Return value of {@link usePresetFormScript}. */
|
|
723
|
+
interface UsePresetFormScriptResult {
|
|
724
|
+
/** Current buy/sell direction. */
|
|
725
|
+
direction: "buy" | "sell";
|
|
726
|
+
/** Update the buy/sell direction. */
|
|
727
|
+
setDirection: (d: "buy" | "sell") => void;
|
|
728
|
+
/** Current preset values from the atom. */
|
|
729
|
+
value: TradePresetValues;
|
|
730
|
+
/** Update the preset values (persists to atom and fires onChange). */
|
|
731
|
+
handleChange: (next: TradePresetValues) => void;
|
|
732
|
+
}
|
|
733
|
+
/** Props for {@link PresetFormWidget}. */
|
|
734
|
+
interface PresetFormWidgetProps extends UsePresetFormScriptParams {
|
|
617
735
|
disableAnimation?: boolean;
|
|
618
736
|
className?: string;
|
|
619
737
|
}
|
|
620
|
-
/**
|
|
621
|
-
interface
|
|
738
|
+
/** Parameters for {@link useMultiPresetFormScript}. */
|
|
739
|
+
interface UseMultiPresetFormScriptParams {
|
|
622
740
|
/** Target chain — determines default values and visible fields. */
|
|
623
741
|
chain: Chain;
|
|
624
742
|
/** Storage key prefix. Defaults to `"liberfi."`. */
|
|
625
743
|
storageKeyPrefix?: string;
|
|
626
744
|
/** Notification callback when value changes (does not control state). */
|
|
627
745
|
onChange?: (presetIndex: number, direction: "buy" | "sell", value: TradePresetValues) => void;
|
|
746
|
+
}
|
|
747
|
+
/** Return value of {@link useMultiPresetFormScript}. */
|
|
748
|
+
interface UseMultiPresetFormScriptResult {
|
|
749
|
+
/** Number of available presets. */
|
|
750
|
+
presetCount: number;
|
|
751
|
+
/** Currently selected preset index. */
|
|
752
|
+
presetIndex: number;
|
|
753
|
+
/** Update the selected preset index. */
|
|
754
|
+
setPresetIndex: (index: number) => void;
|
|
755
|
+
/** Callback forwarded to {@link PresetFormWidget} that tags changes with the current preset index. */
|
|
756
|
+
handlePresetChange: (direction: "buy" | "sell", value: TradePresetValues) => void;
|
|
757
|
+
}
|
|
758
|
+
/** Props for {@link MultiPresetFormWidget}. */
|
|
759
|
+
interface MultiPresetFormWidgetProps extends UseMultiPresetFormScriptParams {
|
|
628
760
|
disableAnimation?: boolean;
|
|
629
761
|
className?: string;
|
|
630
762
|
}
|
|
@@ -694,13 +826,13 @@ declare function InstantTradeWidget({ chain, tokenAddress, onSwapSubmitted, onSw
|
|
|
694
826
|
/**
|
|
695
827
|
* Amount + preset input widget — atom-backed orchestration layer.
|
|
696
828
|
*
|
|
697
|
-
*
|
|
698
|
-
* `id + chain + token.address
|
|
699
|
-
* {@link presetAtomFamily} for tooltip display.
|
|
829
|
+
* Wires {@link useAmountPresetInputScript} to {@link AmountPresetInputUI}.
|
|
830
|
+
* State is persisted via `atomWithStorage` (keyed by `id + chain + token.address`).
|
|
700
831
|
*
|
|
701
832
|
* For a pure presentational input without persistence, use {@link AmountPresetInputUI}.
|
|
833
|
+
* For custom UI with the same state logic, use the hook directly.
|
|
702
834
|
*/
|
|
703
|
-
declare function AmountPresetInputWidget({
|
|
835
|
+
declare function AmountPresetInputWidget({ size, radius, className, ...scriptParams }: AmountPresetInputWidgetProps): react_jsx_runtime.JSX.Element;
|
|
704
836
|
|
|
705
837
|
/**
|
|
706
838
|
* Preset form widget — atom-backed orchestration layer with Buy/Sell tabs.
|
|
@@ -710,7 +842,7 @@ declare function AmountPresetInputWidget({ id, chain, token, storageKeyPrefix, o
|
|
|
710
842
|
*
|
|
711
843
|
* For a pure presentational form without persistence, use {@link PresetFormUI}.
|
|
712
844
|
*/
|
|
713
|
-
declare function PresetFormWidget({
|
|
845
|
+
declare function PresetFormWidget({ disableAnimation, className, ...scriptParams }: PresetFormWidgetProps): react_jsx_runtime.JSX.Element;
|
|
714
846
|
|
|
715
847
|
/**
|
|
716
848
|
* Multi preset form widget.
|
|
@@ -718,7 +850,7 @@ declare function PresetFormWidget({ chain, presetIndex, storageKeyPrefix, onChan
|
|
|
718
850
|
* Combines preset index tabs,
|
|
719
851
|
* and a persisted {@link PresetFormWidget} into a single self-contained editor.
|
|
720
852
|
*/
|
|
721
|
-
declare function MultiPresetFormWidget({
|
|
853
|
+
declare function MultiPresetFormWidget({ disableAnimation, className, ...scriptParams }: MultiPresetFormWidgetProps): react_jsx_runtime.JSX.Element;
|
|
722
854
|
|
|
723
855
|
/**
|
|
724
856
|
* Async-modal wrapper for multi-chain preset editing.
|
|
@@ -733,6 +865,40 @@ declare function PresetFormModal({ id }: {
|
|
|
733
865
|
id?: string;
|
|
734
866
|
}): react_jsx_runtime.JSX.Element;
|
|
735
867
|
|
|
868
|
+
/**
|
|
869
|
+
* Script hook for the amount + preset input.
|
|
870
|
+
*
|
|
871
|
+
* Subscribes to atom-backed `{ amount, preset }` state (keyed by
|
|
872
|
+
* `id + chain + token.address`) and reads preset values from
|
|
873
|
+
* {@link presetAtomFamily} for tooltip display.
|
|
874
|
+
*
|
|
875
|
+
* Use the companion {@link AmountPresetInputWidget} for the default UI,
|
|
876
|
+
* or call this hook directly to build a custom amount + preset input.
|
|
877
|
+
*/
|
|
878
|
+
declare function useAmountPresetInputScript(params: UseAmountPresetInputScriptParams): UseAmountPresetInputScriptResult;
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
* Script hook for the preset form.
|
|
882
|
+
*
|
|
883
|
+
* Manages buy/sell direction state and subscribes to the atom-backed preset
|
|
884
|
+
* values identified by `chain`, `presetIndex`, and `storageKeyPrefix`.
|
|
885
|
+
*
|
|
886
|
+
* Use the companion {@link PresetFormWidget} for the default UI,
|
|
887
|
+
* or call this hook directly to build a custom preset form.
|
|
888
|
+
*/
|
|
889
|
+
declare function usePresetFormScript(params: UsePresetFormScriptParams): UsePresetFormScriptResult;
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Script hook for the multi-preset form.
|
|
893
|
+
*
|
|
894
|
+
* Manages preset index selection and forwards value changes
|
|
895
|
+
* tagged with the current index to the caller.
|
|
896
|
+
*
|
|
897
|
+
* Use the companion {@link MultiPresetFormWidget} for the default UI,
|
|
898
|
+
* or call this hook directly to build a custom multi-preset form.
|
|
899
|
+
*/
|
|
900
|
+
declare function useMultiPresetFormScript(params: UseMultiPresetFormScriptParams): UseMultiPresetFormScriptResult;
|
|
901
|
+
|
|
736
902
|
/**
|
|
737
903
|
* Pure presentational component for the instant trade form.
|
|
738
904
|
*
|
|
@@ -763,12 +929,71 @@ declare function AmountPresetInputUI({ token, chain, amount, onAmountChange, pre
|
|
|
763
929
|
declare function PresetFormUI({ value, onChange, chain, disableAnimation, className, }: PresetFormUIProps): react_jsx_runtime.JSX.Element;
|
|
764
930
|
|
|
765
931
|
/**
|
|
766
|
-
*
|
|
932
|
+
* Script hook for the instant-trade button.
|
|
933
|
+
*
|
|
934
|
+
* Subscribes to the amount / preset atoms identified by `id`, resolves
|
|
935
|
+
* preset values, and returns an auth-guarded swap handler plus all
|
|
936
|
+
* derived state needed to render a trade button.
|
|
937
|
+
*
|
|
938
|
+
* Use the companion {@link InstantTradeButton} widget for the default UI,
|
|
939
|
+
* or call this hook directly to render a fully custom button.
|
|
940
|
+
*/
|
|
941
|
+
declare function useInstantTradeButtonScript(params: UseInstantTradeButtonParams): UseInstantTradeButtonResult;
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Default instant-trade button widget.
|
|
945
|
+
*
|
|
946
|
+
* Wires {@link useInstantTradeButton} to a {@link StyledButton} with a
|
|
947
|
+
* lightning icon and `"amount symbol"` label. For a fully custom button,
|
|
948
|
+
* use the hook directly.
|
|
949
|
+
*/
|
|
950
|
+
declare function InstantTradeButtonWidget({ size, radius, color, className, ...scriptParams }: InstantTradeButtonWidgetProps): react_jsx_runtime.JSX.Element;
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Provides a single auth-guarded swap function to all descendant
|
|
954
|
+
* {@link InstantTradeListButtonWidget} components.
|
|
955
|
+
*
|
|
956
|
+
* Calls `useSwap`, `useConnectedWallet`, and `useAuthCallback` **once**
|
|
957
|
+
* so that N list buttons share one set of context subscriptions instead
|
|
958
|
+
* of each creating their own.
|
|
959
|
+
*
|
|
960
|
+
* The context value is a **stable function reference** (backed by refs)
|
|
961
|
+
* that will not cause consumer re-renders.
|
|
962
|
+
*/
|
|
963
|
+
declare function InstantTradeSwapProvider({ chain, onSwapSubmitted, onSwapError, children, }: InstantTradeSwapProviderProps): react_jsx_runtime.JSX.Element;
|
|
964
|
+
/**
|
|
965
|
+
* Returns the auth-guarded swap function from the nearest
|
|
966
|
+
* {@link InstantTradeSwapProvider}.
|
|
967
|
+
*
|
|
968
|
+
* @throws If called outside an `InstantTradeSwapProvider`.
|
|
969
|
+
*/
|
|
970
|
+
declare function useInstantTradeSwap(): InstantTradeSwapFn;
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* Lightweight script hook for the instant-trade button in list scenarios.
|
|
974
|
+
*
|
|
975
|
+
* Unlike {@link useInstantTradeButtonScript}, this hook does **not** call
|
|
976
|
+
* `useSwap`, `useConnectedWallet`, or `useAuthCallback`. Instead it reads
|
|
977
|
+
* the swap function from {@link InstantTradeSwapProvider} via context,
|
|
978
|
+
* eliminating per-button context subscriptions that cause unnecessary
|
|
979
|
+
* re-renders in large lists.
|
|
980
|
+
*
|
|
981
|
+
* Must be used inside an {@link InstantTradeSwapProvider}.
|
|
982
|
+
*/
|
|
983
|
+
declare function useInstantTradeListButtonScript(params: UseInstantTradeListButtonParams): UseInstantTradeListButtonResult;
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Memoized instant-trade button optimised for list rendering.
|
|
987
|
+
*
|
|
988
|
+
* Visually identical to {@link InstantTradeButtonWidget}, but internally
|
|
989
|
+
* reads the swap function from {@link InstantTradeSwapProvider} instead
|
|
990
|
+
* of calling `useSwap` / `useConnectedWallet` / `useAuthCallback` per
|
|
991
|
+
* instance. This eliminates N redundant context subscriptions in a list
|
|
992
|
+
* of N tokens.
|
|
767
993
|
*
|
|
768
|
-
*
|
|
769
|
-
* settings, and calls `useSwap` from the SDK.
|
|
994
|
+
* Must be used inside an {@link InstantTradeSwapProvider}.
|
|
770
995
|
*/
|
|
771
|
-
declare
|
|
996
|
+
declare const InstantTradeListButtonWidget: react.NamedExoticComponent<InstantTradeListButtonWidgetProps>;
|
|
772
997
|
|
|
773
998
|
type AntiMevOption = "off" | "reduced" | "secure";
|
|
774
999
|
type FeeType = "priorityFee" | "gasFee";
|
|
@@ -817,6 +1042,6 @@ declare global {
|
|
|
817
1042
|
};
|
|
818
1043
|
}
|
|
819
1044
|
}
|
|
820
|
-
declare const _default: "0.1.
|
|
1045
|
+
declare const _default: "0.1.7";
|
|
821
1046
|
|
|
822
|
-
export { AmountPresetInputUI, type AmountPresetInputUIProps, AmountPresetInputWidget, type AmountPresetInputWidgetProps, type AmountPresetState, type AntiMevOption, type BuySettings, type ChainPresetFeatures, DEFAULT_BSC_TRADE_PRESET, DEFAULT_EVM_TRADE_PRESET, DEFAULT_INSTANT_TRADE_SETTINGS, DEFAULT_SELL_PERCENTAGES, DEFAULT_SOL_TRADE_PRESET, type FeeType,
|
|
1047
|
+
export { AmountPresetInputUI, type AmountPresetInputUIProps, AmountPresetInputWidget, type AmountPresetInputWidgetProps, type AmountPresetState, type AntiMevOption, type BuySettings, type ChainPresetFeatures, DEFAULT_BSC_TRADE_PRESET, DEFAULT_EVM_TRADE_PRESET, DEFAULT_INSTANT_TRADE_SETTINGS, DEFAULT_SELL_PERCENTAGES, DEFAULT_SOL_TRADE_PRESET, type FeeType, InstantTradeButtonWidget, type InstantTradeButtonWidgetProps, type InstantTradeContextValue, InstantTradeListButtonWidget, type InstantTradeListButtonWidgetProps, InstantTradeProvider, type InstantTradeProviderProps, type InstantTradeSettings, type InstantTradeSwapFn, InstantTradeSwapProvider, type InstantTradeSwapProviderProps, InstantTradeUI, type InstantTradeUIProps, InstantTradeWidget, type InstantTradeWidgetProps, MultiPresetFormWidget, type MultiPresetFormWidgetProps, type PresetDirection, PresetFormModal, type PresetFormModalParams, 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 UseAmountPresetInputScriptParams, type UseAmountPresetInputScriptResult, type UseInstantTradeAmountParams, type UseInstantTradeButtonParams, type UseInstantTradeButtonResult, type UseInstantTradeListButtonParams, type UseInstantTradeListButtonResult, type UseInstantTradeScriptParams, type UseInstantTradeScriptResult, type UseMultiPresetFormScriptParams, type UseMultiPresetFormScriptResult, type UsePresetFormScriptParams, type UsePresetFormScriptResult, type UsePresetValuesParams, type UseSwapOptions, type UseSwapRoutePollingOptions, type UseSwapScriptParams, type UseSwapScriptResult, type UseTxConfirmationOptions, getChainPresetFeatures, getDefaultBuyAmounts, getDefaultPresetForChain, instantTradeAmountAtomFamily, instantTradeAmountKey, presetAtomFamily, presetKey, useAmountPresetInputScript, useInstantTrade, useInstantTradeAmount, useInstantTradeButtonScript, useInstantTradeListButtonScript, useInstantTradeScript, useInstantTradeSwap, useMultiPresetFormScript, usePresetFormScript, usePresetValues, useSwap, useSwapRoutePolling, useSwapScript, useTxConfirmation, _default as version };
|