@cookill/wallet-adapter 2.5.4 → 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 +155 -165
- package/dist/ErrorBoundary.cjs +53 -110
- 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 +50 -85
- package/dist/ErrorBoundary.js.map +1 -1
- package/dist/LoadingStates.cjs +134 -267
- 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 +129 -239
- package/dist/LoadingStates.js.map +1 -1
- package/dist/index.cjs +287 -158
- 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 +267 -124
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +251 -1030
- 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 -975
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +127 -121
- 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 +118 -91
- package/dist/standard.js.map +1 -1
- package/package.json +42 -36
package/README.md
CHANGED
|
@@ -1,48 +1,28 @@
|
|
|
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
|
-
##
|
|
12
|
-
|
|
13
|
-
**If you're using Vite**, you MUST add React deduplication to prevent "stuck connection" issues:
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
// vite.config.ts
|
|
17
|
-
import { defineConfig } from "vite";
|
|
18
|
-
import react from "@vitejs/plugin-react";
|
|
19
|
-
import path from "path";
|
|
20
|
-
|
|
21
|
-
export default defineConfig({
|
|
22
|
-
plugins: [react()],
|
|
23
|
-
resolve: {
|
|
24
|
-
alias: {
|
|
25
|
-
"@": path.resolve(__dirname, "./src"),
|
|
26
|
-
},
|
|
27
|
-
// CRITICAL: Prevent duplicate React instances
|
|
28
|
-
dedupe: ["react", "react-dom", "react/jsx-runtime"],
|
|
29
|
-
},
|
|
30
|
-
optimizeDeps: {
|
|
31
|
-
include: ["react", "react-dom"],
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**Without this configuration**, the wallet modal may not open and connections will appear "stuck".
|
|
37
|
-
|
|
38
|
-
## Quick Start
|
|
22
|
+
## Quick Start (React)
|
|
39
23
|
|
|
40
24
|
```tsx
|
|
41
|
-
import {
|
|
42
|
-
WalletProvider,
|
|
43
|
-
ConnectButton,
|
|
44
|
-
WalletErrorBoundary,
|
|
45
|
-
} from '@cookill/wallet-adapter/react';
|
|
25
|
+
import { WalletProvider, ConnectButton, WalletErrorBoundary } from '@cookill/wallet-adapter/react';
|
|
46
26
|
|
|
47
27
|
function App() {
|
|
48
28
|
return (
|
|
@@ -60,22 +40,18 @@ function App() {
|
|
|
60
40
|
|
|
61
41
|
### useWallet
|
|
62
42
|
|
|
63
|
-
Main hook for wallet state and actions:
|
|
64
|
-
|
|
65
43
|
```tsx
|
|
66
44
|
import { useWallet } from '@cookill/wallet-adapter/react';
|
|
67
45
|
|
|
68
46
|
function MyComponent() {
|
|
69
47
|
const {
|
|
70
48
|
// State
|
|
71
|
-
connected, // boolean
|
|
72
|
-
connecting, // boolean
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
network, // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
49
|
+
connected, // boolean
|
|
50
|
+
connecting, // boolean
|
|
51
|
+
activeAccount, // WalletAccount | null
|
|
52
|
+
state, // Full state object
|
|
76
53
|
chainId, // 'rialo:devnet' etc
|
|
77
|
-
|
|
78
|
-
error, // Error | null
|
|
54
|
+
isInstalled, // boolean
|
|
79
55
|
|
|
80
56
|
// Actions
|
|
81
57
|
connect, // () => Promise<WalletAccount[]>
|
|
@@ -90,7 +66,6 @@ function MyComponent() {
|
|
|
90
66
|
signAndSendTransaction, // (tx) => Promise<TransactionResult>
|
|
91
67
|
|
|
92
68
|
// Modal
|
|
93
|
-
isModalOpen,
|
|
94
69
|
openModal,
|
|
95
70
|
closeModal,
|
|
96
71
|
} = useWallet();
|
|
@@ -100,54 +75,97 @@ function MyComponent() {
|
|
|
100
75
|
{connected ? (
|
|
101
76
|
<p>Connected: {activeAccount?.address}</p>
|
|
102
77
|
) : (
|
|
103
|
-
<button onClick={
|
|
78
|
+
<button onClick={connect}>Connect</button>
|
|
104
79
|
)}
|
|
105
80
|
</div>
|
|
106
81
|
);
|
|
107
82
|
}
|
|
108
83
|
```
|
|
109
84
|
|
|
110
|
-
###
|
|
85
|
+
### Specialized Hooks
|
|
111
86
|
|
|
112
87
|
```tsx
|
|
113
|
-
//
|
|
88
|
+
// Connection
|
|
89
|
+
const { connect, connecting, isInstalled, error } = useConnectWallet();
|
|
90
|
+
const { disconnect, connected } = useDisconnectWallet();
|
|
114
91
|
const connected = useIsConnected();
|
|
115
92
|
|
|
116
|
-
//
|
|
93
|
+
// Account
|
|
117
94
|
const account = useActiveAccount();
|
|
118
|
-
|
|
119
|
-
// Get all accounts
|
|
120
95
|
const accounts = useAccounts();
|
|
121
96
|
|
|
122
|
-
// Balance
|
|
123
|
-
const { balance,
|
|
124
|
-
// formatted: "1,234.5678 RLO"
|
|
97
|
+
// Balance
|
|
98
|
+
const { balance, refresh } = useBalance();
|
|
125
99
|
|
|
126
|
-
// Network
|
|
127
|
-
const { network, chainId
|
|
100
|
+
// Network
|
|
101
|
+
const { network, chainId } = useNetwork();
|
|
102
|
+
const { switchNetwork, network } = useSwitchNetwork();
|
|
128
103
|
|
|
129
|
-
//
|
|
130
|
-
const {
|
|
104
|
+
// Transactions
|
|
105
|
+
const { signMessage, connected } = useSignMessage();
|
|
106
|
+
const { sendTransaction, signAndSendTransaction, connected } = useSendTransaction();
|
|
107
|
+
```
|
|
131
108
|
|
|
132
|
-
|
|
133
|
-
const { connect, connecting, isInstalled, error } = useConnectWallet();
|
|
109
|
+
## Vanilla JavaScript
|
|
134
110
|
|
|
135
|
-
|
|
136
|
-
|
|
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);
|
|
137
143
|
|
|
138
|
-
//
|
|
139
|
-
const
|
|
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
|
|
140
152
|
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
143
163
|
```
|
|
144
164
|
|
|
145
165
|
## Components
|
|
146
166
|
|
|
147
167
|
### ConnectButton
|
|
148
168
|
|
|
149
|
-
Pre-styled connect button:
|
|
150
|
-
|
|
151
169
|
```tsx
|
|
152
170
|
<ConnectButton
|
|
153
171
|
connectLabel="Connect Wallet"
|
|
@@ -155,17 +173,17 @@ Pre-styled connect button:
|
|
|
155
173
|
showAddress={true}
|
|
156
174
|
showBalance={false}
|
|
157
175
|
className="my-button"
|
|
176
|
+
style={{ backgroundColor: '#6EB9A8' }}
|
|
158
177
|
/>
|
|
159
178
|
```
|
|
160
179
|
|
|
161
180
|
### WalletProvider
|
|
162
181
|
|
|
163
|
-
Wrap your app to provide wallet context:
|
|
164
|
-
|
|
165
182
|
```tsx
|
|
166
183
|
<WalletProvider
|
|
167
|
-
network="devnet"
|
|
168
|
-
autoConnect={true}
|
|
184
|
+
network="devnet" // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
185
|
+
autoConnect={true} // Restore session silently on mount
|
|
186
|
+
wallets={[customWallet]} // Additional wallets to show
|
|
169
187
|
onConnect={(accounts) => console.log('Connected', accounts)}
|
|
170
188
|
onDisconnect={() => console.log('Disconnected')}
|
|
171
189
|
onNetworkChange={(network) => console.log('Network:', network)}
|
|
@@ -175,71 +193,37 @@ Wrap your app to provide wallet context:
|
|
|
175
193
|
</WalletProvider>
|
|
176
194
|
```
|
|
177
195
|
|
|
178
|
-
###
|
|
179
|
-
|
|
180
|
-
Prevents blank screens from uncaught errors:
|
|
196
|
+
### Error Boundary & Loading States
|
|
181
197
|
|
|
182
198
|
```tsx
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
import {
|
|
200
|
+
WalletErrorBoundary,
|
|
201
|
+
ApprovalPending,
|
|
202
|
+
LoadingSpinner,
|
|
203
|
+
ConnectionStatus,
|
|
204
|
+
} from '@cookill/wallet-adapter/react';
|
|
205
|
+
|
|
206
|
+
// Error Boundary
|
|
207
|
+
<WalletErrorBoundary
|
|
208
|
+
fallback={<CustomError />}
|
|
209
|
+
onError={(error, info) => logError(error)}
|
|
186
210
|
>
|
|
187
|
-
<
|
|
211
|
+
<WalletProvider>...</WalletProvider>
|
|
188
212
|
</WalletErrorBoundary>
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Vanilla JavaScript (Non-React)
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
import { RialoWallet, isRialoInstalled, formatBalance } from '@cookill/wallet-adapter';
|
|
195
|
-
|
|
196
|
-
// Check if extension is installed
|
|
197
|
-
if (!isRialoInstalled()) {
|
|
198
|
-
console.log('Please install Sheep Wallet');
|
|
199
|
-
window.open('https://rialo.io/wallet', '_blank');
|
|
200
|
-
}
|
|
201
213
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
// Get balance
|
|
210
|
-
const balance = await wallet.getBalance();
|
|
211
|
-
console.log('Balance:', formatBalance(balance), 'RLO');
|
|
212
|
-
|
|
213
|
-
// Sign message
|
|
214
|
-
const signed = await wallet.signMessage('Hello!');
|
|
215
|
-
console.log('Signature:', signed.signature);
|
|
216
|
-
|
|
217
|
-
// Send transaction
|
|
218
|
-
const tx = await wallet.signAndSendTransaction({
|
|
219
|
-
to: 'RecipientAddress...',
|
|
220
|
-
value: '1000000000', // 1 RLO in kelvins
|
|
221
|
-
});
|
|
222
|
-
console.log('TX Hash:', tx.hash);
|
|
223
|
-
|
|
224
|
-
// Listen to events
|
|
225
|
-
wallet.on('disconnect', () => {
|
|
226
|
-
console.log('Wallet disconnected');
|
|
227
|
-
});
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Direct Provider Access
|
|
214
|
+
// Loading states
|
|
215
|
+
<ApprovalPending
|
|
216
|
+
title="Waiting for Approval"
|
|
217
|
+
message="Please approve in Sheep Wallet"
|
|
218
|
+
walletName="Sheep Wallet"
|
|
219
|
+
onCancel={() => disconnect()}
|
|
220
|
+
/>
|
|
231
221
|
|
|
232
|
-
|
|
222
|
+
<LoadingSpinner size="md" color="#6EB9A8" />
|
|
233
223
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const balance = await window.rialo.getBalance();
|
|
238
|
-
const tx = await window.rialo.signAndSendTransaction({
|
|
239
|
-
to: 'RecipientAddress...',
|
|
240
|
-
value: '1000000000',
|
|
241
|
-
});
|
|
242
|
-
}
|
|
224
|
+
<ConnectionStatus status="connecting" />
|
|
225
|
+
<ConnectionStatus status="approving" message="Check your wallet" />
|
|
226
|
+
<ConnectionStatus status="error" onRetry={() => connect()} />
|
|
243
227
|
```
|
|
244
228
|
|
|
245
229
|
## Networks
|
|
@@ -254,24 +238,22 @@ if (window.rialo) {
|
|
|
254
238
|
## Utilities
|
|
255
239
|
|
|
256
240
|
```typescript
|
|
257
|
-
import {
|
|
258
|
-
formatAddress,
|
|
259
|
-
formatBalance,
|
|
260
|
-
parseBalance,
|
|
261
|
-
isValidAddress,
|
|
262
|
-
toChainId,
|
|
263
|
-
fromChainId,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
NETWORKS,
|
|
241
|
+
import {
|
|
242
|
+
formatAddress, // (address, chars?) => "5YNm...VWr8"
|
|
243
|
+
formatBalance, // (kelvins, decimals?) => "1.0000"
|
|
244
|
+
parseBalance, // (rlo) => bigint (kelvins)
|
|
245
|
+
isValidAddress, // (address) => boolean
|
|
246
|
+
toChainId, // (network) => 'rialo:devnet'
|
|
247
|
+
fromChainId, // (chainId) => 'devnet'
|
|
248
|
+
isInstalled, // () => boolean
|
|
249
|
+
getProvider, // () => RialoProvider | undefined
|
|
250
|
+
waitForProvider, // (timeout?) => Promise<RialoProvider | undefined>
|
|
251
|
+
NETWORKS, // Network configurations
|
|
268
252
|
} from '@cookill/wallet-adapter';
|
|
269
253
|
```
|
|
270
254
|
|
|
271
255
|
## TypeScript
|
|
272
256
|
|
|
273
|
-
Full TypeScript support with all types exported:
|
|
274
|
-
|
|
275
257
|
```typescript
|
|
276
258
|
import type {
|
|
277
259
|
WalletAccount,
|
|
@@ -283,42 +265,50 @@ import type {
|
|
|
283
265
|
WalletInfo,
|
|
284
266
|
RialoProvider,
|
|
285
267
|
RialoNetwork,
|
|
286
|
-
|
|
268
|
+
RialoChainId,
|
|
287
269
|
} from '@cookill/wallet-adapter';
|
|
288
270
|
```
|
|
289
271
|
|
|
290
272
|
## Troubleshooting
|
|
291
273
|
|
|
292
|
-
###
|
|
274
|
+
### Connection hangs / freezes
|
|
293
275
|
|
|
294
|
-
|
|
295
|
-
2. Clear `node_modules` and reinstall: `rm -rf node_modules && npm install`
|
|
296
|
-
3. Check console for errors
|
|
276
|
+
v3.0 has built-in 20-second timeout. If connection still hangs:
|
|
297
277
|
|
|
298
|
-
|
|
278
|
+
1. Make sure extension is installed and unlocked
|
|
279
|
+
2. Check if popup was blocked by browser
|
|
280
|
+
3. Try refreshing the page
|
|
299
281
|
|
|
300
|
-
|
|
301
|
-
2. Refresh the page after installing
|
|
302
|
-
3. Check if `window.rialo` exists in browser console
|
|
282
|
+
### Auto-connect not working
|
|
303
283
|
|
|
304
|
-
|
|
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.
|
|
305
286
|
|
|
306
|
-
|
|
307
|
-
2. Check you have sufficient balance
|
|
308
|
-
3. Verify recipient address is valid
|
|
287
|
+
### Modal not opening
|
|
309
288
|
|
|
310
|
-
|
|
289
|
+
The `WalletProvider` renders the modal automatically. If you see issues:
|
|
311
290
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
|
318
298
|
|
|
319
|
-
|
|
320
|
-
|
|
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
|
+
```
|
|
321
311
|
|
|
322
312
|
## License
|
|
323
313
|
|
|
324
|
-
MIT
|
|
314
|
+
MIT
|
package/dist/ErrorBoundary.cjs
CHANGED
|
@@ -1,127 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var import_react = require("react");
|
|
28
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
-
var WalletErrorBoundary = class extends import_react.Component {
|
|
30
|
-
constructor() {
|
|
31
|
-
super(...arguments);
|
|
32
|
-
this.state = {
|
|
33
|
-
hasError: false,
|
|
34
|
-
error: null
|
|
35
|
-
};
|
|
36
|
-
this.handleRetry = () => {
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
var WalletErrorBoundary = class extends react.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.handleReset = () => {
|
|
37
10
|
this.setState({ hasError: false, error: null });
|
|
38
11
|
};
|
|
12
|
+
this.state = { hasError: false, error: null };
|
|
39
13
|
}
|
|
40
14
|
static getDerivedStateFromError(error) {
|
|
41
15
|
return { hasError: true, error };
|
|
42
16
|
}
|
|
43
17
|
componentDidCatch(error, errorInfo) {
|
|
44
|
-
console.error("[
|
|
18
|
+
console.error("[WalletErrorBoundary] Caught error:", error, errorInfo);
|
|
45
19
|
this.props.onError?.(error, errorInfo);
|
|
46
20
|
}
|
|
47
21
|
render() {
|
|
48
|
-
if (this.state.hasError) {
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
|
51
29
|
}
|
|
52
|
-
return /* @__PURE__ */ (
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
width: "24",
|
|
80
|
-
height: "24",
|
|
81
|
-
viewBox: "0 0 24 24",
|
|
82
|
-
fill: "none",
|
|
83
|
-
stroke: "#dc2626",
|
|
84
|
-
strokeWidth: "2",
|
|
85
|
-
strokeLinecap: "round",
|
|
86
|
-
strokeLinejoin: "round",
|
|
87
|
-
children: [
|
|
88
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
89
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
90
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
),
|
|
96
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
|
|
97
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
|
|
98
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
-
"button",
|
|
100
|
-
{
|
|
101
|
-
onClick: this.handleRetry,
|
|
102
|
-
style: {
|
|
103
|
-
padding: "8px 16px",
|
|
104
|
-
borderRadius: "8px",
|
|
105
|
-
border: "none",
|
|
106
|
-
backgroundColor: "#dc2626",
|
|
107
|
-
color: "white",
|
|
108
|
-
cursor: "pointer",
|
|
109
|
-
fontSize: "14px",
|
|
110
|
-
fontWeight: 500
|
|
111
|
-
},
|
|
112
|
-
children: "Try Again"
|
|
113
|
-
}
|
|
114
|
-
)
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
);
|
|
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
|
+
] });
|
|
118
57
|
}
|
|
119
58
|
return this.props.children;
|
|
120
59
|
}
|
|
121
60
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
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
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.WalletErrorBoundary = WalletErrorBoundary;
|
|
68
|
+
exports.withWalletErrorBoundary = withWalletErrorBoundary;
|
|
69
|
+
//# sourceMappingURL=ErrorBoundary.cjs.map
|
|
127
70
|
//# sourceMappingURL=ErrorBoundary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ErrorBoundary.tsx"],"sourcesContent":["/**\n * @cookill/wallet-adapter
|
|
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"]}
|