@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 +178 -122
- package/dist/ErrorBoundary.cjs +45 -82
- package/dist/ErrorBoundary.cjs.map +1 -1
- package/dist/ErrorBoundary.d.cts +11 -7
- package/dist/ErrorBoundary.d.ts +11 -7
- package/dist/ErrorBoundary.js +45 -80
- package/dist/ErrorBoundary.js.map +1 -1
- package/dist/LoadingStates.cjs +124 -235
- package/dist/LoadingStates.cjs.map +1 -1
- package/dist/LoadingStates.d.cts +11 -15
- package/dist/LoadingStates.d.ts +11 -15
- package/dist/LoadingStates.js +125 -233
- package/dist/LoadingStates.js.map +1 -1
- package/dist/index.cjs +275 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -63
- package/dist/index.d.ts +111 -63
- package/dist/index.js +265 -111
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +245 -1005
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -118
- package/dist/react.d.ts +1 -118
- package/dist/react.js +243 -978
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +115 -81
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +6 -44
- package/dist/standard.d.ts +6 -44
- package/dist/standard.js +116 -81
- package/dist/standard.js.map +1 -1
- package/package.json +42 -35
package/README.md
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
# @cookill/wallet-adapter
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
const {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const {
|
|
103
|
-
const {
|
|
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
|
-
//
|
|
154
|
-
<WalletErrorBoundary
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
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
|
package/dist/ErrorBoundary.cjs
CHANGED
|
@@ -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(
|
|
12
|
-
this.
|
|
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("[
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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.
|
|
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":"
|
|
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;AAAA,MACT;AAEA,MAAA,uBACEC,eAAA,CAAC,SAAI,KAAA,EAAO;AAAA,QACV,OAAA,EAAS,MAAA;AAAA,QACT,MAAA,EAAQ,MAAA;AAAA,QACR,eAAA,EAAiB,SAAA;AAAA,QACjB,MAAA,EAAQ,mBAAA;AAAA,QACR,YAAA,EAAc,MAAA;AAAA,QACd,KAAA,EAAO;AAAA,OACT,EACE,QAAA,EAAA;AAAA,wBAAAC,cAAA,CAAC,IAAA,EAAA,EAAG,OAAO,EAAE,KAAA,EAAO,WAAW,MAAA,EAAQ,YAAA,IAAgB,QAAA,EAAA,yBAAA,EAEvD,CAAA;AAAA,wBACAA,cAAA,CAAC,GAAA,EAAA,EAAE,KAAA,EAAO,EAAE,OAAO,SAAA,EAAW,MAAA,EAAQ,YAAA,EAAc,QAAA,EAAU,MAAA,EAAO,EAClE,QAAA,EAAA,IAAA,CAAK,KAAA,CAAM,MAAM,OAAA,EACpB,CAAA;AAAA,wBACAA,cAAA;AAAA,UAAC,QAAA;AAAA,UAAA;AAAA,YACC,SAAS,IAAA,CAAK,WAAA;AAAA,YACd,KAAA,EAAO;AAAA,cACL,OAAA,EAAS,UAAA;AAAA,cACT,eAAA,EAAiB,SAAA;AAAA,cACjB,KAAA,EAAO,SAAA;AAAA,cACP,MAAA,EAAQ,MAAA;AAAA,cACR,YAAA,EAAc,KAAA;AAAA,cACd,MAAA,EAAQ,SAAA;AAAA,cACR,UAAA,EAAY;AAAA,aACd;AAAA,YACD,QAAA,EAAA;AAAA;AAAA;AAED,OAAA,EACF,CAAA;AAAA,IAEJ;AAEA,IAAA,OAAO,KAAK,KAAA,CAAM,QAAA;AAAA,EACpB;AACF;AAKO,SAAS,uBAAA,CACd,kBACA,QAAA,EACA;AACA,EAAA,OAAO,SAAS,kBAAkB,KAAA,EAAU;AAC1C,IAAA,sCACG,mBAAA,EAAA,EAAoB,QAAA,EACnB,yCAAC,gBAAA,EAAA,EAAkB,GAAG,OAAO,CAAA,EAC/B,CAAA;AAAA,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"]}
|
package/dist/ErrorBoundary.d.cts
CHANGED
|
@@ -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
|
|
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<
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
render():
|
|
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,
|
|
25
|
+
export { WalletErrorBoundary, type WalletErrorBoundaryProps, withWalletErrorBoundary };
|
package/dist/ErrorBoundary.d.ts
CHANGED
|
@@ -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
|
|
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<
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
render():
|
|
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,
|
|
25
|
+
export { WalletErrorBoundary, type WalletErrorBoundaryProps, withWalletErrorBoundary };
|