@deloraprotocol/widget 1.0.1 → 1.0.2

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A React widget component library for crypto trading UI, migrated from delora-exchange (Angular). Includes Trade widget, token selection, network selection, and slippage panel. **Consumers do not need Tailwind** — the library ships compiled CSS.
4
4
 
5
- **Note:** Wallet connection is not implemented. The widget shows placeholder UI for swap actions.
5
+ **Note:** Wallet connection and transaction execution remain host-managed. The widget can request connect, emit quotes, and notify the host when the user clicks `Approve` or `Swap`.
6
6
 
7
7
  ## Installation
8
8
 
@@ -29,7 +29,15 @@ import { TradeWidget } from "@deloraprotocol/widget";
29
29
  theme="dark"
30
30
  config={{
31
31
  apiBase: "https://api.delora.build",
32
+ isWalletConnected: connected,
33
+ onConnectWallet: openWalletModal,
32
34
  }}
35
+ initialBuyToken={{ chainId: 1, address: "0x..." }}
36
+ lockBuyToken
37
+ onQuote={(quote) => console.log("quote", quote)}
38
+ onApprove={(payload) => console.log("approve", payload)}
39
+ onSwap={(payload) => console.log("swap", payload)}
40
+ onError={(error) => console.error(error)}
33
41
  />
34
42
  ```
35
43
 
@@ -57,12 +65,19 @@ import { MyWidget } from "@deloraprotocol/widget";
57
65
 
58
66
  ## API
59
67
 
60
- ### Exports
61
-
62
- - `MyWidget` — the widget component
63
- - `MyWidgetTheme` — `"light" | "dark"`
64
- - `MyWidgetVars` — typed object for token overrides
65
- - `MyWidgetProps` — component props
68
+ ### Exports
69
+
70
+ - `MyWidget` — the widget component
71
+ - `TradeWidget` — trade widget with token/network selection and quote flow
72
+ - `MyWidgetTheme` — `"light" | "dark"`
73
+ - `MyWidgetVars` — typed object for token overrides
74
+ - `MyWidgetProps` — component props
75
+ - `TradeWidgetProps`, `TradeWidgetConfig`
76
+ - `TradeWidgetTokenSelection`
77
+ - `TradeWidgetQuotePayload`
78
+ - `TradeWidgetActionPayload`
79
+ - `TradeWidgetErrorPayload`
80
+ - `Token`, `Network`
66
81
 
67
82
  ### `MyWidgetProps`
68
83
 
@@ -73,7 +88,51 @@ import { MyWidget } from "@deloraprotocol/widget";
73
88
  | `className` | `string` | Applied to root (for host layout/styling) |
74
89
  | `style` | `React.CSSProperties` | Applied last for advanced overrides |
75
90
 
76
- Extends `React.HTMLAttributes<HTMLDivElement>` for other div props.
91
+ Extends `React.HTMLAttributes<HTMLDivElement>` for other div props.
92
+
93
+ ### `TradeWidgetProps`
94
+
95
+ `TradeWidgetProps` extends normal root `div` props except DOM `onError`, which is reserved for the widget error callback below.
96
+
97
+ | Prop | Type | Description |
98
+ |----------|-------------------|--------------------------------------------------|
99
+ | `config` | `TradeWidgetConfig` | Widget runtime config |
100
+ | `theme` | `"light" \| "dark"` | Built-in theme (default: `"dark"`) |
101
+ | `vars` | `Partial<MyWidgetVars>` | Override theme tokens via CSS variables |
102
+ | `initialSellToken` | `{ chainId: number; address: string }` | Preselect sell token |
103
+ | `initialBuyToken` | `{ chainId: number; address: string }` | Preselect buy token |
104
+ | `initialSellNetworkId` | `number` | Preselect sell network |
105
+ | `initialBuyNetworkId` | `number` | Preselect buy network |
106
+ | `lockSellToken` | `boolean` | Prevent changing sell token |
107
+ | `lockBuyToken` | `boolean` | Prevent changing buy token |
108
+ | `lockSellNetwork` | `boolean` | Prevent changing sell network |
109
+ | `lockBuyNetwork` | `boolean` | Prevent changing buy network |
110
+ | `onQuote` | `(payload) => void` | Called when a new quote is resolved |
111
+ | `onApprove` | `(payload) => void` | Called when the user presses `Approve` |
112
+ | `onSwap` | `(payload) => void` | Called when the user presses `Swap` |
113
+ | `onError` | `(payload) => void` | Called for metadata, selection, and quote errors |
114
+
115
+ ### `TradeWidgetConfig`
116
+
117
+ | Prop | Type | Description |
118
+ |----------|-------------------|--------------------------------------------------|
119
+ | `apiBase` | `string` | Delora API base for `/v1/chains`, `/v1/tokens`, `/v1/quotes` |
120
+ | `assetBaseUrl` | `string` | Optional base for resolving relative image URLs |
121
+ | `dataBaseUrl` | `string` | Legacy image-base fallback |
122
+ | `isWalletConnected` | `boolean` | Controls the main action button state |
123
+ | `onConnectWallet` | `() => void` | Called when the user clicks `Connect Wallet` |
124
+
125
+ ### Callback payloads
126
+
127
+ - `onQuote(payload)` returns selected sell/buy network, selected sell/buy token, current sell/buy amounts, slippage, and the raw Delora `quote`.
128
+ - `onApprove(payload)` and `onSwap(payload)` return the current selection plus `quote`, `txData`, `price`, and `gasCostUSD`.
129
+ - `onError(payload)` returns `{ source, message, status?, statusCode?, error? }`, where `source` is one of `metadata`, `selection`, or `quote`.
130
+
131
+ ### Locking behavior
132
+
133
+ - `lockBuyToken` / `lockSellToken` disable token picking and also freeze the related network, because the token already implies a chain.
134
+ - `lockBuyNetwork` / `lockSellNetwork` disable network changes but keep token selection available within the locked chain.
135
+ - Any lock also disables the center "swap sides" button to avoid silently breaking host-provided constraints.
77
136
 
78
137
  ## Why no Tailwind required in host
79
138
 
package/dist/index.d.ts CHANGED
@@ -49,6 +49,34 @@ export declare interface Network {
49
49
  nativeCurrency: INativeCurrency;
50
50
  }
51
51
 
52
+ declare interface QuoteResponse {
53
+ calldata?: {
54
+ to?: string;
55
+ data?: string;
56
+ value?: string;
57
+ };
58
+ gas?: {
59
+ gasPrice?: string;
60
+ gasLimit?: string;
61
+ maxFeePerGas?: string;
62
+ maxPriorityFeePerGas?: string;
63
+ };
64
+ inputAmount?: string;
65
+ outputAmount?: string;
66
+ fees?: {
67
+ total?: {
68
+ amount: string;
69
+ decimals?: number;
70
+ };
71
+ breakdown?: Array<{
72
+ type: string;
73
+ amount: string;
74
+ gasPrice?: string;
75
+ }>;
76
+ };
77
+ [key: string]: unknown;
78
+ }
79
+
52
80
  export declare interface Token {
53
81
  symbol: string;
54
82
  imageUrl: string;
@@ -61,6 +89,21 @@ export declare interface Token {
61
89
 
62
90
  export declare function TradeWidget(props: TradeWidgetProps): JSX.Element;
63
91
 
92
+ export declare interface TradeWidgetActionPayload {
93
+ action: "approve" | "swap";
94
+ sellNetwork: Network;
95
+ buyNetwork: Network;
96
+ sellToken: Token;
97
+ buyToken: Token;
98
+ sellAmount: string;
99
+ buyAmount: string;
100
+ slippage: number;
101
+ quote: QuoteResponse | null;
102
+ txData: QuoteResponse["calldata"] | null;
103
+ price: number;
104
+ gasCostUSD: string | null;
105
+ }
106
+
64
107
  export declare interface TradeWidgetConfig {
65
108
  /** Legacy asset base or custom relative-image base. Metadata is loaded from apiBase/v1/... */
66
109
  dataBaseUrl?: string;
@@ -74,8 +117,44 @@ export declare interface TradeWidgetConfig {
74
117
  onConnectWallet?: () => void;
75
118
  }
76
119
 
77
- export declare interface TradeWidgetProps extends MyWidgetProps {
120
+ export declare interface TradeWidgetErrorPayload {
121
+ source: "metadata" | "quote" | "selection";
122
+ message: string;
123
+ status?: number;
124
+ statusCode?: number;
125
+ error?: unknown;
126
+ }
127
+
128
+ export declare interface TradeWidgetProps extends Omit<MyWidgetProps, "onError"> {
78
129
  config: TradeWidgetConfig;
130
+ initialSellToken?: TradeWidgetTokenSelection;
131
+ initialBuyToken?: TradeWidgetTokenSelection;
132
+ initialSellNetworkId?: number;
133
+ initialBuyNetworkId?: number;
134
+ lockBuyToken?: boolean;
135
+ lockSellToken?: boolean;
136
+ lockBuyNetwork?: boolean;
137
+ lockSellNetwork?: boolean;
138
+ onApprove?: (payload: TradeWidgetActionPayload) => void;
139
+ onSwap?: (payload: TradeWidgetActionPayload) => void;
140
+ onQuote?: (payload: TradeWidgetQuotePayload) => void;
141
+ onError?: (payload: TradeWidgetErrorPayload) => void;
142
+ }
143
+
144
+ export declare interface TradeWidgetQuotePayload {
145
+ sellNetwork: Network;
146
+ buyNetwork: Network;
147
+ sellToken: Token;
148
+ buyToken: Token;
149
+ sellAmount: string;
150
+ buyAmount: string;
151
+ slippage: number;
152
+ quote: QuoteResponse;
153
+ }
154
+
155
+ export declare interface TradeWidgetTokenSelection {
156
+ chainId: number;
157
+ address: string;
79
158
  }
80
159
 
81
160
  export { }