@cookill/wallet-adapter 2.5.3 → 3.0.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/README.md CHANGED
@@ -1,26 +1,32 @@
1
- # @cookill/wallet-adapter v2.4.0
1
+ # @cookill/wallet-adapter v3.0.0
2
2
 
3
3
  Official wallet adapter for **Sheep Wallet** on Rialo blockchain.
4
4
 
5
+ ## 🚀 What's New in v3.0
6
+
7
+ - **Anti-freeze architecture**: All provider calls wrapped with timeouts
8
+ - **Clean separation**: Core (vanilla JS) vs React layer
9
+ - **Silent auto-connect**: Uses `checkSession()` instead of `connect()` for session restoration
10
+ - **No more hangs**: 20-second timeout on connection, 30-second on operations
11
+
5
12
  ## Installation
6
13
 
7
14
  ```bash
8
15
  npm install @cookill/wallet-adapter
16
+ # or
17
+ pnpm add @cookill/wallet-adapter
18
+ # or
19
+ yarn add @cookill/wallet-adapter
9
20
  ```
10
21
 
11
- ## Quick Start
22
+ ## Quick Start (React)
12
23
 
13
24
  ```tsx
14
- import {
15
- WalletProvider,
16
- ConnectButton,
17
- WalletErrorBoundary,
18
- } from '@cookill/wallet-adapter/react';
25
+ import { WalletProvider, ConnectButton, WalletErrorBoundary } from '@cookill/wallet-adapter/react';
19
26
 
20
27
  function App() {
21
28
  return (
22
29
  <WalletErrorBoundary>
23
- {/* WalletProvider will render a default WalletModal automatically */}
24
30
  <WalletProvider network="devnet" autoConnect>
25
31
  <ConnectButton />
26
32
  <YourDApp />
@@ -30,77 +36,130 @@ function App() {
30
36
  }
31
37
  ```
32
38
 
33
- ## Troubleshooting (Connect stuck)
34
-
35
- If clicking **Connect** does nothing or feels "stuck":
36
-
37
- - Make sure your dApp is wrapped in `<WalletProvider>` (and ideally `<WalletErrorBoundary>`).
38
- - Prefer `useConnectWallet().connect` (opens the modal) instead of `connectDirect`.
39
- - The modal is rendered automatically by `WalletProvider`.
40
-
41
39
  ## React Hooks
42
40
 
43
41
  ### useWallet
44
42
 
45
43
  ```tsx
46
- const {
47
- // State
48
- connected, // boolean
49
- connecting, // boolean
50
- accounts, // WalletAccount[]
51
- activeAccount, // WalletAccount | null
52
- network, // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
53
- chainId, // 'rialo:devnet' etc
54
- balance, // string | null (in kelvins)
55
- error, // Error | null
56
-
57
- // Actions
58
- connect, // () => Promise<WalletAccount[]>
59
- disconnect, // () => Promise<void>
60
- switchNetwork, // (network) => Promise<void>
61
- refreshBalance, // () => Promise<void>
62
-
63
- // Transactions
64
- signMessage, // (message: string) => Promise<SignedMessage>
65
- signTransaction, // (tx) => Promise<string>
66
- sendTransaction, // (tx) => Promise<TransactionResult>
67
- signAndSendTransaction, // (tx) => Promise<TransactionResult>
68
-
69
- // Modal
70
- isModalOpen,
71
- openModal,
72
- closeModal,
73
- } = useWallet();
74
- ```
75
-
76
- ### useConnectWallet
44
+ import { useWallet } from '@cookill/wallet-adapter/react';
45
+
46
+ function MyComponent() {
47
+ const {
48
+ // State
49
+ connected, // boolean
50
+ connecting, // boolean
51
+ activeAccount, // WalletAccount | null
52
+ state, // Full state object
53
+ chainId, // 'rialo:devnet' etc
54
+ isInstalled, // boolean
55
+
56
+ // Actions
57
+ connect, // () => Promise<WalletAccount[]>
58
+ disconnect, // () => Promise<void>
59
+ switchNetwork, // (network) => Promise<void>
60
+ refreshBalance, // () => Promise<void>
61
+
62
+ // Transactions
63
+ signMessage, // (message: string) => Promise<SignedMessage>
64
+ signTransaction, // (tx) => Promise<string>
65
+ sendTransaction, // (tx) => Promise<TransactionResult>
66
+ signAndSendTransaction, // (tx) => Promise<TransactionResult>
67
+
68
+ // Modal
69
+ openModal,
70
+ closeModal,
71
+ } = useWallet();
77
72
 
78
- ```tsx
79
- const {
80
- connect, // Opens modal (recommended)
81
- connectDirect, // Calls provider directly
82
- connecting,
83
- isInstalled,
84
- error,
85
- openModal,
86
- } = useConnectWallet();
87
-
88
- <button onClick={connect}>Connect Wallet</button>
73
+ return (
74
+ <div>
75
+ {connected ? (
76
+ <p>Connected: {activeAccount?.address}</p>
77
+ ) : (
78
+ <button onClick={connect}>Connect</button>
79
+ )}
80
+ </div>
81
+ );
82
+ }
89
83
  ```
90
84
 
91
- ### Other Hooks
85
+ ### Specialized Hooks
92
86
 
93
87
  ```tsx
88
+ // Connection
89
+ const { connect, connecting, isInstalled, error } = useConnectWallet();
90
+ const { disconnect, connected } = useDisconnectWallet();
94
91
  const connected = useIsConnected();
92
+
93
+ // Account
95
94
  const account = useActiveAccount();
96
95
  const accounts = useAccounts();
97
- const { balance, formatted, refresh } = useBalance();
98
- const { network, chainId, config } = useNetwork();
99
- const { switchNetwork, switching, error, currentNetwork } = useSwitchNetwork();
100
- const { disconnect, connected } = useDisconnectWallet();
101
- const { sign, signing, signature, error, address } = useSignMessage();
102
- const { sign, signing, signature, error } = useSignTransaction();
103
- const { send, sending, txHash, error, reset } = useSendTransaction();
96
+
97
+ // Balance
98
+ const { balance, refresh } = useBalance();
99
+
100
+ // Network
101
+ const { network, chainId } = useNetwork();
102
+ const { switchNetwork, network } = useSwitchNetwork();
103
+
104
+ // Transactions
105
+ const { signMessage, connected } = useSignMessage();
106
+ const { sendTransaction, signAndSendTransaction, connected } = useSendTransaction();
107
+ ```
108
+
109
+ ## Vanilla JavaScript
110
+
111
+ ```typescript
112
+ import { SheepWallet, isInstalled, formatBalance } from '@cookill/wallet-adapter';
113
+
114
+ // Check if installed
115
+ if (!isInstalled()) {
116
+ console.log('Please install Sheep Wallet');
117
+ }
118
+
119
+ // Create wallet instance
120
+ const wallet = new SheepWallet();
121
+
122
+ // Connect (with built-in timeout)
123
+ try {
124
+ const accounts = await wallet.connect();
125
+ console.log('Connected:', accounts[0].address);
126
+ } catch (error) {
127
+ console.error('Connection failed:', error.message);
128
+ }
129
+
130
+ // Get balance
131
+ const balance = await wallet.getBalance();
132
+ console.log('Balance:', formatBalance(balance), 'RLO');
133
+
134
+ // Sign message
135
+ const signed = await wallet.signMessage('Hello!');
136
+
137
+ // Send transaction
138
+ const tx = await wallet.signAndSendTransaction({
139
+ to: 'RecipientAddress...',
140
+ value: '1000000000', // 1 RLO in kelvins
141
+ });
142
+ console.log('TX Hash:', tx.hash);
143
+
144
+ // Silent session check (for auto-connect, never triggers approval)
145
+ const existingSession = await wallet.checkSession();
146
+ if (existingSession) {
147
+ console.log('Session restored:', existingSession[0].address);
148
+ }
149
+ ```
150
+
151
+ ## Direct Provider Access
152
+
153
+ ```typescript
154
+ // Access window.rialo directly
155
+ if (window.rialo) {
156
+ const accounts = await window.rialo.connect();
157
+ const balance = await window.rialo.getBalance();
158
+ const tx = await window.rialo.signAndSendTransaction({
159
+ to: 'RecipientAddress...',
160
+ value: '1000000000',
161
+ });
162
+ }
104
163
  ```
105
164
 
106
165
  ## Components
@@ -114,22 +173,17 @@ const { send, sending, txHash, error, reset } = useSendTransaction();
114
173
  showAddress={true}
115
174
  showBalance={false}
116
175
  className="my-button"
176
+ style={{ backgroundColor: '#6EB9A8' }}
117
177
  />
118
178
  ```
119
179
 
120
- ### WalletModal
121
-
122
- ```tsx
123
- <WalletModal title="Select Wallet" className="my-modal" />
124
- ```
125
-
126
180
  ### WalletProvider
127
181
 
128
182
  ```tsx
129
183
  <WalletProvider
130
- network="devnet"
131
- autoConnect={true}
132
- wallets={[customWallet]}
184
+ network="devnet" // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
185
+ autoConnect={true} // Restore session silently on mount
186
+ wallets={[customWallet]} // Additional wallets to show
133
187
  onConnect={(accounts) => console.log('Connected', accounts)}
134
188
  onDisconnect={() => console.log('Disconnected')}
135
189
  onNetworkChange={(network) => console.log('Network:', network)}
@@ -144,22 +198,19 @@ const { send, sending, txHash, error, reset } = useSendTransaction();
144
198
  ```tsx
145
199
  import {
146
200
  WalletErrorBoundary,
147
- SafeWalletProvider,
148
201
  ApprovalPending,
149
202
  LoadingSpinner,
150
203
  ConnectionStatus,
151
204
  } from '@cookill/wallet-adapter/react';
152
205
 
153
- // Option 1: Error Boundary wrapper
154
- <WalletErrorBoundary fallback={<CustomError />} onError={logError}>
206
+ // Error Boundary
207
+ <WalletErrorBoundary
208
+ fallback={<CustomError />}
209
+ onError={(error, info) => logError(error)}
210
+ >
155
211
  <WalletProvider>...</WalletProvider>
156
212
  </WalletErrorBoundary>
157
213
 
158
- // Option 2: SafeWalletProvider (includes boundary)
159
- <SafeWalletProvider network="devnet" errorFallback={<CustomError />}>
160
- ...
161
- </SafeWalletProvider>
162
-
163
214
  // Loading states
164
215
  <ApprovalPending
165
216
  title="Waiting for Approval"
@@ -172,44 +223,9 @@ import {
172
223
 
173
224
  <ConnectionStatus status="connecting" />
174
225
  <ConnectionStatus status="approving" message="Check your wallet" />
175
- <ConnectionStatus status="signing" />
176
- <ConnectionStatus status="success" />
177
226
  <ConnectionStatus status="error" onRetry={() => connect()} />
178
227
  ```
179
228
 
180
- ## Vanilla JavaScript
181
-
182
- ```typescript
183
- import { RialoWallet, isRialoInstalled, formatBalance } from '@cookill/wallet-adapter';
184
-
185
- const wallet = new RialoWallet();
186
-
187
- if (!isRialoInstalled()) {
188
- console.log('Please install Sheep Wallet');
189
- }
190
-
191
- const accounts = await wallet.connect();
192
- const balance = await wallet.getBalance();
193
- const signed = await wallet.signMessage('Hello!');
194
- const tx = await wallet.signAndSendTransaction({
195
- to: 'RecipientAddress...',
196
- value: '1000000000', // 1 RLO in kelvins
197
- });
198
- ```
199
-
200
- ## Direct Provider Access
201
-
202
- ```typescript
203
- if (window.rialo) {
204
- const accounts = await window.rialo.connect();
205
- const balance = await window.rialo.getBalance();
206
- const tx = await window.rialo.signAndSendTransaction({
207
- to: 'RecipientAddress...',
208
- value: '1000000000',
209
- });
210
- }
211
- ```
212
-
213
229
  ## Networks
214
230
 
215
231
  | Network | Chain ID | RPC URL | Symbol |
@@ -229,9 +245,9 @@ import {
229
245
  isValidAddress, // (address) => boolean
230
246
  toChainId, // (network) => 'rialo:devnet'
231
247
  fromChainId, // (chainId) => 'devnet'
232
- isRialoInstalled, // () => boolean
233
- getRialoProvider, // () => RialoProvider | undefined
234
- waitForRialoProvider, // (timeout?) => Promise<RialoProvider>
248
+ isInstalled, // () => boolean
249
+ getProvider, // () => RialoProvider | undefined
250
+ waitForProvider, // (timeout?) => Promise<RialoProvider | undefined>
235
251
  NETWORKS, // Network configurations
236
252
  } from '@cookill/wallet-adapter';
237
253
  ```
@@ -249,10 +265,50 @@ import type {
249
265
  WalletInfo,
250
266
  RialoProvider,
251
267
  RialoNetwork,
252
- RialoChain,
268
+ RialoChainId,
253
269
  } from '@cookill/wallet-adapter';
254
270
  ```
255
271
 
272
+ ## Troubleshooting
273
+
274
+ ### Connection hangs / freezes
275
+
276
+ v3.0 has built-in 20-second timeout. If connection still hangs:
277
+
278
+ 1. Make sure extension is installed and unlocked
279
+ 2. Check if popup was blocked by browser
280
+ 3. Try refreshing the page
281
+
282
+ ### Auto-connect not working
283
+
284
+ Auto-connect uses `checkSession()` which only restores **existing** sessions silently.
285
+ It won't trigger the approval popup. User must explicitly call `connect()` first time.
286
+
287
+ ### Modal not opening
288
+
289
+ The `WalletProvider` renders the modal automatically. If you see issues:
290
+
291
+ ```tsx
292
+ // Make sure you're inside WalletProvider
293
+ const { openModal } = useWallet();
294
+ openModal(); // This should work
295
+ ```
296
+
297
+ ## Migration from v2.x
298
+
299
+ ```diff
300
+ // Imports are the same
301
+ import { WalletProvider, ConnectButton } from '@cookill/wallet-adapter/react';
302
+
303
+ // Hook usage is the same
304
+ const { connect, connected } = useWallet();
305
+
306
+ // Main changes:
307
+ // - connect() now has 20s timeout built-in
308
+ // - autoConnect uses checkSession() (silent, never triggers popup)
309
+ // - New SheepWallet class for vanilla JS (replaces RialoWallet)
310
+ ```
311
+
256
312
  ## License
257
313
 
258
314
  MIT
@@ -1,107 +1,70 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var react = require('react');
6
4
  var jsxRuntime = require('react/jsx-runtime');
7
5
 
8
- // src/ErrorBoundary.tsx
9
6
  var WalletErrorBoundary = class extends react.Component {
10
- constructor() {
11
- super(...arguments);
12
- this.state = {
13
- hasError: false,
14
- error: null
15
- };
16
- this.handleRetry = () => {
7
+ constructor(props) {
8
+ super(props);
9
+ this.handleReset = () => {
17
10
  this.setState({ hasError: false, error: null });
18
11
  };
12
+ this.state = { hasError: false, error: null };
19
13
  }
20
14
  static getDerivedStateFromError(error) {
21
15
  return { hasError: true, error };
22
16
  }
23
17
  componentDidCatch(error, errorInfo) {
24
- console.error("[WalletAdapter] Error caught by boundary:", error, errorInfo);
18
+ console.error("[WalletErrorBoundary] Caught error:", error, errorInfo);
25
19
  this.props.onError?.(error, errorInfo);
26
20
  }
27
21
  render() {
28
- if (this.state.hasError) {
29
- if (this.props.fallback) {
30
- return this.props.fallback;
22
+ if (this.state.hasError && this.state.error) {
23
+ const { fallback } = this.props;
24
+ if (typeof fallback === "function") {
25
+ return fallback(this.state.error, this.handleReset);
26
+ }
27
+ if (fallback) {
28
+ return fallback;
31
29
  }
32
- return /* @__PURE__ */ jsxRuntime.jsxs(
33
- "div",
34
- {
35
- style: {
36
- padding: "20px",
37
- borderRadius: "12px",
38
- border: "1px solid #fee2e2",
39
- backgroundColor: "#fef2f2",
40
- textAlign: "center"
41
- },
42
- children: [
43
- /* @__PURE__ */ jsxRuntime.jsx(
44
- "div",
45
- {
46
- style: {
47
- width: "48px",
48
- height: "48px",
49
- margin: "0 auto 12px",
50
- borderRadius: "50%",
51
- backgroundColor: "#fecaca",
52
- display: "flex",
53
- alignItems: "center",
54
- justifyContent: "center"
55
- },
56
- children: /* @__PURE__ */ jsxRuntime.jsxs(
57
- "svg",
58
- {
59
- width: "24",
60
- height: "24",
61
- viewBox: "0 0 24 24",
62
- fill: "none",
63
- stroke: "#dc2626",
64
- strokeWidth: "2",
65
- strokeLinecap: "round",
66
- strokeLinejoin: "round",
67
- children: [
68
- /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
69
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
70
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
71
- ]
72
- }
73
- )
74
- }
75
- ),
76
- /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
77
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
78
- /* @__PURE__ */ jsxRuntime.jsx(
79
- "button",
80
- {
81
- onClick: this.handleRetry,
82
- style: {
83
- padding: "8px 16px",
84
- borderRadius: "8px",
85
- border: "none",
86
- backgroundColor: "#dc2626",
87
- color: "white",
88
- cursor: "pointer",
89
- fontSize: "14px",
90
- fontWeight: 500
91
- },
92
- children: "Try Again"
93
- }
94
- )
95
- ]
96
- }
97
- );
30
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: {
31
+ padding: "20px",
32
+ margin: "10px",
33
+ backgroundColor: "#1a1a2e",
34
+ border: "1px solid #ef4444",
35
+ borderRadius: "12px",
36
+ color: "#ffffff"
37
+ }, children: [
38
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { color: "#ef4444", margin: "0 0 12px 0" }, children: "Wallet Connection Error" }),
39
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "#94a3b8", margin: "0 0 16px 0", fontSize: "14px" }, children: this.state.error.message }),
40
+ /* @__PURE__ */ jsxRuntime.jsx(
41
+ "button",
42
+ {
43
+ onClick: this.handleReset,
44
+ style: {
45
+ padding: "8px 16px",
46
+ backgroundColor: "#6EB9A8",
47
+ color: "#011B29",
48
+ border: "none",
49
+ borderRadius: "8px",
50
+ cursor: "pointer",
51
+ fontWeight: 500
52
+ },
53
+ children: "Try Again"
54
+ }
55
+ )
56
+ ] });
98
57
  }
99
58
  return this.props.children;
100
59
  }
101
60
  };
102
- var ErrorBoundary_default = WalletErrorBoundary;
61
+ function withWalletErrorBoundary(WrappedComponent, fallback) {
62
+ return function WithErrorBoundary(props) {
63
+ return /* @__PURE__ */ jsxRuntime.jsx(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(WrappedComponent, { ...props }) });
64
+ };
65
+ }
103
66
 
104
67
  exports.WalletErrorBoundary = WalletErrorBoundary;
105
- exports.default = ErrorBoundary_default;
68
+ exports.withWalletErrorBoundary = withWalletErrorBoundary;
106
69
  //# sourceMappingURL=ErrorBoundary.cjs.map
107
70
  //# sourceMappingURL=ErrorBoundary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ErrorBoundary.tsx"],"names":["Component","jsxs","jsx"],"mappings":";;;;;;;;AAkBO,IAAM,mBAAA,GAAN,cAAkCA,eAAA,CAAwB;AAAA,EAA1D,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACL,IAAA,IAAA,CAAO,KAAA,GAAe;AAAA,MACpB,QAAA,EAAU,KAAA;AAAA,MACV,KAAA,EAAO;AAAA,KACT;AAWA,IAAA,IAAA,CAAQ,cAAc,MAAM;AAC1B,MAAA,IAAA,CAAK,SAAS,EAAE,QAAA,EAAU,KAAA,EAAO,KAAA,EAAO,MAAM,CAAA;AAAA,IAChD,CAAA;AAAA,EAAA;AAAA,EAXA,OAAc,yBAAyB,KAAA,EAAqB;AAC1D,IAAA,OAAO,EAAE,QAAA,EAAU,IAAA,EAAM,KAAA,EAAM;AAAA,EACjC;AAAA,EAEO,iBAAA,CAAkB,OAAc,SAAA,EAAsB;AAC3D,IAAA,OAAA,CAAQ,KAAA,CAAM,2CAAA,EAA6C,KAAA,EAAO,SAAS,CAAA;AAC3E,IAAA,IAAA,CAAK,KAAA,CAAM,OAAA,GAAU,KAAA,EAAO,SAAS,CAAA;AAAA,EACvC;AAAA,EAMO,MAAA,GAAS;AACd,IAAA,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,EAAI,EAAA,EAAG,IAAA,EAAK,EAAA,EAAG,IAAA,EAAK,CAAA;AAAA,sCACrCA,cAAA,CAAC,UAAK,EAAA,EAAG,IAAA,EAAK,IAAG,IAAA,EAAK,EAAA,EAAG,OAAA,EAAQ,EAAA,EAAG,IAAA,EAAK;AAAA;AAAA;AAAA;AAC3C;AAAA,aACF;AAAA,4BACAA,cAAA,CAAC,IAAA,EAAA,EAAG,KAAA,EAAO,EAAE,MAAA,EAAQ,SAAA,EAAW,QAAA,EAAU,MAAA,EAAQ,UAAA,EAAY,GAAA,EAAK,KAAA,EAAO,SAAA,IAAa,QAAA,EAAA,yBAAA,EAEvF,CAAA;AAAA,4BACAA,cAAA,CAAC,GAAA,EAAA,EAAE,KAAA,EAAO,EAAE,QAAQ,UAAA,EAAY,QAAA,EAAU,MAAA,EAAQ,KAAA,EAAO,WAAU,EAChE,QAAA,EAAA,IAAA,CAAK,KAAA,CAAM,KAAA,EAAO,WAAW,sBAAA,EAChC,CAAA;AAAA,4BACAA,cAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,SAAS,IAAA,CAAK,WAAA;AAAA,gBACd,KAAA,EAAO;AAAA,kBACL,OAAA,EAAS,UAAA;AAAA,kBACT,YAAA,EAAc,KAAA;AAAA,kBACd,MAAA,EAAQ,MAAA;AAAA,kBACR,eAAA,EAAiB,SAAA;AAAA,kBACjB,KAAA,EAAO,OAAA;AAAA,kBACP,MAAA,EAAQ,SAAA;AAAA,kBACR,QAAA,EAAU,MAAA;AAAA,kBACV,UAAA,EAAY;AAAA,iBACd;AAAA,gBACD,QAAA,EAAA;AAAA;AAAA;AAED;AAAA;AAAA,OACF;AAAA,IAEJ;AAEA,IAAA,OAAO,KAAK,KAAA,CAAM,QAAA;AAAA,EACpB;AACF;AAEA,IAAO,qBAAA,GAAQ","file":"ErrorBoundary.cjs","sourcesContent":["/**\n * @cookill/wallet-adapter - Error Boundary\n * Prevents blank screens from uncaught errors\n */\n\nimport React, { Component, ErrorInfo, ReactNode } from 'react';\n\ninterface Props {\n children: ReactNode;\n fallback?: ReactNode;\n onError?: (error: Error, errorInfo: ErrorInfo) => void;\n}\n\ninterface State {\n hasError: boolean;\n error: Error | null;\n}\n\nexport class WalletErrorBoundary extends Component<Props, State> {\n public state: State = {\n hasError: false,\n error: null,\n };\n\n public static getDerivedStateFromError(error: Error): State {\n return { hasError: true, error };\n }\n\n public componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n console.error('[WalletAdapter] Error caught by boundary:', error, errorInfo);\n this.props.onError?.(error, errorInfo);\n }\n\n private handleRetry = () => {\n this.setState({ hasError: false, error: null });\n };\n\n public render() {\n if (this.state.hasError) {\n if (this.props.fallback) {\n return this.props.fallback;\n }\n\n return (\n <div\n style={{\n padding: '20px',\n borderRadius: '12px',\n border: '1px solid #fee2e2',\n backgroundColor: '#fef2f2',\n textAlign: 'center',\n }}\n >\n <div\n style={{\n width: '48px',\n height: '48px',\n margin: '0 auto 12px',\n borderRadius: '50%',\n backgroundColor: '#fecaca',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n }}\n >\n <svg\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"#dc2626\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"12\" />\n <line x1=\"12\" y1=\"16\" x2=\"12.01\" y2=\"16\" />\n </svg>\n </div>\n <h3 style={{ margin: '0 0 8px', fontSize: '16px', fontWeight: 600, color: '#991b1b' }}>\n Wallet Connection Error\n </h3>\n <p style={{ margin: '0 0 16px', fontSize: '14px', color: '#b91c1c' }}>\n {this.state.error?.message || 'Something went wrong'}\n </p>\n <button\n onClick={this.handleRetry}\n style={{\n padding: '8px 16px',\n borderRadius: '8px',\n border: 'none',\n backgroundColor: '#dc2626',\n color: 'white',\n cursor: 'pointer',\n fontSize: '14px',\n fontWeight: 500,\n }}\n >\n Try Again\n </button>\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n\nexport default WalletErrorBoundary;\n"]}
1
+ {"version":3,"sources":["../src/react/ErrorBoundary.tsx"],"names":["Component","jsxs","jsx"],"mappings":";;;;;AAkBO,IAAM,mBAAA,GAAN,cAAkCA,eAAA,CAA2C;AAAA,EAClF,YAAY,KAAA,EAAiC;AAC3C,IAAA,KAAA,CAAM,KAAK,CAAA;AAab,IAAA,IAAA,CAAA,WAAA,GAAc,MAAY;AACxB,MAAA,IAAA,CAAK,SAAS,EAAE,QAAA,EAAU,KAAA,EAAO,KAAA,EAAO,MAAM,CAAA;AAAA,IAChD,CAAA;AAdE,IAAA,IAAA,CAAK,KAAA,GAAQ,EAAE,QAAA,EAAU,KAAA,EAAO,OAAO,IAAA,EAAK;AAAA,EAC9C;AAAA,EAEA,OAAO,yBAAyB,KAAA,EAAqB;AACnD,IAAA,OAAO,EAAE,QAAA,EAAU,IAAA,EAAM,KAAA,EAAM;AAAA,EACjC;AAAA,EAEA,iBAAA,CAAkB,OAAc,SAAA,EAA4B;AAC1D,IAAA,OAAA,CAAQ,KAAA,CAAM,qCAAA,EAAuC,KAAA,EAAO,SAAS,CAAA;AACrE,IAAA,IAAA,CAAK,KAAA,CAAM,OAAA,GAAU,KAAA,EAAO,SAAS,CAAA;AAAA,EACvC;AAAA,EAMA,MAAA,GAAoB;AAClB,IAAA,IAAI,IAAA,CAAK,KAAA,CAAM,QAAA,IAAY,IAAA,CAAK,MAAM,KAAA,EAAO;AAC3C,MAAA,MAAM,EAAE,QAAA,EAAS,GAAI,IAAA,CAAK,KAAA;AAE1B,MAAA,IAAI,OAAO,aAAa,UAAA,EAAY;AAClC,QAAA,OAAO,QAAA,CAAS,IAAA,CAAK,KAAA,CAAM,KAAA,EAAO,KAAK,WAAW,CAAA;AAAA,MACpD;AAEA,MAAA,IAAI,QAAA,EAAU;AACZ,QAAA,OAAO,QAAA;A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AAA,EAEJ,CAAA;AACF","file":"ErrorBoundary.cjs","sourcesContent":["/**\n * @cookill/wallet-adapter/react v3.0.0\n * Error Boundary for wallet integration\n */\n\nimport React, { Component, type ReactNode, type ErrorInfo } from 'react';\n\nexport interface WalletErrorBoundaryProps {\n children: ReactNode;\n fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);\n onError?: (error: Error, errorInfo: ErrorInfo) => void;\n}\n\ninterface State {\n hasError: boolean;\n error: Error | null;\n}\n\nexport class WalletErrorBoundary extends Component<WalletErrorBoundaryProps, State> {\n constructor(props: WalletErrorBoundaryProps) {\n super(props);\n this.state = { hasError: false, error: null };\n }\n\n static getDerivedStateFromError(error: Error): State {\n return { hasError: true, error };\n }\n\n componentDidCatch(error: Error, errorInfo: ErrorInfo): void {\n console.error('[WalletErrorBoundary] Caught error:', error, errorInfo);\n this.props.onError?.(error, errorInfo);\n }\n\n handleReset = (): void => {\n this.setState({ hasError: false, error: null });\n };\n\n render(): ReactNode {\n if (this.state.hasError && this.state.error) {\n const { fallback } = this.props;\n \n if (typeof fallback === 'function') {\n return fallback(this.state.error, this.handleReset);\n }\n \n if (fallback) {\n return fallback;\n }\n\n return (\n <div style={{\n padding: '20px',\n margin: '10px',\n backgroundColor: '#1a1a2e',\n border: '1px solid #ef4444',\n borderRadius: '12px',\n color: '#ffffff',\n }}>\n <h3 style={{ color: '#ef4444', margin: '0 0 12px 0' }}>\n Wallet Connection Error\n </h3>\n <p style={{ color: '#94a3b8', margin: '0 0 16px 0', fontSize: '14px' }}>\n {this.state.error.message}\n </p>\n <button\n onClick={this.handleReset}\n style={{\n padding: '8px 16px',\n backgroundColor: '#6EB9A8',\n color: '#011B29',\n border: 'none',\n borderRadius: '8px',\n cursor: 'pointer',\n fontWeight: 500,\n }}\n >\n Try Again\n </button>\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n\n/**\n * HOC to wrap components with error boundary\n */\nexport function withWalletErrorBoundary<P extends object>(\n WrappedComponent: React.ComponentType<P>,\n fallback?: WalletErrorBoundaryProps['fallback']\n) {\n return function WithErrorBoundary(props: P) {\n return (\n <WalletErrorBoundary fallback={fallback}>\n <WrappedComponent {...props} />\n </WalletErrorBoundary>\n );\n };\n}\n\nexport default WalletErrorBoundary;\n"]}
@@ -1,21 +1,25 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React, { Component, ReactNode, ErrorInfo } from 'react';
3
3
 
4
- interface Props {
4
+ interface WalletErrorBoundaryProps {
5
5
  children: ReactNode;
6
- fallback?: ReactNode;
6
+ fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);
7
7
  onError?: (error: Error, errorInfo: ErrorInfo) => void;
8
8
  }
9
9
  interface State {
10
10
  hasError: boolean;
11
11
  error: Error | null;
12
12
  }
13
- declare class WalletErrorBoundary extends Component<Props, State> {
14
- state: State;
13
+ declare class WalletErrorBoundary extends Component<WalletErrorBoundaryProps, State> {
14
+ constructor(props: WalletErrorBoundaryProps);
15
15
  static getDerivedStateFromError(error: Error): State;
16
16
  componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
17
- private handleRetry;
18
- render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
17
+ handleReset: () => void;
18
+ render(): ReactNode;
19
19
  }
20
+ /**
21
+ * HOC to wrap components with error boundary
22
+ */
23
+ declare function withWalletErrorBoundary<P extends object>(WrappedComponent: React.ComponentType<P>, fallback?: WalletErrorBoundaryProps['fallback']): (props: P) => react_jsx_runtime.JSX.Element;
20
24
 
21
- export { WalletErrorBoundary, WalletErrorBoundary as default };
25
+ export { WalletErrorBoundary, type WalletErrorBoundaryProps, withWalletErrorBoundary };
@@ -1,21 +1,25 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React, { Component, ReactNode, ErrorInfo } from 'react';
3
3
 
4
- interface Props {
4
+ interface WalletErrorBoundaryProps {
5
5
  children: ReactNode;
6
- fallback?: ReactNode;
6
+ fallback?: ReactNode | ((error: Error, reset: () => void) => ReactNode);
7
7
  onError?: (error: Error, errorInfo: ErrorInfo) => void;
8
8
  }
9
9
  interface State {
10
10
  hasError: boolean;
11
11
  error: Error | null;
12
12
  }
13
- declare class WalletErrorBoundary extends Component<Props, State> {
14
- state: State;
13
+ declare class WalletErrorBoundary extends Component<WalletErrorBoundaryProps, State> {
14
+ constructor(props: WalletErrorBoundaryProps);
15
15
  static getDerivedStateFromError(error: Error): State;
16
16
  componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
17
- private handleRetry;
18
- render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element | null | undefined;
17
+ handleReset: () => void;
18
+ render(): ReactNode;
19
19
  }
20
+ /**
21
+ * HOC to wrap components with error boundary
22
+ */
23
+ declare function withWalletErrorBoundary<P extends object>(WrappedComponent: React.ComponentType<P>, fallback?: WalletErrorBoundaryProps['fallback']): (props: P) => react_jsx_runtime.JSX.Element;
20
24
 
21
- export { WalletErrorBoundary, WalletErrorBoundary as default };
25
+ export { WalletErrorBoundary, type WalletErrorBoundaryProps, withWalletErrorBoundary };