router-widget-sdk 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/README.md +928 -63
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,23 @@
1
- # router-widget-sdk
1
+ # Router Widget SDK
2
2
 
3
- Router Protocol Widget - A React component for cross-chain swaps that can be embedded in any React application.
3
+ A production-ready React component for cross-chain swaps that can be embedded in any React application. Supports EVM chains, Solana, Bitcoin, and Sui with flexible wallet integration options.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Quick Start](#quick-start)
9
+ - [Wallet Integration](#wallet-integration)
10
+ - [Internal Wallet Mode (Default)](#internal-wallet-mode-default)
11
+ - [External Wallet Mode (Dynamic.xyz)](#external-wallet-mode-dynamicxyz)
12
+ - [Solana Support](#solana-support)
13
+ - [Configuration](#configuration)
14
+ - [Advanced Usage](#advanced-usage)
15
+ - [API Reference](#api-reference)
16
+ - [Examples](#examples)
17
+ - [TypeScript Support](#typescript-support)
18
+ - [Styling](#styling)
19
+ - [Environment Variables](#environment-variables)
20
+ - [Browser Support](#browser-support)
4
21
 
5
22
  ## Installation
6
23
 
@@ -12,8 +29,18 @@ pnpm add router-widget-sdk
12
29
  yarn add router-widget-sdk
13
30
  ```
14
31
 
32
+ ### Peer Dependencies
33
+
34
+ The SDK requires React 18.3.1 or higher:
35
+
36
+ ```bash
37
+ npm install react@^18.3.1 react-dom@^18.3.1
38
+ ```
39
+
15
40
  ## Quick Start
16
41
 
42
+ ### Basic Usage
43
+
17
44
  ```tsx
18
45
  import { RouterWidget } from 'router-widget-sdk';
19
46
  import 'router-widget-sdk/styles.css';
@@ -30,115 +57,807 @@ function App() {
30
57
  }
31
58
  ```
32
59
 
33
- ## Configuration
60
+ ### With Initial State
34
61
 
35
- ### Basic Usage
62
+ ```tsx
63
+ <RouterWidget
64
+ config={{
65
+ initialState: {
66
+ fromChainId: '1', // Ethereum
67
+ fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
68
+ toChainId: '137', // Polygon
69
+ toTokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
70
+ },
71
+ theme: { mode: 'dark' },
72
+ integrator: 'MyDApp',
73
+ }}
74
+ />
75
+ ```
76
+
77
+ ## Wallet Integration
78
+
79
+ The SDK supports multiple wallet integration modes:
80
+
81
+ ### Internal Wallet Mode (Default)
82
+
83
+ By default, the SDK provides its own wallet connection infrastructure:
84
+
85
+ - **EVM Chains**: Uses Wagmi with AppKit for wallet connection
86
+ - **Solana**: Uses `@solana/wallet-adapter-react` with built-in adapters
87
+ - **Bitcoin/Sui**: Placeholder support (external providers required)
88
+
89
+ ```tsx
90
+ // No additional setup needed - SDK handles everything
91
+ <RouterWidget config={{ theme: { mode: 'dark' } }} />
92
+ ```
93
+
94
+ The SDK will:
95
+ - Show its own wallet connection modal
96
+ - Support all EVM wallets (MetaMask, WalletConnect, Coinbase, etc.)
97
+ - Support Solana wallets (Phantom, Solflare, Coinbase Wallet, etc.)
98
+ - Handle wallet connection/disconnection automatically
99
+
100
+ ### External Wallet Mode (Dynamic.xyz)
101
+
102
+ If your app already uses Dynamic.xyz or another wallet provider, the SDK will automatically detect and use it:
36
103
 
37
104
  ```tsx
105
+ import { DynamicContextProvider } from '@dynamic-labs/sdk-react-core';
106
+ import { EthereumWalletConnectors } from '@dynamic-labs/ethereum';
107
+ import { SolanaWalletConnectors } from '@dynamic-labs/solana';
108
+ import { DynamicWagmiConnector } from '@dynamic-labs/wagmi-connector';
109
+ import { WagmiProvider } from 'wagmi';
38
110
  import { RouterWidget } from 'router-widget-sdk';
39
- import 'router-widget-sdk/styles.css';
40
111
 
41
112
  function App() {
42
113
  return (
114
+ <DynamicContextProvider
115
+ settings={{
116
+ environmentId: 'your-dynamic-env-id',
117
+ walletConnectors: [
118
+ EthereumWalletConnectors,
119
+ SolanaWalletConnectors,
120
+ ],
121
+ }}
122
+ >
123
+ <WagmiProvider config={wagmiConfig}>
124
+ <DynamicWagmiConnector>
43
125
  <RouterWidget
44
126
  config={{
45
- theme: {
46
- mode: 'dark', // 'light' | 'dark' | 'auto'
47
- primaryColor: '#e4357a',
48
- backgroundColor: '#0a0a0a',
49
- },
50
- integrator: 'MyDApp',
51
- }}
52
- />
127
+ theme: { mode: 'dark' },
128
+ wallet: {
129
+ onConnectClick: () => {
130
+ // Open Dynamic's auth flow
131
+ setShowAuthFlow(true);
132
+ },
133
+ },
134
+ }}
135
+ />
136
+ </DynamicWagmiConnector>
137
+ </WagmiProvider>
138
+ </DynamicContextProvider>
53
139
  );
54
140
  }
55
141
  ```
56
142
 
57
- ### With Initial State
143
+ **How it works:**
144
+ - SDK detects external Wagmi context → hides internal wallet modal
145
+ - SDK detects external Solana context → uses external Solana adapter
146
+ - `onConnectClick` callback opens your wallet connection UI
147
+ - SDK uses your wallet for all transactions
58
148
 
149
+ See [examples/nextjs-dynamic-provider](./examples/nextjs-dynamic-provider) for a complete example.
150
+
151
+ ### Solana Support
152
+
153
+ The SDK includes full Solana wallet support:
154
+
155
+ #### Internal Solana Mode
156
+
157
+ ```tsx
158
+ // SDK automatically provides Solana wallet infrastructure
159
+ <RouterWidget config={{ theme: { mode: 'dark' } }} />
160
+ ```
161
+
162
+ Supported wallets:
163
+ - Phantom
164
+ - Solflare
165
+ - Coinbase Wallet
166
+ - Any Wallet Standard-compatible wallet
167
+
168
+ #### External Solana Mode (with Dynamic)
169
+
170
+ ```tsx
171
+ import { SolanaProvider } from './components/SolanaProvider';
172
+ import { DynamicSolanaProvider } from './components/DynamicSolanaProvider';
173
+
174
+ // In your providers setup
175
+ <ConnectionProvider endpoint={endpoint}>
176
+ <WalletProvider wallets={[]} autoConnect>
177
+ <DynamicSolanaProvider>
178
+ <RouterWidget config={{ theme: { mode: 'dark' } }} />
179
+ </DynamicSolanaProvider>
180
+ </WalletProvider>
181
+ </ConnectionProvider>
182
+ ```
183
+
184
+ The SDK will:
185
+ - Detect external Solana context
186
+ - Use Dynamic's Solana wallet for transactions
187
+ - Automatically switch between EVM and Solana as needed
188
+
189
+ ## Configuration
190
+
191
+ ### Component Props
192
+
193
+ #### `RouterWidget`
194
+
195
+ The main widget component accepts a single prop:
196
+
197
+ ```typescript
198
+ interface RouterWidgetProps {
199
+ /**
200
+ * Widget configuration object
201
+ * All properties are optional
202
+ */
203
+ config?: WidgetConfig;
204
+ }
205
+ ```
206
+
207
+ **Example:**
208
+ ```tsx
209
+ <RouterWidget config={widgetConfig} />
210
+ ```
211
+
212
+ ### WidgetConfig Interface
213
+
214
+ Complete configuration interface with all available options:
215
+
216
+ ```typescript
217
+ interface WidgetConfig {
218
+ // Theme configuration
219
+ theme?: WidgetTheme;
220
+
221
+ // Initial swap state
222
+ initialState?: InitialState;
223
+
224
+ // Integrator identifier
225
+ integrator?: string;
226
+
227
+ // Feature flags
228
+ features?: FeatureFlags;
229
+
230
+ // Selected routing nodes
231
+ selectedNodes?: string[];
232
+
233
+ // Wallet integration
234
+ wallet?: WalletConfig;
235
+
236
+ // Widget mode flag
237
+ isWidget?: boolean;
238
+
239
+ // Chain type restrictions
240
+ chains?: ChainConfig;
241
+
242
+ // Custom wallet providers (advanced)
243
+ providers?: any[];
244
+ }
245
+ ```
246
+
247
+ ### WidgetTheme
248
+
249
+ Theme configuration options:
250
+
251
+ ```typescript
252
+ interface WidgetTheme {
253
+ /**
254
+ * Theme mode
255
+ * - 'light': Light theme
256
+ * - 'dark': Dark theme (default)
257
+ * - 'auto': Follows system preference
258
+ *
259
+ * @default 'dark'
260
+ */
261
+ mode?: 'light' | 'dark' | 'auto';
262
+
263
+ /**
264
+ * Primary accent color (hex format)
265
+ * Used for buttons, links, and highlights
266
+ *
267
+ * @example '#e4357a'
268
+ */
269
+ primaryColor?: string;
270
+
271
+ /**
272
+ * Background color (hex format)
273
+ * Main background color for the widget
274
+ *
275
+ * @example '#0a0a0a'
276
+ */
277
+ backgroundColor?: string;
278
+
279
+ /**
280
+ * Primary text color (hex format)
281
+ * Main text color for content
282
+ *
283
+ * @example '#ffffff'
284
+ */
285
+ textColorPrimary?: string;
286
+
287
+ /**
288
+ * Secondary text color (hex format)
289
+ * Used for labels, hints, and less important text
290
+ *
291
+ * @example '#a0a0a0'
292
+ */
293
+ textColorSecondary?: string;
294
+
295
+ /**
296
+ * Muted background color (hex format)
297
+ * Used for cards, inputs, and secondary backgrounds
298
+ *
299
+ * @example '#1a1a1a'
300
+ */
301
+ mutedColor?: string;
302
+
303
+ /**
304
+ * Card border radius (CSS value)
305
+ * Only applied when isWidget: true
306
+ *
307
+ * @example '10px' | '0.5rem' | '0'
308
+ */
309
+ cardBorderRadius?: string;
310
+
311
+ /**
312
+ * Button border radius (CSS value)
313
+ * Applied to all buttons in the widget
314
+ *
315
+ * @example '4px' | '0.25rem' | '0'
316
+ */
317
+ buttonBorderRadius?: string;
318
+
319
+ /**
320
+ * Font family (CSS font-family value)
321
+ * Applied to all text in the widget
322
+ *
323
+ * @example 'Inter, sans-serif' | 'system-ui'
324
+ */
325
+ fontFamily?: string;
326
+ }
327
+ ```
328
+
329
+ **Example:**
330
+ ```tsx
331
+ <RouterWidget
332
+ config={{
333
+ theme: {
334
+ mode: 'dark',
335
+ primaryColor: '#e4357a',
336
+ backgroundColor: '#0a0a0a',
337
+ textColorPrimary: '#ffffff',
338
+ textColorSecondary: '#a0a0a0',
339
+ mutedColor: '#1a1a1a',
340
+ cardBorderRadius: '10px', // Only applied when isWidget: true
341
+ buttonBorderRadius: '4px',
342
+ fontFamily: 'Inter, sans-serif',
343
+ },
344
+ }}
345
+ />
346
+ ```
347
+
348
+ ### InitialState
349
+
350
+ Pre-configure the swap interface with initial values:
351
+
352
+ ```typescript
353
+ interface InitialState {
354
+ /**
355
+ * Source chain ID
356
+ * Chain ID of the source chain (e.g., '1' for Ethereum, '137' for Polygon)
357
+ *
358
+ * @example '1' | '137' | '8453'
359
+ */
360
+ fromChainId?: string;
361
+
362
+ /**
363
+ * Source token address
364
+ * Contract address of the source token
365
+ * Use 'native' or '0x0000000000000000000000000000000000000000' for native token
366
+ *
367
+ * @example '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' (USDC)
368
+ */
369
+ fromTokenAddress?: string;
370
+
371
+ /**
372
+ * Destination chain ID
373
+ * Chain ID of the destination chain
374
+ *
375
+ * @example '137' | '42161'
376
+ */
377
+ toChainId?: string;
378
+
379
+ /**
380
+ * Destination token address
381
+ * Contract address of the destination token
382
+ *
383
+ * @example '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' (USDC on Polygon)
384
+ */
385
+ toTokenAddress?: string;
386
+ }
387
+ ```
388
+
389
+ **Example:**
59
390
  ```tsx
60
391
  <RouterWidget
61
392
  config={{
62
393
  initialState: {
63
394
  fromChainId: '1', // Ethereum
64
- fromTokenAddress: '0x...', // USDC
395
+ fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
65
396
  toChainId: '137', // Polygon
66
- toTokenAddress: '0x...', // USDC on Polygon
397
+ toTokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
398
+ },
399
+ }}
400
+ />
401
+ ```
402
+
403
+ ### FeatureFlags
404
+
405
+ Control widget features and UI elements:
406
+
407
+ ```typescript
408
+ interface FeatureFlags {
409
+ /**
410
+ * Show header in the swap interface
411
+ *
412
+ * @default true
413
+ */
414
+ showHeader?: boolean;
415
+
416
+ /**
417
+ * Disable source chain/token selection
418
+ * When true, users cannot change the source chain or token
419
+ *
420
+ * @default false
421
+ */
422
+ isSrcDisabled?: boolean;
423
+
424
+ /**
425
+ * Disable destination chain/token selection
426
+ * When true, users cannot change the destination chain or token
427
+ *
428
+ * @default false
429
+ */
430
+ isDestDisabled?: boolean;
431
+ }
432
+ ```
433
+
434
+ **Example:**
435
+ ```tsx
436
+ <RouterWidget
437
+ config={{
438
+ features: {
439
+ showHeader: true,
440
+ isSrcDisabled: false,
441
+ isDestDisabled: false,
67
442
  },
68
- theme: { mode: 'dark' },
69
443
  }}
70
444
  />
71
445
  ```
72
446
 
73
- ### Skip Providers (If Already Wrapped)
447
+ ### WalletConfig
448
+
449
+ Wallet integration callbacks for external wallet providers:
74
450
 
75
- If your app already has the necessary providers (ThemeProvider, wallet providers, etc.), you can skip them:
451
+ ```typescript
452
+ interface WalletConfig {
453
+ /**
454
+ * Called when user clicks "CONNECT WALLET" button
455
+ * Only triggered when external wallet provider is detected (e.g., Dynamic.xyz)
456
+ *
457
+ * Use this to open your app's wallet connection UI
458
+ *
459
+ * @example
460
+ * wallet: {
461
+ * onConnectClick: () => {
462
+ * setShowAuthFlow(true); // Open Dynamic auth flow
463
+ * },
464
+ * }
465
+ */
466
+ onConnectClick?: () => void;
467
+ }
468
+ ```
76
469
 
470
+ **Example:**
77
471
  ```tsx
78
472
  <RouterWidget
79
- config={{ theme: { mode: 'dark' } }}
80
- skipProviders={true}
473
+ config={{
474
+ wallet: {
475
+ onConnectClick: () => {
476
+ // Open your wallet connection modal
477
+ setShowAuthFlow(true);
478
+ },
479
+ },
480
+ }}
81
481
  />
82
482
  ```
83
483
 
84
- ## Configuration Options
484
+ ### ChainConfig
485
+
486
+ Restrict which chain types are available:
487
+
488
+ ```typescript
489
+ interface ChainConfig {
490
+ /**
491
+ * Allowed chain types
492
+ * If provided, only these chain types will be enabled
493
+ *
494
+ * Available types:
495
+ * - 'evm': Ethereum Virtual Machine chains (Ethereum, Polygon, Arbitrum, etc.)
496
+ * - 'sol': Solana
497
+ * - 'btc': Bitcoin
498
+ * - 'sui': Sui
499
+ *
500
+ * @example ['evm', 'sol'] // Only EVM and Solana chains
501
+ */
502
+ types?: ('evm' | 'sol' | 'btc' | 'sui')[];
503
+ }
504
+ ```
505
+
506
+ **Example:**
507
+ ```tsx
508
+ <RouterWidget
509
+ config={{
510
+ chains: {
511
+ types: ['evm', 'sol'], // Only EVM and Solana chains
512
+ },
513
+ }}
514
+ />
515
+ ```
85
516
 
86
- ### WidgetConfig
517
+ ### Other Config Options
87
518
 
88
519
  ```typescript
89
520
  interface WidgetConfig {
90
- theme?: {
91
- mode?: 'light' | 'dark' | 'auto';
92
- primaryColor?: string;
93
- backgroundColor?: string;
94
- textColorPrimary?: string;
95
- textColorSecondary?: string;
96
- mutedColor?: string;
97
- cardBorderRadius?: string;
98
- buttonBorderRadius?: string;
99
- fontFamily?: string;
100
- };
101
- initialState?: {
102
- fromChainId?: string;
103
- fromTokenAddress?: string;
104
- toChainId?: string;
105
- toTokenAddress?: string;
106
- };
521
+ /**
522
+ * Integrator identifier
523
+ * Used for analytics and tracking
524
+ *
525
+ * @example 'MyDApp' | 'MyCompany'
526
+ */
107
527
  integrator?: string;
108
- features?: {
109
- showHeader?: boolean;
110
- isSrcDisabled?: boolean;
111
- isDestDisabled?: boolean;
112
- };
528
+
529
+ /**
530
+ * Selected routing nodes/bridges
531
+ * Array of node IDs to use for routing
532
+ * If not provided, default nodes are used
533
+ *
534
+ * @example ['router', 'stargate', 'hop']
535
+ */
113
536
  selectedNodes?: string[];
537
+
538
+ /**
539
+ * Widget mode flag
540
+ * When true:
541
+ * - Applies widget-specific styling (rounded corners, etc.)
542
+ * - Shows wallet header in widget mode
543
+ * - Optimizes for embedded use case
544
+ *
545
+ * When false:
546
+ * - Uses flat design (no rounded corners)
547
+ * - Hides widget-specific UI elements
548
+ * - Optimizes for full-page use case
549
+ *
550
+ * @default false
551
+ */
114
552
  isWidget?: boolean;
553
+
554
+ /**
555
+ * Custom wallet providers (advanced)
556
+ * Override default providers for transaction execution
557
+ *
558
+ * Used for custom wallet integrations beyond Dynamic.xyz
559
+ *
560
+ * @example
561
+ * providers: [
562
+ * createEVMProvider({ getWalletClient: async () => customWalletClient }),
563
+ * createSolanaProvider({ getWalletAdapter: async () => customAdapter }),
564
+ * ]
565
+ */
566
+ providers?: any[];
115
567
  }
116
568
  ```
117
569
 
118
- ## Environment Variables
570
+ ### Complete Configuration Example
119
571
 
120
- The widget requires certain environment variables to be set. These should be configured in your application:
572
+ ```tsx
573
+ <RouterWidget
574
+ config={{
575
+ // Theme
576
+ theme: {
577
+ mode: 'dark',
578
+ primaryColor: '#e4357a',
579
+ backgroundColor: '#0a0a0a',
580
+ textColorPrimary: '#ffffff',
581
+ textColorSecondary: '#a0a0a0',
582
+ mutedColor: '#1a1a1a',
583
+ cardBorderRadius: '10px',
584
+ buttonBorderRadius: '4px',
585
+ fontFamily: 'Inter, sans-serif',
586
+ },
121
587
 
122
- ```bash
123
- NEXT_PUBLIC_SUPPORTED_NETWORK=1,10,8453,137,sui,solana
124
- NEXT_PUBLIC_API_URL=your-grpc-api-url
125
- NEXT_PUBLIC_API_DISCOVERY_URL=https://api.discover.routerprotocol.com
126
- NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your-walletconnect-project-id
127
- NEXT_PUBLIC_PROJECT_ID=your-project-id
588
+ // Initial state
589
+ initialState: {
590
+ fromChainId: '1',
591
+ fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
592
+ toChainId: '137',
593
+ toTokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
594
+ },
595
+
596
+ // Features
597
+ features: {
598
+ showHeader: true,
599
+ isSrcDisabled: false,
600
+ isDestDisabled: false,
601
+ },
602
+
603
+ // Wallet integration
604
+ wallet: {
605
+ onConnectClick: () => {
606
+ setShowAuthFlow(true);
607
+ },
608
+ },
609
+
610
+ // Chain restrictions
611
+ chains: {
612
+ types: ['evm', 'sol'],
613
+ },
614
+
615
+ // Other options
616
+ integrator: 'MyDApp',
617
+ selectedNodes: ['router', 'stargate'],
618
+ isWidget: true,
619
+ }}
620
+ />
128
621
  ```
129
622
 
130
- ## Features
623
+ ## Advanced Usage
624
+
625
+ ### Custom Wallet Providers
626
+
627
+ For advanced use cases, you can provide custom wallet providers:
628
+
629
+ ```tsx
630
+ import { createEVMProvider, createSolanaProvider } from 'router-widget-sdk';
631
+
632
+ <RouterWidget
633
+ config={{
634
+ providers: [
635
+ createEVMProvider({
636
+ getWalletClient: async () => {
637
+ // Your custom EVM wallet client
638
+ return walletClient;
639
+ },
640
+ }),
641
+ createSolanaProvider({
642
+ getWalletAdapter: async () => {
643
+ // Your custom Solana adapter
644
+ return { signer, connection };
645
+ },
646
+ }),
647
+ ],
648
+ }}
649
+ />
650
+ ```
651
+
652
+ ### Wallet Hooks
653
+
654
+ The SDK exports hooks for wallet management:
655
+
656
+ ```tsx
657
+ import { useWallet } from 'router-widget-sdk';
658
+
659
+ function MyComponent() {
660
+ const {
661
+ primaryWallet,
662
+ userWallets,
663
+ isConnected,
664
+ walletAddress,
665
+ connectWallet,
666
+ handleLogOut,
667
+ signMessage,
668
+ } = useWallet();
669
+
670
+ // Use wallet state and methods
671
+ }
672
+ ```
673
+
674
+ **Available hooks:**
675
+ - `useWallet()` - Main wallet hook (EVM + Solana)
676
+ - `useWalletModal()` - Wallet connection modal state
677
+ - `useAccountConnect()` - Unified connect function
678
+ - `useAccountDisconnect()` - Unified disconnect function
679
+
680
+ ### Multi-Chain Wallet Support
681
+
682
+ The SDK supports connecting multiple wallets simultaneously:
683
+
684
+ ```tsx
685
+ const { userWallets, primaryWallet, switchWallet } = useWallet();
686
+
687
+ // userWallets contains all connected wallets (EVM + Solana)
688
+ // primaryWallet is the active wallet
689
+ // switchWallet() switches between wallets
690
+ ```
691
+
692
+ ## API Reference
693
+
694
+ ### Components
131
695
 
132
- - ✅ Multi-chain Support (EVM and non-EVM chains)
133
- - ✅ Wallet Integration (Dynamic wallet connection)
134
- - Real-time Quotes (Automatic quote fetching and refresh)
135
- - ✅ Customizable Themes (Light, dark, or custom colors)
136
- - ✅ Configurable (Extensive configuration options)
137
- - ✅ Responsive (Works on desktop and mobile)
696
+ #### `RouterWidget`
697
+
698
+ Main widget component. Renders the complete swap interface with all necessary providers.
699
+
700
+ **Props:**
701
+ ```typescript
702
+ interface RouterWidgetProps {
703
+ /**
704
+ * Widget configuration object
705
+ * All properties are optional
706
+ *
707
+ * @see WidgetConfig for complete configuration options
708
+ */
709
+ config?: WidgetConfig;
710
+ }
711
+ ```
712
+
713
+ **Example:**
714
+ ```tsx
715
+ <RouterWidget config={widgetConfig} />
716
+ ```
717
+
718
+ **Returns:**
719
+ - Renders the swap interface wrapped with all necessary providers
720
+ - Automatically detects external wallet contexts (Wagmi, Solana)
721
+ - Handles wallet connection/disconnection
722
+ - Manages swap state and transactions
723
+
724
+ ### Hooks
725
+
726
+ #### `useWallet()`
727
+
728
+ Returns wallet state and connection methods.
729
+
730
+ **Returns:**
731
+ ```typescript
732
+ {
733
+ primaryWallet: Wallet | null;
734
+ userWallets: Wallet[];
735
+ isConnected: boolean;
736
+ walletAddress: string;
737
+ activeConnectorId?: string;
738
+ connectWallet: () => void;
739
+ handleLogOut: () => Promise<void>;
740
+ switchWallet: (walletId: string) => Promise<boolean>;
741
+ signMessage: (message: string) => Promise<`0x${string}` | undefined>;
742
+ // ... more methods
743
+ }
744
+ ```
745
+
746
+ #### `useWalletModal()`
747
+
748
+ Manages wallet connection modal state.
749
+
750
+ **Returns:**
751
+ ```typescript
752
+ {
753
+ isOpen: boolean;
754
+ setIsOpen: (open: boolean) => void;
755
+ openModal: () => void;
756
+ closeModal: () => void;
757
+ }
758
+ ```
759
+
760
+ ### Types
761
+
762
+ #### `Wallet`
763
+
764
+ ```typescript
765
+ interface Wallet {
766
+ address: string;
767
+ chainType: ChainType; // 'evm' | 'sol' | 'btc' | 'sui'
768
+ id: string;
769
+ connector?: {
770
+ name?: string;
771
+ key?: string;
772
+ };
773
+ }
774
+ ```
775
+
776
+ #### `ChainType`
777
+
778
+ ```typescript
779
+ enum ChainType {
780
+ Evm = 'evm',
781
+ Sol = 'sol',
782
+ Btc = 'btc',
783
+ Sui = 'sui',
784
+ }
785
+ ```
786
+
787
+ ### Exported Types
788
+
789
+ The SDK exports the following TypeScript types:
790
+
791
+ ```typescript
792
+ // Main exports
793
+ import { RouterWidget, type WidgetConfig } from 'router-widget-sdk';
794
+
795
+ // Default export
796
+ import RouterWidget from 'router-widget-sdk';
797
+ ```
798
+
799
+ **Public API Exports:**
800
+
801
+ ```typescript
802
+ // Component
803
+ export { RouterWidget };
804
+ export default RouterWidget;
805
+
806
+ // Configuration type
807
+ export type { WidgetConfig };
808
+ ```
809
+
810
+ **Note:** The `WidgetConfig` type includes all nested types (`WidgetTheme`, `InitialState`, `FeatureFlags`, `WalletConfig`, `ChainConfig`) as documented in the [Configuration](#configuration) section above. These nested types are part of the `WidgetConfig` interface and don't need to be imported separately.
811
+
812
+ ## Examples
813
+
814
+ ### Basic Next.js Example
815
+
816
+ ```tsx
817
+ // app/page.tsx
818
+ 'use client';
819
+
820
+ import { RouterWidget } from 'router-widget-sdk';
821
+ import 'router-widget-sdk/styles.css';
822
+
823
+ export default function Home() {
824
+ return (
825
+ <main>
826
+ <RouterWidget
827
+ config={{
828
+ theme: { mode: 'dark' },
829
+ integrator: 'MyNextJSApp',
830
+ }}
831
+ />
832
+ </main>
833
+ );
834
+ }
835
+ ```
836
+
837
+ ### With Dynamic.xyz
838
+
839
+ See [examples/nextjs-dynamic-provider](./examples/nextjs-dynamic-provider) for a complete example with:
840
+ - Dynamic.xyz wallet integration
841
+ - EVM and Solana support
842
+ - External wallet context detection
843
+
844
+ ### With Custom Styling
845
+
846
+ ```tsx
847
+ import 'router-widget-sdk/styles.css';
848
+ import './custom-styles.css';
849
+
850
+ // custom-styles.css
851
+ .router-widget {
852
+ --primary: #e4357a;
853
+ --background: #0a0a0a;
854
+ --foreground: #ffffff;
855
+ }
856
+ ```
138
857
 
139
858
  ## TypeScript Support
140
859
 
141
- The package includes TypeScript definitions:
860
+ The SDK is written in TypeScript and includes full type definitions:
142
861
 
143
862
  ```tsx
144
863
  import { RouterWidget, type WidgetConfig } from 'router-widget-sdk';
@@ -147,26 +866,77 @@ const config: WidgetConfig = {
147
866
  theme: { mode: 'dark' },
148
867
  integrator: 'MyDApp',
149
868
  };
869
+
870
+ <RouterWidget config={config} />
150
871
  ```
151
872
 
152
873
  ## Styling
153
874
 
154
- Import the CSS file to get the default styles:
875
+ ### Default Styles
876
+
877
+ Import the CSS file to get default styles:
155
878
 
156
879
  ```tsx
157
880
  import 'router-widget-sdk/styles.css';
158
881
  ```
159
882
 
160
- You can override styles using CSS variables:
883
+ ### Custom Styling
884
+
885
+ Override styles using CSS variables:
161
886
 
162
887
  ```css
163
888
  .router-widget {
164
889
  --primary: #e4357a;
165
890
  --background: #0a0a0a;
166
891
  --foreground: #ffffff;
892
+ --muted: #1a1a1a;
167
893
  }
168
894
  ```
169
895
 
896
+ ### Widget Mode Styling
897
+
898
+ When `isWidget: true`, the SDK applies widget-specific styling:
899
+ - Rounded corners on cards (`cardBorderRadius`)
900
+ - Widget-optimized spacing
901
+ - Container constraints
902
+
903
+ When `isWidget: false`, the SDK uses flat design (no rounded corners) to match your app's design system.
904
+
905
+ ## Environment Variables
906
+
907
+ The widget requires certain environment variables:
908
+
909
+ ```bash
910
+ # Required: Supported networks (comma-separated chain IDs)
911
+ NEXT_PUBLIC_SUPPORTED_NETWORK=1,10,8453,137,42161
912
+
913
+ # Required: API endpoints
914
+ NEXT_PUBLIC_API_URL=your-grpc-api-url
915
+ NEXT_PUBLIC_API_DISCOVERY_URL=https://api.discover.routerprotocol.com
916
+
917
+ # Optional: WalletConnect
918
+ NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your-walletconnect-project-id
919
+ NEXT_PUBLIC_PROJECT_ID=your-project-id
920
+
921
+ # Optional: Dynamic.xyz (if using external wallet mode)
922
+ NEXT_PUBLIC_DYNAMIC_ENV_ID=your-dynamic-environment-id
923
+ ```
924
+
925
+ ### Supported Chain IDs
926
+
927
+ **EVM Chains:**
928
+ - `1` - Ethereum
929
+ - `10` - Optimism
930
+ - `137` - Polygon
931
+ - `42161` - Arbitrum
932
+ - `8453` - Base
933
+ - And more...
934
+
935
+ **Non-EVM Chains:**
936
+ - `solana` - Solana Mainnet
937
+ - `sui` - Sui Mainnet
938
+ - `btc` - Bitcoin
939
+
170
940
  ## Browser Support
171
941
 
172
942
  - Chrome (latest)
@@ -174,7 +944,102 @@ You can override styles using CSS variables:
174
944
  - Safari (latest)
175
945
  - Edge (latest)
176
946
 
947
+ ## Features
948
+
949
+ - ✅ **Multi-Chain Support**: EVM, Solana, Bitcoin, Sui
950
+ - ✅ **Flexible Wallet Integration**: Internal or external wallet providers
951
+ - ✅ **Real-time Quotes**: Automatic quote fetching and refresh
952
+ - ✅ **Customizable Themes**: Light, dark, or custom colors
953
+ - ✅ **TypeScript**: Full type definitions included
954
+ - ✅ **Responsive**: Works on desktop and mobile
955
+ - ✅ **Production Ready**: Battle-tested and optimized
956
+
957
+ ## Architecture
958
+
959
+ ### Provider Hierarchy
960
+
961
+ ```
962
+ RouterWidget
963
+ ├── AppProviders
964
+ │ ├── QueryClientProvider
965
+ │ ├── WidgetConfigProvider
966
+ │ ├── WalletProviderContextProvider
967
+ │ ├── PostHogProvider
968
+ │ ├── ThemeProvider
969
+ │ ├── WalletProvider
970
+ │ │ ├── EVMProvider (conditional)
971
+ │ │ ├── SVMProvider (conditional)
972
+ │ │ ├── UTXOProvider (placeholder)
973
+ │ │ ├── SuiProvider (placeholder)
974
+ │ │ ├── SDKProviders
975
+ │ │ └── WalletModalProvider
976
+ │ └── StoreProvider
977
+ └── SwapInterface
978
+ ```
979
+
980
+ ### Wallet Detection Flow
981
+
982
+ 1. **EVM Detection:**
983
+ - Checks for external Wagmi context
984
+ - If found → uses external, hides internal modal
985
+ - If not found → uses internal Wagmi/AppKit
986
+
987
+ 2. **Solana Detection:**
988
+ - Checks for external Solana context (`ConnectionProvider`)
989
+ - If found → uses external adapter
990
+ - If not found → uses internal `SVMBaseProvider`
991
+
992
+ 3. **Transaction Execution:**
993
+ - Retrieves wallet client/adapter from registered providers
994
+ - Supports chain-specific transaction handling
995
+ - Automatic chain switching for EVM
996
+
997
+ ## Troubleshooting
998
+
999
+ ### Wallet Not Connecting
1000
+
1001
+ 1. **Check External Context Detection:**
1002
+ - Ensure your wallet provider is properly set up
1003
+ - Verify `onConnectClick` callback is provided
1004
+
1005
+ 2. **Check Environment Variables:**
1006
+ - Verify `NEXT_PUBLIC_SUPPORTED_NETWORK` includes your chains
1007
+ - Ensure API URLs are correct
1008
+
1009
+ 3. **Check Console for Errors:**
1010
+ - Look for wallet connection errors
1011
+ - Check for missing dependencies
1012
+
1013
+ ### Solana Wallets Not Showing
1014
+
1015
+ 1. **Verify Solana Provider Setup:**
1016
+ - Ensure `ConnectionProvider` and `WalletProvider` are present
1017
+ - Check that `autoConnect` is enabled if needed
1018
+
1019
+ 2. **Check Wallet Standard:**
1020
+ - Ensure wallets implement Wallet Standard
1021
+ - Verify wallet extensions are installed
1022
+
1023
+ ### Styling Issues
1024
+
1025
+ 1. **Import Styles:**
1026
+ - Ensure `router-widget-sdk/styles.css` is imported
1027
+ - Check for CSS conflicts with your app
1028
+
1029
+ 2. **Widget Mode:**
1030
+ - Set `isWidget: true` for widget-specific styling
1031
+ - Use `isWidget: false` for flat design
1032
+
1033
+ ## Contributing
1034
+
1035
+ Contributions are welcome! Please see our contributing guidelines.
1036
+
177
1037
  ## License
178
1038
 
179
1039
  MIT
180
1040
 
1041
+ ## Support
1042
+
1043
+ For issues and questions:
1044
+ - GitHub Issues: [router-protocol/blinq-ui](https://github.com/router-protocol/blinq-ui)
1045
+ - Documentation: [Router Protocol Docs](https://docs.routerprotocol.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "router-widget-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Router Protocol Widget - Cross-chain swap component for React applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",