@silentswap/react 0.0.41

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 (86) hide show
  1. package/README.md +48 -0
  2. package/dist/contexts/AssetsContext.d.ts +24 -0
  3. package/dist/contexts/AssetsContext.js +83 -0
  4. package/dist/contexts/BalancesContext.d.ts +28 -0
  5. package/dist/contexts/BalancesContext.js +533 -0
  6. package/dist/contexts/OrdersContext.d.ts +53 -0
  7. package/dist/contexts/OrdersContext.js +240 -0
  8. package/dist/contexts/PricesContext.d.ts +12 -0
  9. package/dist/contexts/PricesContext.js +109 -0
  10. package/dist/contexts/SilentSwapContext.d.ts +58 -0
  11. package/dist/contexts/SilentSwapContext.js +205 -0
  12. package/dist/hooks/silent/orderTrackingWebSocketManager.d.ts +48 -0
  13. package/dist/hooks/silent/orderTrackingWebSocketManager.js +284 -0
  14. package/dist/hooks/silent/solana-transaction.d.ts +60 -0
  15. package/dist/hooks/silent/solana-transaction.js +236 -0
  16. package/dist/hooks/silent/useAuth.d.ts +90 -0
  17. package/dist/hooks/silent/useAuth.js +269 -0
  18. package/dist/hooks/silent/useBridgeExecution.d.ts +39 -0
  19. package/dist/hooks/silent/useBridgeExecution.js +877 -0
  20. package/dist/hooks/silent/useOrderSigning.d.ts +34 -0
  21. package/dist/hooks/silent/useOrderSigning.js +133 -0
  22. package/dist/hooks/silent/useOrderTracking.d.ts +174 -0
  23. package/dist/hooks/silent/useOrderTracking.js +524 -0
  24. package/dist/hooks/silent/useQuoteCalculation.d.ts +50 -0
  25. package/dist/hooks/silent/useQuoteCalculation.js +331 -0
  26. package/dist/hooks/silent/useQuoteFetching.d.ts +18 -0
  27. package/dist/hooks/silent/useQuoteFetching.js +54 -0
  28. package/dist/hooks/silent/useRefund.d.ts +26 -0
  29. package/dist/hooks/silent/useRefund.js +134 -0
  30. package/dist/hooks/silent/useSilentClient.d.ts +16 -0
  31. package/dist/hooks/silent/useSilentClient.js +32 -0
  32. package/dist/hooks/silent/useSilentOrders.d.ts +174 -0
  33. package/dist/hooks/silent/useSilentOrders.js +73 -0
  34. package/dist/hooks/silent/useSilentQuote.d.ts +88 -0
  35. package/dist/hooks/silent/useSilentQuote.js +381 -0
  36. package/dist/hooks/silent/useWallet.d.ts +76 -0
  37. package/dist/hooks/silent/useWallet.js +203 -0
  38. package/dist/hooks/useAssetPrice.d.ts +8 -0
  39. package/dist/hooks/useAssetPrice.js +47 -0
  40. package/dist/hooks/useContacts.d.ts +52 -0
  41. package/dist/hooks/useContacts.js +259 -0
  42. package/dist/hooks/useEgressEstimates.d.ts +32 -0
  43. package/dist/hooks/useEgressEstimates.js +230 -0
  44. package/dist/hooks/useHiddenSwapFees.d.ts +22 -0
  45. package/dist/hooks/useHiddenSwapFees.js +81 -0
  46. package/dist/hooks/useOrderEstimates.d.ts +37 -0
  47. package/dist/hooks/useOrderEstimates.js +393 -0
  48. package/dist/hooks/useOutputAssetInfo.d.ts +12 -0
  49. package/dist/hooks/useOutputAssetInfo.js +38 -0
  50. package/dist/hooks/usePrices.d.ts +60 -0
  51. package/dist/hooks/usePrices.js +188 -0
  52. package/dist/hooks/useQuote.d.ts +73 -0
  53. package/dist/hooks/useQuote.js +507 -0
  54. package/dist/hooks/useResetSwapForm.d.ts +16 -0
  55. package/dist/hooks/useResetSwapForm.js +68 -0
  56. package/dist/hooks/useSlippageUsd.d.ts +11 -0
  57. package/dist/hooks/useSlippageUsd.js +19 -0
  58. package/dist/hooks/useSolanaAdapter.d.ts +15 -0
  59. package/dist/hooks/useSolanaAdapter.js +55 -0
  60. package/dist/hooks/useStatus.d.ts +25 -0
  61. package/dist/hooks/useStatus.js +60 -0
  62. package/dist/hooks/useSwap.d.ts +67 -0
  63. package/dist/hooks/useSwap.js +285 -0
  64. package/dist/hooks/useTransaction.d.ts +119 -0
  65. package/dist/hooks/useTransaction.js +353 -0
  66. package/dist/hooks/useTransactionAddress.d.ts +11 -0
  67. package/dist/hooks/useTransactionAddress.js +26 -0
  68. package/dist/hooks/useUsdValue.d.ts +7 -0
  69. package/dist/hooks/useUsdValue.js +19 -0
  70. package/dist/index.d.ts +54 -0
  71. package/dist/index.js +41 -0
  72. package/dist/stories/SilentSwapOverview.stories.d.ts +10 -0
  73. package/dist/stories/SilentSwapOverview.stories.js +364 -0
  74. package/dist/stories/useAuth.stories.d.ts +6 -0
  75. package/dist/stories/useAuth.stories.js +55 -0
  76. package/dist/stories/useSilentClient.stories.d.ts +9 -0
  77. package/dist/stories/useSilentClient.stories.js +39 -0
  78. package/dist/stories/useSilentOrders.stories.d.ts +1 -0
  79. package/dist/stories/useSilentOrders.stories.js +1 -0
  80. package/dist/stories/useSilentQuote.stories.d.ts +6 -0
  81. package/dist/stories/useSilentQuote.stories.js +267 -0
  82. package/dist/stories/useTransaction.stories.d.ts +6 -0
  83. package/dist/stories/useTransaction.stories.js +121 -0
  84. package/dist/utils/formatters.d.ts +33 -0
  85. package/dist/utils/formatters.js +82 -0
  86. package/package.json +67 -0
@@ -0,0 +1,364 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useMemo } from 'react';
3
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
4
+ import { WagmiProvider, createConfig, http } from 'wagmi';
5
+ import { mainnet, avalanche } from 'wagmi/chains';
6
+ import { injected } from 'wagmi/connectors';
7
+ import { SilentSwapProvider, useSilentSwap } from '../index.js';
8
+ import { useSilentOrders } from '../hooks/silent/useSilentOrders.js';
9
+ import { useAuth } from '../hooks/silent/useAuth.js';
10
+ import { createViemSigner, DeliveryMethod, FacilitatorKeyType, createHdFacilitatorGroupFromEntropy, caip19FungibleEvmToken, PublicKeyArgGroups, ENVIRONMENT, createSilentSwapClient } from '@silentswap/sdk';
11
+ import { useWalletClient, useAccount, useConnect, useDisconnect, useChainId } from 'wagmi';
12
+ import { switchChain } from 'viem/actions';
13
+ function WalletConnectionSection({ isConnected, connectedAddress, connectors, isPending, onConnect, onDisconnect, }) {
14
+ return (_jsxs("div", { style: {
15
+ marginBottom: '20px',
16
+ padding: '15px',
17
+ border: '2px solid #e0e0e0',
18
+ borderRadius: '8px',
19
+ background: isConnected ? '#d4edda' : '#fff3cd',
20
+ }, children: [_jsx("h3", { children: "\uD83D\uDD17 Wallet Connection" }), isConnected ? (_jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: "Status:" }), " \u2705 Connected"] }), _jsxs("p", { children: [_jsx("strong", { children: "Address:" }), " ", connectedAddress] }), _jsx("button", { onClick: onDisconnect, style: {
21
+ padding: '8px 16px',
22
+ background: '#dc3545',
23
+ color: 'white',
24
+ border: 'none',
25
+ borderRadius: '4px',
26
+ cursor: 'pointer',
27
+ marginTop: '10px',
28
+ }, children: "Disconnect Wallet" })] })) : (_jsxs("div", { children: [_jsxs("p", { children: [_jsx("strong", { children: "Status:" }), " \u274C Not Connected"] }), _jsx("p", { children: "Please connect your wallet to continue." }), _jsx("div", { style: { display: 'flex', gap: '10px', flexWrap: 'wrap', marginTop: '10px' }, children: connectors.map((connector) => (_jsx("button", { onClick: () => onConnect(connector), disabled: isPending, style: {
29
+ padding: '8px 16px',
30
+ background: '#007bff',
31
+ color: 'white',
32
+ border: 'none',
33
+ borderRadius: '4px',
34
+ cursor: isPending ? 'not-allowed' : 'pointer',
35
+ opacity: isPending ? 0.6 : 1,
36
+ }, children: isPending ? 'Connecting...' : `Connect ${connector.name}` }, connector.uid))) })] }))] }));
37
+ }
38
+ function StatusSection({ step, isLoading, error }) {
39
+ return (_jsxs("div", { style: {
40
+ marginBottom: '20px',
41
+ padding: '15px',
42
+ border: '2px solid #e0e0e0',
43
+ borderRadius: '8px',
44
+ background: '#fafafa',
45
+ }, children: [_jsx("h3", { children: "Status" }), _jsxs("p", { children: [_jsx("strong", { children: "Current Step:" }), " ", step.toUpperCase()] }), _jsxs("p", { children: [_jsx("strong", { children: "Loading:" }), " ", isLoading ? '⏳ Processing...' : '✅ Ready'] }), _jsxs("p", { children: [_jsx("strong", { children: "Error:" }), " ", error ? `❌ ${error.message}` : '✅ None'] })] }));
46
+ }
47
+ function FlowStepsSection({ step, isLoading, isActionLoading, isConnected, hasNonce, hasAuth, hasQuote, onGetNonce, onAuthenticate, onGetQuote, onCreateOrder, onReset, }) {
48
+ const isDisabled = isLoading || isActionLoading;
49
+ const buttonStyle = (isActive, disabled) => ({
50
+ padding: '8px 16px',
51
+ background: isActive ? '#007bff' : '#f8f9fa',
52
+ color: isActive ? 'white' : 'black',
53
+ border: '1px solid #ddd',
54
+ borderRadius: '4px',
55
+ cursor: disabled ? 'not-allowed' : 'pointer',
56
+ opacity: disabled ? 0.6 : 1,
57
+ });
58
+ return (_jsxs("div", { style: { marginBottom: '20px' }, children: [_jsx("h3", { children: "Swap Flow Steps" }), _jsxs("div", { style: { display: 'flex', gap: '10px', flexWrap: 'wrap', marginBottom: '15px' }, children: [_jsx("button", { onClick: onGetNonce, disabled: isDisabled || step !== 'idle' || !isConnected, style: buttonStyle(step === 'nonce', isDisabled || step !== 'idle' || !isConnected), children: isActionLoading && step === 'nonce' ? '⏳ Loading...' : '1. Get Nonce' }), _jsx("button", { onClick: onAuthenticate, disabled: isDisabled || !hasNonce || step === 'idle', style: buttonStyle(step === 'auth', isDisabled || !hasNonce || step === 'idle'), children: isActionLoading && step === 'auth' ? '⏳ Loading...' : '2. Authenticate' }), _jsx("button", { onClick: onGetQuote, disabled: isDisabled || !hasAuth, style: buttonStyle(step === 'quote', isDisabled || !hasAuth), children: isActionLoading && step === 'quote' ? '⏳ Loading...' : '3. Get Quote' }), _jsx("button", { onClick: onCreateOrder, disabled: isDisabled || !hasQuote, style: buttonStyle(step === 'order', isDisabled || !hasQuote), children: isActionLoading && step === 'order' ? '⏳ Loading...' : '4. Create Order' }), _jsx("button", { onClick: onReset, disabled: isDisabled, style: {
59
+ padding: '8px 16px',
60
+ background: '#dc3545',
61
+ color: 'white',
62
+ border: '1px solid #ddd',
63
+ borderRadius: '4px',
64
+ cursor: isDisabled ? 'not-allowed' : 'pointer',
65
+ opacity: isDisabled ? 0.6 : 1,
66
+ }, children: "\uD83D\uDD04 Reset" })] })] }));
67
+ }
68
+ function ResultsSection({ results }) {
69
+ return (_jsxs("div", { children: [_jsx("h3", { children: "Results" }), Object.entries(results).map(([key, value]) => (_jsxs("details", { style: { marginBottom: '10px' }, children: [_jsxs("summary", { children: [key.charAt(0).toUpperCase() + key.slice(1), " Result"] }), _jsx("pre", { style: {
70
+ background: '#f8f9fa',
71
+ padding: '10px',
72
+ borderRadius: '4px',
73
+ border: '1px solid #dee2e6',
74
+ overflow: 'auto',
75
+ maxHeight: '200px',
76
+ }, children: JSON.stringify(value, null, 2) })] }, key)))] }));
77
+ }
78
+ function HookUsageSummary() {
79
+ return (_jsxs("details", { style: { marginTop: '20px' }, children: [_jsx("summary", { children: "Hook Usage Summary" }), _jsxs("div", { style: { padding: '10px', background: '#f8f9fa', borderRadius: '4px' }, children: [_jsx("h4", { children: "\uD83D\uDD17 useSilentClient" }), _jsx("p", { children: "Creates and manages the SilentSwap client instance with your configuration." }), _jsx("h4", { children: "\uD83D\uDCE6 useSilentOrders" }), _jsx("p", { children: "Provides methods for nonce retrieval, authentication, quote fetching, and order creation with built-in loading and error states." }), _jsx("h4", { children: "\uD83D\uDD10 useAuth" }), _jsx("p", { children: "Offers utility functions for creating sign-in messages and EIP-712 typed data for secure authentication." })] })] }));
80
+ }
81
+ function useSilentQuoteHandlers({ client, getNonce, authenticate, createSignInMessage, createEip712DocForOrder, walletClient, connectedAddress, chainId, setStep, setResults, results, setIsActionLoading, }) {
82
+ const handleGetNonce = async () => {
83
+ if (!connectedAddress) {
84
+ alert('Please connect your wallet first');
85
+ return;
86
+ }
87
+ setIsActionLoading(true);
88
+ try {
89
+ setStep('nonce');
90
+ const nonce = await getNonce(connectedAddress);
91
+ setResults((prev) => ({ ...prev, nonce }));
92
+ if (nonce)
93
+ setStep('auth');
94
+ }
95
+ finally {
96
+ setIsActionLoading(false);
97
+ }
98
+ };
99
+ const handleAuthenticate = async () => {
100
+ if (!results.nonce)
101
+ return;
102
+ if (!connectedAddress) {
103
+ alert('Please connect your wallet first');
104
+ return;
105
+ }
106
+ setIsActionLoading(true);
107
+ setStep('auth');
108
+ const signInMessage = createSignInMessage(connectedAddress, results.nonce.nonce, window.location.host);
109
+ if (!walletClient) {
110
+ alert('Wallet client not available. Please try reconnecting your wallet.');
111
+ setIsActionLoading(false);
112
+ return;
113
+ }
114
+ try {
115
+ const signer = createViemSigner({ address: connectedAddress, type: 'json-rpc' }, walletClient);
116
+ const signature = await signer.signEip191Message(signInMessage.message);
117
+ const authRequest = {
118
+ siwe: {
119
+ message: signInMessage.message,
120
+ signature: signature,
121
+ },
122
+ };
123
+ const authResult = await authenticate(authRequest);
124
+ setResults((prev) => ({ ...prev, auth: authResult, signInMessage, signature }));
125
+ if (authResult)
126
+ setStep('quote');
127
+ }
128
+ catch (error) {
129
+ console.error('Authentication failed:', error);
130
+ alert('Authentication failed. Please try again.');
131
+ }
132
+ finally {
133
+ setIsActionLoading(false);
134
+ }
135
+ };
136
+ const handleGetQuote = async () => {
137
+ if (!connectedAddress) {
138
+ alert('Please connect your wallet first');
139
+ return;
140
+ }
141
+ setIsActionLoading(true);
142
+ setStep('quote');
143
+ try {
144
+ // Switch to Mainnet if not already on it
145
+ if (!walletClient) {
146
+ throw new Error('Wallet client not available');
147
+ }
148
+ // Generate entropy (in a real app, this would come from a secure source)
149
+ const entropy = new Uint8Array(32);
150
+ const random = crypto.getRandomValues(entropy);
151
+ // Create HD facilitator group from entropy
152
+ const group = await createHdFacilitatorGroupFromEntropy(random, 0);
153
+ // Derive viewer account
154
+ const viewer = await group.viewer();
155
+ // Export its public key
156
+ const { publicKeyBytes: pk65_viewer } = viewer.exportPublicKey('*', FacilitatorKeyType.SECP256K1);
157
+ // Export public keys for the facilitator group
158
+ const groupPublicKeys = await group.exportPublicKeys(1, [...PublicKeyArgGroups.GENERIC]);
159
+ // Define outputs
160
+ const outputs = [
161
+ {
162
+ method: DeliveryMethod.SNIP,
163
+ asset: caip19FungibleEvmToken(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
164
+ facilitatorPublicKeys: groupPublicKeys[0],
165
+ recipient: connectedAddress,
166
+ value: '10000000',
167
+ },
168
+ ];
169
+ // Ensure outputs
170
+ if (!((outputs?.length ?? 0) >= 1))
171
+ throw Error('No outputs specified');
172
+ // Request a quote
173
+ const [error, quote] = await client.quote({
174
+ signer: connectedAddress,
175
+ viewer: pk65_viewer,
176
+ outputs: outputs,
177
+ });
178
+ if (error) {
179
+ throw new Error(`Failed to get quote: ${error.error}`);
180
+ }
181
+ setResults((prev) => ({ ...prev, quote, group }));
182
+ if (quote)
183
+ setStep('order');
184
+ }
185
+ catch (error) {
186
+ console.error('Quote request failed:', error);
187
+ alert(`Failed to get quote: ${error instanceof Error ? error.message : 'Unknown error'}`);
188
+ }
189
+ finally {
190
+ setIsActionLoading(false);
191
+ }
192
+ };
193
+ const handleCreateOrder = async () => {
194
+ if (!results.quote || !results.group)
195
+ return;
196
+ if (!connectedAddress || !walletClient) {
197
+ alert('Please connect your wallet first');
198
+ return;
199
+ }
200
+ setIsActionLoading(true);
201
+ setStep('order');
202
+ try {
203
+ const quoteResponse = results.quote;
204
+ const group = results.group;
205
+ if (!walletClient) {
206
+ throw new Error('Wallet client not available');
207
+ }
208
+ const signer = createViemSigner({ address: connectedAddress, type: 'json-rpc' }, walletClient);
209
+ // Switch to Avalanche if not already on it
210
+ if (chainId !== avalanche.id) {
211
+ await switchChain(walletClient, { id: avalanche.id });
212
+ }
213
+ // Sign authorizations
214
+ const signedAuths = await Promise.all(quoteResponse.authorizations.map(async (g_auth) => ({
215
+ ...g_auth,
216
+ signature: await (async () => {
217
+ if ('eip3009_deposit' === g_auth.type) {
218
+ return await signer.signEip712TypedData(g_auth.eip712);
219
+ }
220
+ throw Error(`Authorization instruction type not implemented: ${g_auth.type}`);
221
+ })(),
222
+ })));
223
+ // Switch to Mainnet if not already on it
224
+ if (chainId !== mainnet.id) {
225
+ await switchChain(walletClient, { id: mainnet.id });
226
+ }
227
+ // Sign the order's EIP-712
228
+ const orderDoc = createEip712DocForOrder(quoteResponse);
229
+ const signedQuote = await signer.signEip712TypedData(orderDoc);
230
+ // Approve proxy authorizations
231
+ const facilitatorReplies = await group.approveProxyAuthorizations(quoteResponse.facilitators, {
232
+ proxyPublicKey: client.proxyPublicKey,
233
+ });
234
+ // Place the order
235
+ const [orderError, orderResponse] = await client.order({
236
+ quote: quoteResponse.quote,
237
+ quoteId: quoteResponse.quoteId,
238
+ authorizations: signedAuths,
239
+ eip712Domain: orderDoc.domain,
240
+ signature: signedQuote,
241
+ facilitators: facilitatorReplies,
242
+ });
243
+ if (orderError || !orderResponse) {
244
+ throw new Error(`Failed to place order: ${orderError?.type}: ${orderError?.error}`);
245
+ }
246
+ setResults((prev) => ({ ...prev, order: orderResponse }));
247
+ if (orderResponse) {
248
+ console.log(`Placed order ${orderResponse.response.orderId}`);
249
+ setStep('idle');
250
+ }
251
+ }
252
+ catch (error) {
253
+ console.error('Order creation failed:', error);
254
+ alert(`Failed to create order: ${error instanceof Error ? error.message : 'Unknown error'}`);
255
+ }
256
+ finally {
257
+ setIsActionLoading(false);
258
+ }
259
+ };
260
+ const reset = () => {
261
+ setStep('idle');
262
+ setResults({});
263
+ };
264
+ return {
265
+ handleGetNonce,
266
+ handleAuthenticate,
267
+ handleGetQuote,
268
+ handleCreateOrder,
269
+ reset,
270
+ };
271
+ }
272
+ // ============================================================================
273
+ // Main Component
274
+ // ============================================================================
275
+ // Inner component that uses the new provider flow
276
+ function SilentSwapCompleteDemoInner({ config }) {
277
+ // Use the new useSilentSwap hook (same as web-app-example)
278
+ const { client, wallet, walletLoading, swapLoading, swapError, quote, } = useSilentSwap();
279
+ // For backward compatibility with the demo, we still need useSilentOrders for getNonce, authenticate, etc.
280
+ // But we can use useSilentSwap for client and other shared state
281
+ const { isLoading, error, getNonce, authenticate, getQuote, createOrder } = useSilentOrders({ client });
282
+ const { createSignInMessage, createEip712DocForOrder } = useAuth();
283
+ const [step, setStep] = useState('idle');
284
+ const [results, setResults] = useState({});
285
+ const [isActionLoading, setIsActionLoading] = useState(false);
286
+ const { data: walletClient } = useWalletClient();
287
+ const { address: connectedAddress, isConnected } = useAccount();
288
+ const { connect, connectors, isPending } = useConnect();
289
+ const { disconnect } = useDisconnect();
290
+ const chainId = useChainId();
291
+ const { handleGetNonce, handleAuthenticate, handleGetQuote, handleCreateOrder, reset } = useSilentQuoteHandlers({
292
+ client,
293
+ getNonce,
294
+ authenticate,
295
+ createSignInMessage,
296
+ createEip712DocForOrder,
297
+ walletClient,
298
+ connectedAddress,
299
+ chainId,
300
+ setStep,
301
+ setResults,
302
+ results,
303
+ setIsActionLoading,
304
+ });
305
+ return (_jsxs("div", { style: { maxWidth: '800px', fontFamily: 'Arial, sans-serif' }, children: [_jsx("h2", { children: "\uD83D\uDE80 SilentSwap Complete Flow Demo" }), _jsx("p", { children: "This demo shows how all SilentSwap React hooks work together in a complete swap flow." }), _jsx(WalletConnectionSection, { isConnected: isConnected, connectedAddress: connectedAddress, connectors: connectors, isPending: isPending, onConnect: (connector) => connect({ connector }), onDisconnect: disconnect }), _jsx(StatusSection, { step: step, isLoading: isLoading, error: error }), _jsx(FlowStepsSection, { step: step, isLoading: isLoading, isActionLoading: isActionLoading, isConnected: isConnected, hasNonce: !!results.nonce, hasAuth: !!results.auth, hasQuote: !!results.quote, onGetNonce: handleGetNonce, onAuthenticate: handleAuthenticate, onGetQuote: handleGetQuote, onCreateOrder: handleCreateOrder, onReset: reset }), _jsx(ResultsSection, { results: results }), _jsx(HookUsageSummary, {})] }));
306
+ }
307
+ // ============================================================================
308
+ // Storybook Configuration
309
+ // ============================================================================
310
+ // Create providers for Storybook
311
+ const queryClient = new QueryClient();
312
+ const wagmiConfig = createConfig({
313
+ chains: [mainnet, avalanche],
314
+ connectors: [injected()],
315
+ transports: {
316
+ [mainnet.id]: http(),
317
+ [avalanche.id]: http(),
318
+ },
319
+ });
320
+ // Wrapper component that provides SilentSwapProvider
321
+ function SilentSwapCompleteDemo({ config }) {
322
+ const { address, isConnected, connector } = useAccount();
323
+ const { data: walletClient } = useWalletClient();
324
+ // Create client instance for the provider
325
+ const client = useMemo(() => createSilentSwapClient({ environment: config.environment }), [config.environment]);
326
+ return (_jsx(SilentSwapProvider, { client: client, environment: config.environment, solanaRpcUrl: undefined, evmAddress: address, solAddress: undefined, solanaConnector: undefined, solanaConnection: undefined, connector: connector, walletClient: walletClient, isConnected: isConnected, children: _jsx(SilentSwapCompleteDemoInner, { config: config }) }));
327
+ }
328
+ const meta = {
329
+ title: 'Overview/Complete SilentSwap Flow',
330
+ component: ({ config }) => {
331
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(SilentSwapCompleteDemo, { config: config }) }) }));
332
+ },
333
+ tags: ['autodocs'],
334
+ parameters: {
335
+ docs: {
336
+ description: {
337
+ component: 'Complete demonstration of all SilentSwap React hooks working together in a typical swap flow.',
338
+ },
339
+ },
340
+ },
341
+ argTypes: {
342
+ config: {
343
+ description: 'Configuration object for the SilentSwap client',
344
+ control: { type: 'object' },
345
+ },
346
+ },
347
+ };
348
+ export default meta;
349
+ export const DefaultFlow = {
350
+ args: {
351
+ config: {
352
+ baseUrl: 'https://api.silentswap.com',
353
+ environment: ENVIRONMENT.MAINNET,
354
+ },
355
+ },
356
+ };
357
+ export const StagingEnvironment = {
358
+ args: {
359
+ config: {
360
+ baseUrl: 'https://api-staging.silentswap.com',
361
+ environment: ENVIRONMENT.MAINNET,
362
+ },
363
+ },
364
+ };
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ declare function AuthDemo(): import("react/jsx-runtime").JSX.Element;
3
+ declare const meta: Meta<typeof AuthDemo>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof meta>;
6
+ export declare const Default: Story;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useAuth } from '../hooks/silent/useAuth.js';
4
+ // Mock component to demonstrate the auth hook
5
+ function AuthDemo() {
6
+ const { createSignInMessage, createEip712DocForOrder, createEip712DocForWalletGeneration } = useAuth();
7
+ const [signInMessage, setSignInMessage] = useState(null);
8
+ const [eip712OrderDoc, setEip712OrderDoc] = useState('');
9
+ const [eip712WalletDoc, setEip712WalletDoc] = useState('');
10
+ const handleCreateSignInMessage = () => {
11
+ const address = '0x461ddCA267968eB7A8191c0cDb1684a45b9250c9';
12
+ const nonce = '5iUbxyv4Hw2G7BFib2ymjD6atpdmX7ob1Lp3QKM8ZAsqXYsDrHzVRFUk4FmgeaFJXYSaMobX2ep2MZYCKef6vVtj9fAjpWpBfiWXkFh9im61dAC8rxGa4yMCn1ikPYPsyuV1xuiuCA6KjTugKrv5Q3gw6C6ssVvhVBDmAtM2X7VoSwY24KmDmA9yL915wmuPtwfYrBDukTUrdYXdwaCg31GsXrei2AhtB9YJaodf9mFQdCyW3sLU1C3PMj6iqz9ZdSdMCX5CAq9RZuv';
13
+ const domain = 'app.silentswap.com';
14
+ const message = createSignInMessage(address, nonce, domain);
15
+ setSignInMessage(message);
16
+ };
17
+ const handleCreateEip712OrderDoc = () => {
18
+ // Mock quote response
19
+ const mockQuoteResponse = {
20
+ quoteId: 'quote-123',
21
+ sellToken: '0xA0b86a33E6441e88C5F2712C3E9b74B8F7c6F5F5',
22
+ buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
23
+ sellAmount: '1000000000000000000',
24
+ buyAmount: '2500000000000000000',
25
+ feeAmount: '25000000000000000',
26
+ expiration: Date.now() + 3600000, // 1 hour from now
27
+ };
28
+ const doc = createEip712DocForOrder(mockQuoteResponse);
29
+ setEip712OrderDoc(JSON.stringify(doc, null, 2));
30
+ };
31
+ const handleCreateEip712WalletDoc = () => {
32
+ const scope = 'wallet-generation';
33
+ const token = 'token-456';
34
+ const doc = createEip712DocForWalletGeneration(scope, token);
35
+ setEip712WalletDoc(JSON.stringify(doc, null, 2));
36
+ };
37
+ return (_jsxs("div", { children: [_jsx("h3", { children: "SilentSwap Auth Utilities Demo" }), _jsxs("div", { style: { marginBottom: '20px' }, children: [_jsx("button", { onClick: handleCreateSignInMessage, style: { marginRight: '10px' }, children: "Create Sign-In Message" }), _jsx("button", { onClick: handleCreateEip712OrderDoc, style: { marginRight: '10px' }, children: "Create EIP-712 Order Doc" }), _jsx("button", { onClick: handleCreateEip712WalletDoc, children: "Create EIP-712 Wallet Doc" })] }), signInMessage && (_jsxs("details", { style: { marginBottom: '10px' }, children: [_jsx("summary", { children: "Sign-In Message" }), _jsx("pre", { style: { background: '#f5f5f5', padding: '10px', borderRadius: '4px' }, children: JSON.stringify(signInMessage, null, 2) })] })), eip712OrderDoc && (_jsxs("details", { style: { marginBottom: '10px' }, children: [_jsx("summary", { children: "EIP-712 Order Document" }), _jsx("pre", { style: { background: '#f5f5f5', padding: '10px', borderRadius: '4px' }, children: eip712OrderDoc })] })), eip712WalletDoc && (_jsxs("details", { style: { marginBottom: '10px' }, children: [_jsx("summary", { children: "EIP-712 Wallet Document" }), _jsx("pre", { style: { background: '#f5f5f5', padding: '10px', borderRadius: '4px' }, children: eip712WalletDoc })] })), _jsxs("details", { style: { marginTop: '20px' }, children: [_jsx("summary", { children: "Available Methods:" }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("code", { children: "createSignInMessage(address, nonce, domain?)" }), " - Create sign-in message for authentication"] }), _jsxs("li", { children: [_jsx("code", { children: "createEip712DocForOrder(quoteResponse)" }), " - Create EIP-712 typed data for order signing"] }), _jsxs("li", { children: [_jsx("code", { children: "createEip712DocForWalletGeneration(scope, token)" }), " - Create EIP-712 typed data for wallet generation"] })] })] })] }));
38
+ }
39
+ const meta = {
40
+ title: 'Hooks/useAuth',
41
+ component: AuthDemo,
42
+ //👇 Enables auto-generated documentation for this component and includes all stories in this file
43
+ tags: ['autodocs'],
44
+ parameters: {
45
+ docs: {
46
+ description: {
47
+ component: 'React hook providing authentication utilities for SilentSwap, including sign-in messages and EIP-712 typed data creation.',
48
+ },
49
+ },
50
+ },
51
+ };
52
+ export default meta;
53
+ export const Default = {
54
+ args: {},
55
+ };
@@ -0,0 +1,9 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { type SilentSwapClientConfig } from '@silentswap/sdk';
3
+ declare function ClientDemo({ config }: {
4
+ config: SilentSwapClientConfig;
5
+ }): import("react/jsx-runtime").JSX.Element;
6
+ declare const meta: Meta<typeof ClientDemo>;
7
+ export default meta;
8
+ type Story = StoryObj<typeof meta>;
9
+ export declare const Default: Story;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useSilentClient } from '../hooks/silent/useSilentClient.js';
3
+ import { ENVIRONMENT } from '@silentswap/sdk';
4
+ // Mock component to demonstrate the hook
5
+ function ClientDemo({ config }) {
6
+ const { client } = useSilentClient({ config });
7
+ return (_jsxs("div", { children: [_jsx("h3", { children: "SilentSwap Client Demo" }), _jsxs("p", { children: [_jsx("strong", { children: "Client created:" }), " ", client ? '✅' : '❌'] }), _jsxs("p", { children: [_jsx("strong", { children: "Client type:" }), " ", client?.constructor?.name || 'Unknown'] }), _jsxs("details", { children: [_jsx("summary", { children: "Client methods available:" }), _jsx("ul", { children: client &&
8
+ Object.getOwnPropertyNames(client.constructor.prototype)
9
+ .filter((name) => name !== 'constructor')
10
+ .map((method) => _jsx("li", { children: method }, method)) })] })] }));
11
+ }
12
+ const meta = {
13
+ title: 'Hooks/useSilentClient',
14
+ component: ClientDemo,
15
+ //👇 Enables auto-generated documentation for this component and includes all stories in this file
16
+ tags: ['autodocs'],
17
+ parameters: {
18
+ docs: {
19
+ description: {
20
+ component: 'React hook for creating and managing a SilentSwap client instance.',
21
+ },
22
+ },
23
+ },
24
+ argTypes: {
25
+ config: {
26
+ description: 'Configuration object for the SilentSwap client',
27
+ control: { type: 'object' },
28
+ },
29
+ },
30
+ };
31
+ export default meta;
32
+ export const Default = {
33
+ args: {
34
+ config: {
35
+ baseUrl: 'https://api-staging.silentswap.com',
36
+ environment: ENVIRONMENT.MAINNET,
37
+ },
38
+ },
39
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ declare function BridgeQuoteDemo(): import("react/jsx-runtime").JSX.Element;
3
+ declare const meta: Meta<typeof BridgeQuoteDemo>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof meta>;
6
+ export declare const Default: Story;