@lombard.finance/sdk-devtools 0.1.0-canary.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 ADDED
@@ -0,0 +1,344 @@
1
+ # @lombard.finance/sdk-devtools
2
+
3
+ Developer tools for the Lombard SDK. Provides debugging, inspection, and testing utilities for developers integrating with the Lombard protocol.
4
+
5
+ ## How It Works
6
+
7
+ The SDK DevTools automatically hooks into SDK actions to collect events and state:
8
+
9
+ ```
10
+ ┌─────────────────────────────────────────────────────────────────────────────┐
11
+ │ YOUR APP │
12
+ ├─────────────────────────────────────────────────────────────────────────────┤
13
+ │ │
14
+ │ ┌─────────────────────┐ ┌─────────────────────┐ │
15
+ │ │ Lombard SDK │ │ DevTools │ │
16
+ │ │ │ │ │ │
17
+ │ │ const stake = sdk │───────▶│ Automatically │ │
18
+ │ │ .btc.stake(...) │ events │ collects events, │ │
19
+ │ │ │ │ tracks status │ │
20
+ │ └─────────────────────┘ └──────────┬──────────┘ │
21
+ │ │ │
22
+ │ ▼ │
23
+ │ ┌─────────────────────────┐ │
24
+ │ │ DevToolsPanel │ │
25
+ │ │ (Visual debugger) │ │
26
+ │ └─────────────────────────┘ │
27
+ │ │
28
+ └─────────────────────────────────────────────────────────────────────────────┘
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ yarn add @lombard.finance/sdk-devtools
35
+ # or
36
+ npm install @lombard.finance/sdk-devtools
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 1. Wrap Your App with DevToolsProvider
42
+
43
+ ```tsx
44
+ import { DevToolsProvider } from '@lombard.finance/sdk-devtools';
45
+
46
+ function App() {
47
+ return (
48
+ <DevToolsProvider enabled={process.env.NODE_ENV !== 'production'}>
49
+ <MyApp />
50
+ </DevToolsProvider>
51
+ );
52
+ }
53
+ ```
54
+
55
+ ### 2. Register SDK Actions
56
+
57
+ ```tsx
58
+ import { useDevToolsContext } from '@lombard.finance/sdk-devtools';
59
+ import { createLombardSDK, Chain, AssetId } from '@lombard.finance/sdk';
60
+
61
+ function StakeComponent() {
62
+ const { registerAction } = useDevToolsContext();
63
+ const [stake, setStake] = useState(null);
64
+
65
+ // Create and register the action
66
+ useEffect(() => {
67
+ async function init() {
68
+ const sdk = await createLombardSDK({
69
+ env: 'testnet',
70
+ providers: { evm: () => window.ethereum },
71
+ });
72
+
73
+ const action = sdk.btc.stake({
74
+ destChain: Chain.ETHEREUM,
75
+ assetOut: AssetId.LBTC,
76
+ });
77
+
78
+ // Register with DevTools - events are now collected automatically!
79
+ const unregister = registerAction('btc-stake', action, {
80
+ category: 'btc',
81
+ });
82
+
83
+ setStake(action);
84
+
85
+ return unregister;
86
+ }
87
+
88
+ init();
89
+ }, [registerAction]);
90
+
91
+ // Use the action normally
92
+ async function handleStake() {
93
+ await stake.prepare({ amount: '0.001', recipient: '0x...' });
94
+ await stake.authorize();
95
+ const address = await stake.generateDepositAddress();
96
+ console.log('Deposit to:', address);
97
+ }
98
+
99
+ return <button onClick={handleStake}>Stake BTC</button>;
100
+ }
101
+ ```
102
+
103
+ ### 3. Display DevTools Panel
104
+
105
+ ```tsx
106
+ import { DevToolsPanel, useDevToolsContext } from '@lombard.finance/sdk-devtools';
107
+
108
+ function DebugPanel() {
109
+ const { events, clearEvents, actions } = useDevToolsContext();
110
+
111
+ // Get state summary for all registered actions
112
+ const stateSummary = useMemo(() => {
113
+ const summary = {};
114
+ actions.forEach((reg, name) => {
115
+ summary[name] = {
116
+ status: reg.action.status,
117
+ isLoading: reg.action.isLoading,
118
+ };
119
+ });
120
+ return summary;
121
+ }, [actions]);
122
+
123
+ return (
124
+ <DevToolsPanel
125
+ events={events}
126
+ onClearEvents={clearEvents}
127
+ state={stateSummary}
128
+ />
129
+ );
130
+ }
131
+ ```
132
+
133
+ ## Alternative: Without Provider
134
+
135
+ For simpler setups or non-React apps, use the bridge directly:
136
+
137
+ ```tsx
138
+ import { DevToolsBridge, DevToolsPanel } from '@lombard.finance/sdk-devtools';
139
+
140
+ // Create bridge
141
+ const bridge = new DevToolsBridge({ consoleLogging: true });
142
+
143
+ // Register action
144
+ const stake = sdk.btc.stake({ ... });
145
+ const unregister = bridge.registerAction('stake', stake);
146
+
147
+ // Get events for display
148
+ const events = bridge.getEvents();
149
+
150
+ // In React:
151
+ function DebugView() {
152
+ const [events, setEvents] = useState([]);
153
+
154
+ useEffect(() => {
155
+ return bridge.onEvent(() => {
156
+ setEvents(bridge.getEvents());
157
+ });
158
+ }, []);
159
+
160
+ return (
161
+ <DevToolsPanel
162
+ events={events}
163
+ onClearEvents={() => bridge.clearEvents()}
164
+ />
165
+ );
166
+ }
167
+ ```
168
+
169
+ ## Using Hook for Single Action
170
+
171
+ For monitoring a single action with full state:
172
+
173
+ ```tsx
174
+ import { useActionEvents } from '@lombard.finance/sdk-devtools';
175
+
176
+ function StakeProgress({ action }) {
177
+ const { events, status, isLoading, error, isFailed } = useActionEvents(action);
178
+
179
+ return (
180
+ <div>
181
+ <StatusBadge status={status} />
182
+ {isLoading && <Spinner />}
183
+ {isFailed && <Error message={error.message} />}
184
+ <EventLog events={events} onClear={() => {}} />
185
+ </div>
186
+ );
187
+ }
188
+ ```
189
+
190
+ ## Components
191
+
192
+ ### DevToolsPanel
193
+
194
+ Full debug panel with tabs for events, actions, and state:
195
+
196
+ ```tsx
197
+ <DevToolsPanel
198
+ events={events}
199
+ onClearEvents={clearEvents}
200
+ reducerLogs={logs} // Optional: Redux-style action log
201
+ onClearReducerLogs={clearLogs} // Optional
202
+ state={{ status: 'ready' }} // Optional: State to inspect
203
+ initialTab="events" // Optional: 'events' | 'reducer' | 'state'
204
+ title="SDK Debug" // Optional
205
+ />
206
+ ```
207
+
208
+ ### Individual Components
209
+
210
+ ```tsx
211
+ import {
212
+ EventLog,
213
+ StateInspector,
214
+ StatusBadge,
215
+ StepIndicator,
216
+ createSteps,
217
+ } from '@lombard.finance/sdk-devtools';
218
+
219
+ // Status Badge
220
+ <StatusBadge status="needs_fee_authorization" />
221
+
222
+ // Step Indicator
223
+ const steps = [
224
+ { id: 'create', label: 'Create' },
225
+ { id: 'prepare', label: 'Prepare' },
226
+ { id: 'authorize', label: 'Authorize' },
227
+ { id: 'execute', label: 'Execute' },
228
+ ];
229
+
230
+ <StepIndicator
231
+ steps={createSteps(steps, currentStep)}
232
+ currentStep={currentStep}
233
+ />
234
+
235
+ // Event Log (standalone)
236
+ <EventLog events={events} onClear={clearEvents} />
237
+
238
+ // State Inspector (JSON tree viewer)
239
+ <StateInspector state={{ amount: '0.001' }} title="Transaction" />
240
+ ```
241
+
242
+ ## Mock Wallet
243
+
244
+ Test flows without connecting a real wallet:
245
+
246
+ ```tsx
247
+ import { useMockWallet, MOCK_ADDRESSES } from '@lombard.finance/sdk-devtools';
248
+
249
+ function WalletSection() {
250
+ const mockWallet = useMockWallet();
251
+
252
+ return (
253
+ <div>
254
+ {!mockWallet.isEnabled ? (
255
+ <button onClick={mockWallet.enable}>Use Mock Wallet</button>
256
+ ) : (
257
+ <div>
258
+ <p>Mock Address: {mockWallet.address}</p>
259
+ <p>⚠️ Cannot sign transactions</p>
260
+ <button onClick={mockWallet.disable}>Disable Mock</button>
261
+ </div>
262
+ )}
263
+ </div>
264
+ );
265
+ }
266
+
267
+ // Available mock addresses
268
+ console.log(MOCK_ADDRESSES.evm); // 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
269
+ console.log(MOCK_ADDRESSES.bitcoin); // bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh
270
+ console.log(MOCK_ADDRESSES.solana); // DRpbCBMxVnDK7maPMxTm9dRYNLGhPEYALmJY9VvUdWTm
271
+ ```
272
+
273
+ ## SDK Events Collected
274
+
275
+ The bridge automatically subscribes to these SDK events:
276
+
277
+ | Event | Description |
278
+ |-------|-------------|
279
+ | `status-change` | Action status changed (e.g., `idle` → `needs_fee_authorization`) |
280
+ | `loading` | Loading state changed |
281
+ | `error` | An error occurred |
282
+ | `completed` | Action completed successfully |
283
+ | `failed` | Action failed |
284
+ | `progress` | Progress update with step details |
285
+
286
+ ## API Reference
287
+
288
+ ### Provider
289
+
290
+ | Export | Description |
291
+ |--------|-------------|
292
+ | `DevToolsProvider` | React context provider |
293
+ | `useDevToolsContext` | Hook to access DevTools context |
294
+ | `useRegisterAction` | Hook to register an action |
295
+
296
+ ### Bridge
297
+
298
+ | Export | Description |
299
+ |--------|-------------|
300
+ | `DevToolsBridge` | Core bridge class |
301
+ | `getDevToolsBridge` | Get global singleton bridge |
302
+ | `resetDevToolsBridge` | Reset global bridge |
303
+
304
+ ### Hooks
305
+
306
+ | Hook | Description |
307
+ |------|-------------|
308
+ | `useDevTools` | Full DevTools state and methods |
309
+ | `useMonitoredAction` | Create and auto-register an action |
310
+ | `useActionEvents` | Subscribe to events from a single action |
311
+ | `useMockWallet` | Mock wallet for testing |
312
+
313
+ ### Components
314
+
315
+ | Component | Description |
316
+ |-----------|-------------|
317
+ | `DevToolsPanel` | Full tabbed debug panel |
318
+ | `EventLog` | SDK event stream |
319
+ | `ReducerLog` | Redux-style action log |
320
+ | `StateInspector` | JSON tree viewer |
321
+ | `StatusBadge` | Status indicator |
322
+ | `StepIndicator` | Progress steps |
323
+
324
+ ## Styling
325
+
326
+ Components use Tailwind CSS classes. For best results, ensure Tailwind is configured in your project. Components support dark mode via `dark:` prefix classes.
327
+
328
+ ## Production
329
+
330
+ DevTools is automatically disabled in production when using `DevToolsProvider`:
331
+
332
+ ```tsx
333
+ <DevToolsProvider enabled={process.env.NODE_ENV !== 'production'}>
334
+ ```
335
+
336
+ Or disable manually:
337
+
338
+ ```tsx
339
+ <DevToolsProvider enabled={false}>
340
+ ```
341
+
342
+ ## License
343
+
344
+ MIT