@recoilpay/intent-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Recoil Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @recoilpay/intent-react
2
+
3
+ RecoilPay intents as one React component. The user types what they want ("swap 10 USDC on Base for ETH on Arbitrum"), sees the best solver quote, confirms in their wallet, and watches it settle, without you building any of that UI.
4
+
5
+ ```sh
6
+ npm install @recoilpay/intent-react viem
7
+ ```
8
+
9
+ ## With wagmi (and RainbowKit)
10
+
11
+ ```tsx
12
+ import { RecoilIntent } from '@recoilpay/intent-react';
13
+ import { useWagmiIntentWallet } from '@recoilpay/intent-react/wagmi';
14
+ import '@recoilpay/intent-react/styles.css';
15
+ import { useConnectModal } from '@rainbow-me/rainbowkit';
16
+
17
+ export function Swap() {
18
+ const wallet = useWagmiIntentWallet(); // null until connected
19
+ const { openConnectModal } = useConnectModal();
20
+
21
+ return <RecoilIntent hfAccessToken={HF_TOKEN} wallet={wallet} onConnectWallet={openConnectModal} />;
22
+ }
23
+ ```
24
+
25
+ The component doesn't include a wallet modal. It uses your app's: `onConnectWallet` opens it, and the `wallet` prop tells the component which account is connected. A pending intent continues by itself once a wallet connects.
26
+
27
+ ## Without wagmi
28
+
29
+ Pass any `IntentWallet`. From a viem `WalletClient`:
30
+
31
+ ```tsx
32
+ import { RecoilIntent, viemWallet } from '@recoilpay/intent-react';
33
+
34
+ <RecoilIntent wallet={walletClient ? viemWallet(walletClient) : null} onConnectWallet={connect} />
35
+ ```
36
+
37
+ ## Props
38
+
39
+ | Prop | Type | |
40
+ |---|---|---|
41
+ | `hfAccessToken` | `string \| null` | Your Hugging Face token for plain-English parsing (see Notes). |
42
+ | `wallet` | `IntentWallet \| null` | The connected wallet. |
43
+ | `onConnectWallet` | `() => void` | Opens your connect flow. |
44
+ | `theme` | `{ mode, accent, accentText, radius, fontFamily }` | `mode` is `'dark'` (default) or `'light'`. It uses your page's font unless you set one. |
45
+ | `examples` | `{ label, sentence }[] \| false` | Clickable suggestions under the field. |
46
+ | `placeholder`, `defaultValue` | `string` | |
47
+ | `onOrderSubmitted` | `(orderId) => void` | The signed order was accepted. |
48
+ | `onComplete` | `(state) => void` | Every intent in the sentence reached a final status. |
49
+ | `onError` | `(message) => void` | Any failure, already written for the end user. |
50
+ | `apiUrl` | `string` | Defaults to production (`https://api.recoilpay.com`). |
51
+ | `session` | `IntentSession` | Share one flow between components, or inject one in tests. |
52
+ | `className` | `string` | Added to the root element. |
53
+
54
+ ## Styling
55
+
56
+ Import `@recoilpay/intent-react/styles.css` once. Every rule is scoped under `.rp-root`, so it won't touch the rest of your page. Beyond the `theme` prop, you can override any variable from your own CSS:
57
+
58
+ ```css
59
+ .my-swap .rp-root {
60
+ --rp-surface: #0f1115;
61
+ --rp-line: #222631;
62
+ --rp-accent: #22c55e;
63
+ --rp-radius: 6px;
64
+ }
65
+ ```
66
+
67
+ Variables: `--rp-surface`, `--rp-raised`, `--rp-sunken`, `--rp-ink`, `--rp-ink-2`, `--rp-muted`, `--rp-line`, `--rp-accent`, `--rp-accent-text`, `--rp-success`, `--rp-danger`, `--rp-radius`, `--rp-font`, `--rp-mono`.
68
+
69
+ ## Your own UI
70
+
71
+ `useRecoilIntent()` gives you the same flow as React state with no markup: `phase`, `preview`, `issues`, `status`, `explorerUrl` and so on, plus `run`, `confirm` and `reset`. See `@recoilpay/intent-core` for what each field means.
72
+
73
+ ```tsx
74
+ const intent = useRecoilIntent({ wallet });
75
+ // intent.phase === 'quoted' → render intent.preview, call intent.confirm()
76
+ ```
77
+
78
+ ## Notes
79
+
80
+ - **Hugging Face token:** Plain-English parsing calls a language model on Hugging Face **from the browser**, with your own access token. The token is visible to anyone who loads your page, so use a fine-grained token with only the "Make calls to Inference Providers" permission, use it for nothing else, and rotate it if it's abused. Without a token, parsing is off and users see an example sentence.
81
+ - **Testnets only** for now: Base Sepolia, OP Sepolia, Ethereum Sepolia and Polygon Amoy, with mock tokens.
82
+ - **The first swap of a token needs a one-time Permit2 approval.** The confirm card says so before it happens.
83
+ - **Requirements:** React 18+, and viem 2 as a peer dependency. wagmi is optional and only needed for `@recoilpay/intent-react/wagmi`.
package/dist/index.cjs ADDED
@@ -0,0 +1,381 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ RecoilIntent: () => RecoilIntent,
24
+ createIntentSession: () => import_intent_core2.createIntentSession,
25
+ useRecoilIntent: () => useRecoilIntent,
26
+ viemWallet: () => import_intent_core2.viemWallet
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/RecoilIntent.tsx
31
+ var import_react2 = require("react");
32
+
33
+ // src/icons.tsx
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var base = {
36
+ width: 16,
37
+ height: 16,
38
+ viewBox: "0 0 16 16",
39
+ fill: "none",
40
+ stroke: "currentColor",
41
+ strokeWidth: 1.5,
42
+ strokeLinecap: "round",
43
+ strokeLinejoin: "round",
44
+ "aria-hidden": true
45
+ };
46
+ var ArrowRight = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 8h10M9 4l4 4-4 4" }) });
47
+ var Check = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3.5 8.5l3 3 6-7" }) });
48
+ var Cross = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 4l8 8M12 4l-8 8" }) });
49
+ var Alert = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...base, children: [
50
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "8", cy: "8", r: "6" }),
51
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 5v3.5M8 11h.01" })
52
+ ] });
53
+ var Spinner = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...base, className: "rp-spin", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8 2a6 6 0 1 0 6 6" }) });
54
+ var Route = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { ...base, children: [
55
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "4", cy: "12", r: "1.5" }),
56
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "4", r: "1.5" }),
57
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5.5 12H10a2 2 0 0 0 0-4H6a2 2 0 0 1 0-4h4.5" })
58
+ ] });
59
+ var External = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { ...base, width: 12, height: 12, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 3H3v10h10v-3M9 3h4v4M13 3L7 9" }) });
60
+
61
+ // src/useRecoilIntent.ts
62
+ var import_intent_core = require("@recoilpay/intent-core");
63
+ var import_react = require("react");
64
+ function useRecoilIntent(options = {}) {
65
+ const [session] = (0, import_react.useState)(() => options.session ?? (0, import_intent_core.createIntentSession)({ apiUrl: options.apiUrl, hfAccessToken: options.hfAccessToken }));
66
+ const state = (0, import_react.useSyncExternalStore)(session.subscribe, session.getState, session.getState);
67
+ const wallet = options.wallet ?? null;
68
+ (0, import_react.useEffect)(() => session.setWallet(wallet), [session, wallet]);
69
+ const hfAccessToken = options.hfAccessToken;
70
+ (0, import_react.useEffect)(() => {
71
+ if (hfAccessToken !== void 0) session.setHfAccessToken(hfAccessToken);
72
+ }, [session, hfAccessToken]);
73
+ return { ...state, run: session.run, confirm: session.confirm, reset: session.reset, session };
74
+ }
75
+
76
+ // src/RecoilIntent.tsx
77
+ var import_jsx_runtime2 = require("react/jsx-runtime");
78
+ var DEFAULT_EXAMPLES = [
79
+ { label: "Swap 1 USDC from OP Sepolia to Base Sepolia", sentence: "swap 1 USDC on op sepolia for USDC on base sepolia" },
80
+ { label: "Swap 5 USDC from Base Sepolia to OP Sepolia", sentence: "swap 5 USDC on base sepolia for USDC on op sepolia" }
81
+ ];
82
+ var BUSY = ["switchingChain", "approving", "signing", "submitting"];
83
+ var CARD_PHASES = ["quoted", "needsWallet", ...BUSY];
84
+ function themeVars(theme = {}) {
85
+ const vars = {};
86
+ if (theme.accent) vars["--rp-accent"] = theme.accent;
87
+ if (theme.accentText) vars["--rp-accent-text"] = theme.accentText;
88
+ if (theme.radius !== void 0) vars["--rp-radius"] = `${theme.radius}px`;
89
+ if (theme.fontFamily) vars["--rp-font"] = theme.fontFamily;
90
+ return vars;
91
+ }
92
+ function RecoilIntent(props) {
93
+ const intent = useRecoilIntent({ apiUrl: props.apiUrl, session: props.session, wallet: props.wallet, hfAccessToken: props.hfAccessToken });
94
+ const [value, setValue] = (0, import_react2.useState)(props.defaultValue ?? "");
95
+ const examples = props.examples === false ? [] : props.examples ?? DEFAULT_EXAMPLES;
96
+ useLifecycleCallbacks(intent, props);
97
+ const submit = (sentence = value) => {
98
+ const text = sentence.trim();
99
+ if (text && intent.ready) void intent.run(text);
100
+ };
101
+ const startOver = () => {
102
+ intent.reset();
103
+ setValue("");
104
+ };
105
+ const connect = () => props.onConnectWallet?.();
106
+ const showCard = intent.preview && (CARD_PHASES.includes(intent.phase) || intent.phase === "error" && intent.route);
107
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: ["rp-root", props.className].filter(Boolean).join(" "), "data-mode": props.theme?.mode ?? "dark", style: themeVars(props.theme), children: [
108
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-composer", children: [
109
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-composer-head", children: [
110
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "rp-eyebrow", children: [
111
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": "true", children: "/" }),
112
+ "intent"
113
+ ] }),
114
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-powered", children: "RecoilPay" })
115
+ ] }),
116
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
117
+ "form",
118
+ {
119
+ className: "rp-composer-row",
120
+ onSubmit: (e) => {
121
+ e.preventDefault();
122
+ submit();
123
+ },
124
+ children: [
125
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
126
+ "input",
127
+ {
128
+ className: "rp-input",
129
+ value,
130
+ onChange: (e) => setValue(e.target.value),
131
+ placeholder: props.placeholder ?? "swap 1 USDC on OP Sepolia for USDC on Base Sepolia",
132
+ "aria-label": "Describe a swap or send",
133
+ autoComplete: "off",
134
+ spellCheck: false,
135
+ maxLength: 500
136
+ }
137
+ ),
138
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "submit", className: "rp-run", "aria-label": "Run intent", disabled: !intent.ready || !value.trim(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ArrowRight, {}) })
139
+ ]
140
+ }
141
+ ),
142
+ intent.phase === "idle" && examples.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-examples", children: [
143
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-examples-label", children: "try" }),
144
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-example-list", children: examples.map((ex) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
145
+ "button",
146
+ {
147
+ type: "button",
148
+ className: "rp-example",
149
+ disabled: !intent.ready,
150
+ onClick: () => {
151
+ setValue(ex.sentence);
152
+ submit(ex.sentence);
153
+ },
154
+ children: ex.label
155
+ },
156
+ ex.sentence
157
+ )) })
158
+ ] })
159
+ ] }),
160
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-results", "aria-live": "polite", children: [
161
+ intent.assetsError && intent.phase === "idle" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Note, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Alert, {}), children: [
162
+ "Could not reach the solver network.",
163
+ " ",
164
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "rp-link", onClick: () => void intent.session.refreshAssets(), children: "Retry" })
165
+ ] }),
166
+ intent.phase === "parsing" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Note, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spinner, {}), children: "Reading your intent\u2026" }),
167
+ intent.phase === "offTemplate" && intent.hint && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Note, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Alert, {}), children: intent.hint }),
168
+ intent.phase === "invalid" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "rp-issues", children: intent.issues.map((issue, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { children: [
169
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Alert, {}),
170
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: issue.message })
171
+ ] }, `${issue.field}-${i}`)) }),
172
+ intent.phase === "quoting" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Note, { icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Route, {}), tone: "accent", children: intent.queueTotal > 1 ? `Intent ${intent.queueIndex + 1} of ${intent.queueTotal}: asking solvers for a quote\u2026` : "Asking solvers for a quote\u2026" }),
173
+ intent.phase === "needsWallet" && !intent.preview && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-connect", children: [
174
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Connect a wallet to get a quote." }),
175
+ props.onConnectWallet && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "rp-button", onClick: connect, children: "Connect wallet" })
176
+ ] }),
177
+ intent.queueTotal > 1 && !["idle", "parsing", "offTemplate", "invalid"].includes(intent.phase) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-queue", children: [
178
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
179
+ "Intent ",
180
+ intent.queueIndex + 1,
181
+ " of ",
182
+ intent.queueTotal
183
+ ] }),
184
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-queue-track", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { width: `${(intent.queueIndex + (intent.phase === "done" ? 1 : 0)) / intent.queueTotal * 100}%` } }) })
185
+ ] }),
186
+ showCard && intent.preview && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
187
+ ConfirmCard,
188
+ {
189
+ preview: intent.preview,
190
+ phase: intent.phase,
191
+ needsApproval: intent.needsApproval,
192
+ isConnected: intent.isConnected,
193
+ direct: intent.route === "direct",
194
+ error: intent.phase === "error" ? intent.error : null,
195
+ onConfirm: () => void intent.confirm(),
196
+ onConnect: props.onConnectWallet ? connect : void 0,
197
+ onCancel: startOver
198
+ }
199
+ ),
200
+ (intent.phase === "tracking" || intent.phase === "done") && intent.orderId && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OrderProgress, { status: intent.status, direct: intent.route === "direct", explorerUrl: intent.explorerUrl, onNew: startOver }),
201
+ intent.phase === "error" && !intent.route && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-error", children: [
202
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: intent.error }),
203
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "rp-button rp-button-quiet", onClick: startOver, children: "Dismiss" })
204
+ ] })
205
+ ] })
206
+ ] });
207
+ }
208
+ function useLifecycleCallbacks(intent, props) {
209
+ const prev = (0, import_react2.useRef)(intent);
210
+ const cbs = (0, import_react2.useRef)(props);
211
+ cbs.current = props;
212
+ (0, import_react2.useEffect)(() => {
213
+ const before = prev.current;
214
+ prev.current = intent;
215
+ if (intent.orderId && intent.orderId !== before.orderId) cbs.current.onOrderSubmitted?.(intent.orderId);
216
+ if (intent.phase === "done" && before.phase !== "done") cbs.current.onComplete?.(intent);
217
+ if (intent.phase === "error" && before.phase !== "error" && intent.error) cbs.current.onError?.(intent.error);
218
+ }, [intent]);
219
+ }
220
+ function Note({ icon, tone = "muted", children }) {
221
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "rp-note", "data-tone": tone, children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-note-icon", children: icon }),
223
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children })
224
+ ] });
225
+ }
226
+ var shortAddr = (a) => a.length > 12 ? `${a.slice(0, 6)}\u2026${a.slice(-4)}` : a;
227
+ function actionLabel(phase, isConnected, needsApproval, symbol, direct) {
228
+ if (!isConnected || phase === "needsWallet") return "Connect wallet";
229
+ switch (phase) {
230
+ case "switchingChain":
231
+ return "Switching network\u2026";
232
+ case "approving":
233
+ return `Approving ${symbol}\u2026`;
234
+ case "signing":
235
+ return "Confirm in your wallet\u2026";
236
+ case "submitting":
237
+ return "Submitting\u2026";
238
+ case "error":
239
+ return "Try again";
240
+ default:
241
+ if (direct) return `Send ${symbol}`;
242
+ return needsApproval ? `Approve ${symbol} and swap` : "Confirm and sign";
243
+ }
244
+ }
245
+ function ConfirmCard(p) {
246
+ const busy = BUSY.includes(p.phase);
247
+ const send = p.preview.action === "send";
248
+ const wantsWallet = !p.isConnected || p.phase === "needsWallet";
249
+ const { solverCount, solversQueried } = p.preview;
250
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-card", children: [
251
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-card-head", children: [
252
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
253
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-overline", children: "Review" }),
254
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-card-title", children: p.direct ? "Direct transfer" : "Best solver route" })
255
+ ] }),
256
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "rp-badge", children: [
257
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Check, {}),
258
+ " Quoted"
259
+ ] })
260
+ ] }),
261
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-route", children: [
262
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Amount, { label: send ? "You send" : "You pay", amount: p.preview.payAmount, symbol: p.preview.paySymbol, chain: p.preview.srcChainName }),
263
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-route-arrow", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ArrowRight, {}) }),
264
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
265
+ Amount,
266
+ {
267
+ align: "end",
268
+ label: send ? "They receive" : "You receive",
269
+ amount: p.direct ? p.preview.receiveAmount : `~${p.preview.receiveAmount}`,
270
+ symbol: p.preview.receiveSymbol,
271
+ chain: p.preview.dstChainName
272
+ }
273
+ )
274
+ ] }),
275
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("dl", { className: "rp-meta", children: [
276
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
277
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: "Settles in" }),
278
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { children: p.preview.etaSeconds ? `~${p.preview.etaSeconds}s` : "Fast" })
279
+ ] }),
280
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
281
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: p.direct ? "Route" : "Solvers" }),
282
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { "data-accent": true, children: p.direct ? "Your wallet" : solversQueried && solversQueried > solverCount ? `${solverCount} of ${solversQueried} quoted` : `${solverCount} quoted` })
283
+ ] }),
284
+ send && p.preview.recipient && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
285
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dt", { children: "Recipient" }),
286
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("dd", { className: "rp-mono", children: shortAddr(p.preview.recipient) })
287
+ ] })
288
+ ] }),
289
+ p.needsApproval && !busy && !wantsWallet && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "rp-fineprint", children: [
290
+ "First time with ",
291
+ p.preview.paySymbol,
292
+ ": your wallet will ask for a one-time approval, then a signature."
293
+ ] }),
294
+ p.error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "rp-card-error", children: p.error }),
295
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-card-actions", children: [
296
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
297
+ "button",
298
+ {
299
+ type: "button",
300
+ className: "rp-button",
301
+ disabled: busy || wantsWallet && !p.onConnect,
302
+ onClick: wantsWallet ? p.onConnect : p.onConfirm,
303
+ children: [
304
+ busy && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spinner, {}),
305
+ actionLabel(p.phase, p.isConnected, p.needsApproval, p.preview.paySymbol, p.direct)
306
+ ]
307
+ }
308
+ ),
309
+ !busy && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "rp-link", onClick: p.onCancel, children: "Cancel" })
310
+ ] })
311
+ ] });
312
+ }
313
+ function Amount({ label, amount, symbol, chain, align = "start" }) {
314
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-amount", "data-align": align, children: [
315
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-overline", children: label }),
316
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-amount-value", children: [
317
+ amount,
318
+ " ",
319
+ symbol
320
+ ] }),
321
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-amount-chain", children: [
322
+ "on ",
323
+ chain
324
+ ] })
325
+ ] });
326
+ }
327
+ var STEPS = ["Submitted", "Filling", "Filled", "Settling", "Done"];
328
+ function stepOf(status) {
329
+ switch (status) {
330
+ case "executing":
331
+ return 1;
332
+ case "executed":
333
+ return 2;
334
+ case "settled":
335
+ case "settling":
336
+ return 3;
337
+ case "finalized":
338
+ return 4;
339
+ default:
340
+ return 0;
341
+ }
342
+ }
343
+ function OrderProgress({ status, direct, explorerUrl, onNew }) {
344
+ const failed = !!status && typeof status === "object" && "failed" in status;
345
+ const refunded = status === "refunded";
346
+ const finished = status === "finalized";
347
+ const active = stepOf(status);
348
+ const title = failed ? "Order failed" : refunded ? "Refunded" : finished ? direct ? "Sent" : "Settled" : "Settling\u2026";
349
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-card", "data-state": failed || refunded ? "bad" : finished ? "good" : "pending", children: [
350
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "rp-card-head", children: [
351
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-card-title", children: title }),
352
+ explorerUrl && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("a", { className: "rp-link", href: explorerUrl, target: "_blank", rel: "noopener noreferrer", children: [
353
+ "View on explorer ",
354
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(External, {})
355
+ ] })
356
+ ] }),
357
+ !direct && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ol", { className: "rp-steps", children: STEPS.map((label, i) => {
358
+ const state = failed || refunded ? "bad" : i < active || finished ? "done" : i === active ? "current" : "todo";
359
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { "data-state": state, children: [
360
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-step-dot", children: state === "bad" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Cross, {}) : state === "done" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Check, {}) : state === "current" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spinner, {}) : null }),
361
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "rp-step-label", children: label })
362
+ ] }, label);
363
+ }) }),
364
+ failed && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "rp-card-error", children: [
365
+ status.failed[0],
366
+ ": ",
367
+ status.failed[1]
368
+ ] }),
369
+ (finished || failed || refunded) && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rp-card-actions", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "rp-button rp-button-quiet", onClick: onNew, children: "New intent" }) })
370
+ ] });
371
+ }
372
+
373
+ // src/index.ts
374
+ var import_intent_core2 = require("@recoilpay/intent-core");
375
+ // Annotate the CommonJS export names for ESM import in node:
376
+ 0 && (module.exports = {
377
+ RecoilIntent,
378
+ createIntentSession,
379
+ useRecoilIntent,
380
+ viemWallet
381
+ });
@@ -0,0 +1,77 @@
1
+ import * as react from 'react';
2
+ import { IntentSession, IntentWallet, IntentState } from '@recoilpay/intent-core';
3
+ export { IntentPhase, IntentPreview, IntentSession, IntentState, IntentWallet, createIntentSession, viemWallet } from '@recoilpay/intent-core';
4
+
5
+ interface RecoilTheme {
6
+ /** Default `dark`. */
7
+ mode?: 'dark' | 'light';
8
+ /** Buttons, focus ring and highlights. Default RecoilPay violet. */
9
+ accent?: string;
10
+ /** Text colour on accent-filled buttons. */
11
+ accentText?: string;
12
+ /** Corner radius of cards and the composer, in px. Default 12. */
13
+ radius?: number;
14
+ /** Default: inherit the host page's font. */
15
+ fontFamily?: string;
16
+ }
17
+ interface IntentExample {
18
+ label: string;
19
+ sentence: string;
20
+ }
21
+ interface RecoilIntentProps {
22
+ /** Aggregator base URL. Defaults to production. */
23
+ apiUrl?: string;
24
+ /** Share a session with other components, or inject one in tests. */
25
+ session?: IntentSession;
26
+ /** The connected wallet, or null. With wagmi, use `useWagmiIntentWallet()`. */
27
+ wallet?: IntentWallet | null;
28
+ /** Your Hugging Face access token for plain-English parsing (visible in the page; use an inference-only token). */
29
+ hfAccessToken?: string | null;
30
+ /** Open your app's wallet connect flow. Shown when a wallet is needed. */
31
+ onConnectWallet?: () => void;
32
+ /** Suggestions under the field. `false` hides them. */
33
+ examples?: IntentExample[] | false;
34
+ placeholder?: string;
35
+ /** Pre-fill the field (it isn't submitted until the user runs it). */
36
+ defaultValue?: string;
37
+ theme?: RecoilTheme;
38
+ className?: string;
39
+ onOrderSubmitted?: (orderId: string) => void;
40
+ /** Every intent in the sentence reached a final status. */
41
+ onComplete?: (state: IntentState) => void;
42
+ onError?: (message: string) => void;
43
+ }
44
+ /**
45
+ * RecoilPay intents in one component: the user types what they want, sees
46
+ * the best solver quote, confirms in their wallet, and watches it settle.
47
+ * Import `@recoilpay/intent-react/styles.css` once.
48
+ */
49
+ declare function RecoilIntent(props: RecoilIntentProps): react.JSX.Element;
50
+
51
+ interface UseRecoilIntentOptions {
52
+ /** Aggregator base URL. Defaults to production. Read once, on first render. */
53
+ apiUrl?: string;
54
+ /** Bring your own session (shared across components, or for tests). */
55
+ session?: IntentSession;
56
+ /** The connected wallet, or null. Changes are passed straight to the session. */
57
+ wallet?: IntentWallet | null;
58
+ /**
59
+ * Your Hugging Face access token for plain-English parsing. It runs in the
60
+ * browser, so it's visible in your page: use a dedicated inference-only
61
+ * token. Without one, users see the example-sentence hint.
62
+ */
63
+ hfAccessToken?: string | null;
64
+ }
65
+ interface UseRecoilIntent extends IntentState {
66
+ run: (text: string) => Promise<void>;
67
+ confirm: () => Promise<void>;
68
+ reset: () => void;
69
+ session: IntentSession;
70
+ }
71
+ /**
72
+ * The intent flow as React state. Renders nothing: build your own UI on it,
73
+ * or use `<RecoilIntent />`, which is built on this.
74
+ */
75
+ declare function useRecoilIntent(options?: UseRecoilIntentOptions): UseRecoilIntent;
76
+
77
+ export { type IntentExample, RecoilIntent, type RecoilIntentProps, type RecoilTheme, type UseRecoilIntent, type UseRecoilIntentOptions, useRecoilIntent };
@@ -0,0 +1,77 @@
1
+ import * as react from 'react';
2
+ import { IntentSession, IntentWallet, IntentState } from '@recoilpay/intent-core';
3
+ export { IntentPhase, IntentPreview, IntentSession, IntentState, IntentWallet, createIntentSession, viemWallet } from '@recoilpay/intent-core';
4
+
5
+ interface RecoilTheme {
6
+ /** Default `dark`. */
7
+ mode?: 'dark' | 'light';
8
+ /** Buttons, focus ring and highlights. Default RecoilPay violet. */
9
+ accent?: string;
10
+ /** Text colour on accent-filled buttons. */
11
+ accentText?: string;
12
+ /** Corner radius of cards and the composer, in px. Default 12. */
13
+ radius?: number;
14
+ /** Default: inherit the host page's font. */
15
+ fontFamily?: string;
16
+ }
17
+ interface IntentExample {
18
+ label: string;
19
+ sentence: string;
20
+ }
21
+ interface RecoilIntentProps {
22
+ /** Aggregator base URL. Defaults to production. */
23
+ apiUrl?: string;
24
+ /** Share a session with other components, or inject one in tests. */
25
+ session?: IntentSession;
26
+ /** The connected wallet, or null. With wagmi, use `useWagmiIntentWallet()`. */
27
+ wallet?: IntentWallet | null;
28
+ /** Your Hugging Face access token for plain-English parsing (visible in the page; use an inference-only token). */
29
+ hfAccessToken?: string | null;
30
+ /** Open your app's wallet connect flow. Shown when a wallet is needed. */
31
+ onConnectWallet?: () => void;
32
+ /** Suggestions under the field. `false` hides them. */
33
+ examples?: IntentExample[] | false;
34
+ placeholder?: string;
35
+ /** Pre-fill the field (it isn't submitted until the user runs it). */
36
+ defaultValue?: string;
37
+ theme?: RecoilTheme;
38
+ className?: string;
39
+ onOrderSubmitted?: (orderId: string) => void;
40
+ /** Every intent in the sentence reached a final status. */
41
+ onComplete?: (state: IntentState) => void;
42
+ onError?: (message: string) => void;
43
+ }
44
+ /**
45
+ * RecoilPay intents in one component: the user types what they want, sees
46
+ * the best solver quote, confirms in their wallet, and watches it settle.
47
+ * Import `@recoilpay/intent-react/styles.css` once.
48
+ */
49
+ declare function RecoilIntent(props: RecoilIntentProps): react.JSX.Element;
50
+
51
+ interface UseRecoilIntentOptions {
52
+ /** Aggregator base URL. Defaults to production. Read once, on first render. */
53
+ apiUrl?: string;
54
+ /** Bring your own session (shared across components, or for tests). */
55
+ session?: IntentSession;
56
+ /** The connected wallet, or null. Changes are passed straight to the session. */
57
+ wallet?: IntentWallet | null;
58
+ /**
59
+ * Your Hugging Face access token for plain-English parsing. It runs in the
60
+ * browser, so it's visible in your page: use a dedicated inference-only
61
+ * token. Without one, users see the example-sentence hint.
62
+ */
63
+ hfAccessToken?: string | null;
64
+ }
65
+ interface UseRecoilIntent extends IntentState {
66
+ run: (text: string) => Promise<void>;
67
+ confirm: () => Promise<void>;
68
+ reset: () => void;
69
+ session: IntentSession;
70
+ }
71
+ /**
72
+ * The intent flow as React state. Renders nothing: build your own UI on it,
73
+ * or use `<RecoilIntent />`, which is built on this.
74
+ */
75
+ declare function useRecoilIntent(options?: UseRecoilIntentOptions): UseRecoilIntent;
76
+
77
+ export { type IntentExample, RecoilIntent, type RecoilIntentProps, type RecoilTheme, type UseRecoilIntent, type UseRecoilIntentOptions, useRecoilIntent };