@cookill/wallet-adapter 0.1.0 → 2.4.1
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 +143 -261
- package/dist/ErrorBoundary.cjs +107 -0
- package/dist/ErrorBoundary.cjs.map +1 -0
- package/dist/ErrorBoundary.d.cts +21 -0
- package/dist/ErrorBoundary.d.ts +21 -0
- package/dist/ErrorBoundary.js +102 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/LoadingStates.cjs +269 -0
- package/dist/LoadingStates.cjs.map +1 -0
- package/dist/LoadingStates.d.cts +32 -0
- package/dist/LoadingStates.d.ts +32 -0
- package/dist/LoadingStates.js +262 -0
- package/dist/LoadingStates.js.map +1 -0
- package/dist/index.cjs +65 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -48
- package/dist/index.d.ts +51 -48
- package/dist/index.js +64 -16
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +670 -121
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +41 -56
- package/dist/react.d.ts +41 -56
- package/dist/react.js +662 -124
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +81 -15
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +12 -4
- package/dist/standard.d.ts +12 -4
- package/dist/standard.js +81 -16
- package/dist/standard.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,138 +1,62 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @cookill/wallet-adapter v2.4.0
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
> This is a **community-maintained** wallet adapter, NOT an official Rialo package.
|
|
5
|
-
> For official Rialo packages, see: [@rialo/frost](https://www.npmjs.com/package/@rialo/frost)
|
|
6
|
-
|
|
7
|
-
Universal wallet adapter for Rialo blockchain dApps. Connect to Rialo Wallet and other compatible wallets with a simple, unified API.
|
|
3
|
+
Official wallet adapter for **Sheep Wallet** on Rialo blockchain.
|
|
8
4
|
|
|
9
5
|
## Installation
|
|
10
6
|
|
|
11
7
|
```bash
|
|
12
|
-
npm install @
|
|
13
|
-
# or
|
|
14
|
-
yarn add @cookillabs/wallet-adapter
|
|
15
|
-
# or
|
|
16
|
-
bun add @cookillabs/wallet-adapter
|
|
8
|
+
npm install @cookill/wallet-adapter
|
|
17
9
|
```
|
|
18
10
|
|
|
19
11
|
## Quick Start
|
|
20
12
|
|
|
21
|
-
### React (Recommended)
|
|
22
|
-
|
|
23
13
|
```tsx
|
|
24
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
WalletProvider,
|
|
16
|
+
WalletModal,
|
|
17
|
+
ConnectButton,
|
|
18
|
+
WalletErrorBoundary,
|
|
19
|
+
} from '@cookill/wallet-adapter/react';
|
|
25
20
|
|
|
26
21
|
function App() {
|
|
27
22
|
return (
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function YourDApp() {
|
|
37
|
-
const { connected, activeAccount, signMessage, sendTransaction } = useWallet();
|
|
38
|
-
|
|
39
|
-
const handleSign = async () => {
|
|
40
|
-
const result = await signMessage('Hello Rialo!');
|
|
41
|
-
console.log('Signature:', result.signature);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleSend = async () => {
|
|
45
|
-
const result = await sendTransaction({
|
|
46
|
-
to: 'RecipientBase58Address...', // Base58 address
|
|
47
|
-
value: '1000000000', // 1 RLO in kelvins
|
|
48
|
-
});
|
|
49
|
-
console.log('TX Hash:', result.hash);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if (!connected) return <p>Please connect your wallet</p>;
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<div>
|
|
56
|
-
<p>Connected: {activeAccount?.address}</p>
|
|
57
|
-
<button onClick={handleSign}>Sign Message</button>
|
|
58
|
-
<button onClick={handleSend}>Send 1 RLO</button>
|
|
59
|
-
</div>
|
|
23
|
+
<WalletErrorBoundary>
|
|
24
|
+
<WalletProvider network="devnet" autoConnect>
|
|
25
|
+
<ConnectButton />
|
|
26
|
+
<WalletModal />
|
|
27
|
+
<YourDApp />
|
|
28
|
+
</WalletProvider>
|
|
29
|
+
</WalletErrorBoundary>
|
|
60
30
|
);
|
|
61
31
|
}
|
|
62
32
|
```
|
|
63
33
|
|
|
64
|
-
### Vanilla JavaScript
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { RialoWallet, isRialoInstalled, formatBalance } from '@cookillabs/wallet-adapter';
|
|
68
|
-
|
|
69
|
-
const wallet = new RialoWallet();
|
|
70
|
-
|
|
71
|
-
// Check if installed
|
|
72
|
-
if (!isRialoInstalled()) {
|
|
73
|
-
console.log('Please install Rialo Wallet from https://rialo.io/wallet');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Connect
|
|
77
|
-
const accounts = await wallet.connect();
|
|
78
|
-
console.log('Connected:', accounts[0].address);
|
|
79
|
-
|
|
80
|
-
// Get balance
|
|
81
|
-
const balance = await wallet.getBalance();
|
|
82
|
-
console.log('Balance:', formatBalance(balance), 'RLO');
|
|
83
|
-
|
|
84
|
-
// Sign message
|
|
85
|
-
const signed = await wallet.signMessage('Hello Rialo!');
|
|
86
|
-
console.log('Signature:', signed.signature);
|
|
87
|
-
|
|
88
|
-
// Send transaction
|
|
89
|
-
const tx = await wallet.signAndSendTransaction({
|
|
90
|
-
to: 'RecipientBase58Address...', // Base58 address
|
|
91
|
-
value: '1000000000', // 1 RLO
|
|
92
|
-
});
|
|
93
|
-
console.log('TX Hash:', tx.hash);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Direct Provider Access
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
// Access the injected provider directly
|
|
100
|
-
if (window.rialo) {
|
|
101
|
-
const accounts = await window.rialo.connect();
|
|
102
|
-
const balance = await window.rialo.getBalance();
|
|
103
|
-
|
|
104
|
-
const tx = await window.rialo.signAndSendTransaction({
|
|
105
|
-
to: 'RecipientBase58Address...',
|
|
106
|
-
value: '1000000000',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
34
|
## React Hooks
|
|
112
35
|
|
|
113
36
|
### useWallet
|
|
114
37
|
|
|
115
|
-
Main hook with all functionality:
|
|
116
|
-
|
|
117
38
|
```tsx
|
|
118
39
|
const {
|
|
119
40
|
// State
|
|
120
|
-
connected,
|
|
121
|
-
connecting,
|
|
122
|
-
accounts,
|
|
123
|
-
activeAccount,
|
|
124
|
-
network,
|
|
125
|
-
|
|
41
|
+
connected, // boolean
|
|
42
|
+
connecting, // boolean
|
|
43
|
+
accounts, // WalletAccount[]
|
|
44
|
+
activeAccount, // WalletAccount | null
|
|
45
|
+
network, // 'mainnet' | 'testnet' | 'devnet' | 'localnet'
|
|
46
|
+
chainId, // 'rialo:devnet' etc
|
|
47
|
+
balance, // string | null (in kelvins)
|
|
48
|
+
error, // Error | null
|
|
126
49
|
|
|
127
50
|
// Actions
|
|
128
|
-
connect,
|
|
129
|
-
disconnect,
|
|
130
|
-
switchNetwork,
|
|
51
|
+
connect, // () => Promise<WalletAccount[]>
|
|
52
|
+
disconnect, // () => Promise<void>
|
|
53
|
+
switchNetwork, // (network) => Promise<void>
|
|
54
|
+
refreshBalance, // () => Promise<void>
|
|
131
55
|
|
|
132
56
|
// Transactions
|
|
133
|
-
signMessage,
|
|
134
|
-
signTransaction,
|
|
135
|
-
sendTransaction,
|
|
57
|
+
signMessage, // (message: string) => Promise<SignedMessage>
|
|
58
|
+
signTransaction, // (tx) => Promise<string>
|
|
59
|
+
sendTransaction, // (tx) => Promise<TransactionResult>
|
|
136
60
|
signAndSendTransaction, // (tx) => Promise<TransactionResult>
|
|
137
61
|
|
|
138
62
|
// Modal
|
|
@@ -142,32 +66,34 @@ const {
|
|
|
142
66
|
} = useWallet();
|
|
143
67
|
```
|
|
144
68
|
|
|
145
|
-
###
|
|
69
|
+
### useConnectWallet
|
|
146
70
|
|
|
147
71
|
```tsx
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// Balance
|
|
158
|
-
const { balance, formatted } = useBalance();
|
|
159
|
-
|
|
160
|
-
// Network
|
|
161
|
-
const { network, config } = useNetwork();
|
|
72
|
+
const {
|
|
73
|
+
connect, // Opens modal (recommended)
|
|
74
|
+
connectDirect, // Calls provider directly
|
|
75
|
+
connecting,
|
|
76
|
+
isInstalled,
|
|
77
|
+
error,
|
|
78
|
+
openModal,
|
|
79
|
+
} = useConnectWallet();
|
|
162
80
|
|
|
163
|
-
|
|
164
|
-
|
|
81
|
+
<button onClick={connect}>Connect Wallet</button>
|
|
82
|
+
```
|
|
165
83
|
|
|
166
|
-
|
|
167
|
-
const { sign, signing, signature, error } = useSignMessage();
|
|
84
|
+
### Other Hooks
|
|
168
85
|
|
|
169
|
-
|
|
170
|
-
const
|
|
86
|
+
```tsx
|
|
87
|
+
const connected = useIsConnected();
|
|
88
|
+
const account = useActiveAccount();
|
|
89
|
+
const accounts = useAccounts();
|
|
90
|
+
const { balance, formatted, refresh } = useBalance();
|
|
91
|
+
const { network, chainId, config } = useNetwork();
|
|
92
|
+
const { switchNetwork, switching, error, currentNetwork } = useSwitchNetwork();
|
|
93
|
+
const { disconnect, connected } = useDisconnectWallet();
|
|
94
|
+
const { sign, signing, signature, error, address } = useSignMessage();
|
|
95
|
+
const { sign, signing, signature, error } = useSignTransaction();
|
|
96
|
+
const { send, sending, txHash, error, reset } = useSendTransaction();
|
|
171
97
|
```
|
|
172
98
|
|
|
173
99
|
## Components
|
|
@@ -176,194 +102,150 @@ const { send, sending, txHash, error } = useSendTransaction();
|
|
|
176
102
|
|
|
177
103
|
```tsx
|
|
178
104
|
<ConnectButton
|
|
179
|
-
connectLabel="Connect Wallet"
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
105
|
+
connectLabel="Connect Wallet"
|
|
106
|
+
disconnectLabel="Disconnect"
|
|
107
|
+
showAddress={true}
|
|
108
|
+
showBalance={false}
|
|
109
|
+
className="my-button"
|
|
183
110
|
/>
|
|
184
111
|
```
|
|
185
112
|
|
|
186
113
|
### WalletModal
|
|
187
114
|
|
|
188
115
|
```tsx
|
|
189
|
-
<WalletModal
|
|
190
|
-
title="Select Wallet" // Modal title
|
|
191
|
-
className="my-modal" // Custom class
|
|
192
|
-
/>
|
|
116
|
+
<WalletModal title="Select Wallet" className="my-modal" />
|
|
193
117
|
```
|
|
194
118
|
|
|
195
119
|
### WalletProvider
|
|
196
120
|
|
|
197
121
|
```tsx
|
|
198
122
|
<WalletProvider
|
|
199
|
-
network="devnet"
|
|
200
|
-
autoConnect={true}
|
|
201
|
-
wallets={[customWallet]}
|
|
123
|
+
network="devnet"
|
|
124
|
+
autoConnect={true}
|
|
125
|
+
wallets={[customWallet]}
|
|
202
126
|
onConnect={(accounts) => console.log('Connected', accounts)}
|
|
203
127
|
onDisconnect={() => console.log('Disconnected')}
|
|
128
|
+
onNetworkChange={(network) => console.log('Network:', network)}
|
|
204
129
|
onError={(error) => console.error(error)}
|
|
205
130
|
>
|
|
206
131
|
{children}
|
|
207
132
|
</WalletProvider>
|
|
208
133
|
```
|
|
209
134
|
|
|
210
|
-
|
|
135
|
+
### Error Boundary & Loading States
|
|
211
136
|
|
|
212
137
|
```tsx
|
|
213
|
-
import {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
138
|
+
import {
|
|
139
|
+
WalletErrorBoundary,
|
|
140
|
+
SafeWalletProvider,
|
|
141
|
+
ApprovalPending,
|
|
142
|
+
LoadingSpinner,
|
|
143
|
+
ConnectionStatus,
|
|
144
|
+
} from '@cookill/wallet-adapter/react';
|
|
145
|
+
|
|
146
|
+
// Option 1: Error Boundary wrapper
|
|
147
|
+
<WalletErrorBoundary fallback={<CustomError />} onError={logError}>
|
|
148
|
+
<WalletProvider>...</WalletProvider>
|
|
149
|
+
</WalletErrorBoundary>
|
|
150
|
+
|
|
151
|
+
// Option 2: SafeWalletProvider (includes boundary)
|
|
152
|
+
<SafeWalletProvider network="devnet" errorFallback={<CustomError />}>
|
|
153
|
+
...
|
|
154
|
+
</SafeWalletProvider>
|
|
155
|
+
|
|
156
|
+
// Loading states
|
|
157
|
+
<ApprovalPending
|
|
158
|
+
title="Waiting for Approval"
|
|
159
|
+
message="Please approve in Sheep Wallet"
|
|
160
|
+
walletName="Sheep Wallet"
|
|
161
|
+
onCancel={() => disconnect()}
|
|
162
|
+
/>
|
|
224
163
|
|
|
225
|
-
|
|
226
|
-
return (
|
|
227
|
-
<WalletProvider wallets={customWallets}>
|
|
228
|
-
{children}
|
|
229
|
-
</WalletProvider>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
```
|
|
164
|
+
<LoadingSpinner size="md" color="#6EB9A8" />
|
|
233
165
|
|
|
234
|
-
|
|
166
|
+
<ConnectionStatus status="connecting" />
|
|
167
|
+
<ConnectionStatus status="approving" message="Check your wallet" />
|
|
168
|
+
<ConnectionStatus status="signing" />
|
|
169
|
+
<ConnectionStatus status="success" />
|
|
170
|
+
<ConnectionStatus status="error" onRetry={() => connect()} />
|
|
171
|
+
```
|
|
235
172
|
|
|
236
|
-
|
|
173
|
+
## Vanilla JavaScript
|
|
237
174
|
|
|
238
175
|
```typescript
|
|
239
|
-
import {
|
|
240
|
-
RialoWalletStandard,
|
|
241
|
-
registerRialoWallet,
|
|
242
|
-
getRialoWallet,
|
|
243
|
-
RIALO_SIGN_MESSAGE,
|
|
244
|
-
RIALO_SIGN_TRANSACTION,
|
|
245
|
-
} from '@cookillabs/wallet-adapter/standard';
|
|
246
|
-
|
|
247
|
-
// Get registered wallet
|
|
248
|
-
const wallet = getRialoWallet();
|
|
249
|
-
|
|
250
|
-
if (wallet) {
|
|
251
|
-
// Connect
|
|
252
|
-
const { accounts } = await wallet.features['standard:connect'].connect();
|
|
253
|
-
|
|
254
|
-
// Sign message
|
|
255
|
-
const message = new TextEncoder().encode('Hello Rialo!');
|
|
256
|
-
const { signature } = await wallet.features[RIALO_SIGN_MESSAGE].signMessage({
|
|
257
|
-
account: accounts[0],
|
|
258
|
-
message,
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// Listen for changes
|
|
262
|
-
const unsubscribe = wallet.features['standard:events'].on('change', (data) => {
|
|
263
|
-
console.log('Wallet changed:', data);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
```
|
|
176
|
+
import { RialoWallet, isRialoInstalled, formatBalance } from '@cookill/wallet-adapter';
|
|
267
177
|
|
|
268
|
-
|
|
178
|
+
const wallet = new RialoWallet();
|
|
269
179
|
|
|
270
|
-
|
|
180
|
+
if (!isRialoInstalled()) {
|
|
181
|
+
console.log('Please install Sheep Wallet');
|
|
182
|
+
}
|
|
271
183
|
|
|
184
|
+
const accounts = await wallet.connect();
|
|
185
|
+
const balance = await wallet.getBalance();
|
|
186
|
+
const signed = await wallet.signMessage('Hello!');
|
|
187
|
+
const tx = await wallet.signAndSendTransaction({
|
|
188
|
+
to: 'RecipientAddress...',
|
|
189
|
+
value: '1000000000', // 1 RLO in kelvins
|
|
190
|
+
});
|
|
272
191
|
```
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
192
|
+
|
|
193
|
+
## Direct Provider Access
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
if (window.rialo) {
|
|
197
|
+
const accounts = await window.rialo.connect();
|
|
198
|
+
const balance = await window.rialo.getBalance();
|
|
199
|
+
const tx = await window.rialo.signAndSendTransaction({
|
|
200
|
+
to: 'RecipientAddress...',
|
|
201
|
+
value: '1000000000',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
276
204
|
```
|
|
277
205
|
|
|
278
206
|
## Networks
|
|
279
207
|
|
|
280
|
-
| Network | Chain ID | RPC URL |
|
|
281
|
-
|
|
282
|
-
| Mainnet | rialo:mainnet | https://mainnet.rialo.io:4101 |
|
|
283
|
-
| Testnet | rialo:testnet | https://testnet.rialo.io:4101 |
|
|
284
|
-
| Devnet | rialo:devnet | https://devnet.rialo.io:4101 |
|
|
285
|
-
| Localnet | rialo:localnet | http://localhost:4101 |
|
|
208
|
+
| Network | Chain ID | RPC URL | Symbol |
|
|
209
|
+
|----------|-----------------|----------------------------------|--------|
|
|
210
|
+
| Mainnet | rialo:mainnet | https://mainnet.rialo.io:4101 | RLO |
|
|
211
|
+
| Testnet | rialo:testnet | https://testnet.rialo.io:4101 | tRLO |
|
|
212
|
+
| Devnet | rialo:devnet | https://devnet.rialo.io:4101 | dRLO |
|
|
213
|
+
| Localnet | rialo:localnet | http://localhost:4101 | lRLO |
|
|
286
214
|
|
|
287
|
-
##
|
|
215
|
+
## Utilities
|
|
288
216
|
|
|
289
217
|
```typescript
|
|
290
218
|
import {
|
|
291
|
-
formatAddress,
|
|
292
|
-
formatBalance,
|
|
293
|
-
parseBalance,
|
|
294
|
-
isValidAddress,
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
219
|
+
formatAddress, // (address, chars?) => "5YNm...VWr8"
|
|
220
|
+
formatBalance, // (kelvins, decimals?) => "1.0000"
|
|
221
|
+
parseBalance, // (rlo) => bigint (kelvins)
|
|
222
|
+
isValidAddress, // (address) => boolean
|
|
223
|
+
toChainId, // (network) => 'rialo:devnet'
|
|
224
|
+
fromChainId, // (chainId) => 'devnet'
|
|
225
|
+
isRialoInstalled, // () => boolean
|
|
226
|
+
getRialoProvider, // () => RialoProvider | undefined
|
|
227
|
+
waitForRialoProvider, // (timeout?) => Promise<RialoProvider>
|
|
228
|
+
NETWORKS, // Network configurations
|
|
229
|
+
} from '@cookill/wallet-adapter';
|
|
299
230
|
```
|
|
300
231
|
|
|
301
232
|
## TypeScript
|
|
302
233
|
|
|
303
|
-
Full TypeScript support included:
|
|
304
|
-
|
|
305
234
|
```typescript
|
|
306
235
|
import type {
|
|
307
236
|
WalletAccount,
|
|
308
237
|
TransactionRequest,
|
|
309
238
|
TransactionResult,
|
|
310
239
|
SignedMessage,
|
|
240
|
+
BalanceResult,
|
|
311
241
|
NetworkConfig,
|
|
312
242
|
WalletInfo,
|
|
313
243
|
RialoProvider,
|
|
314
244
|
RialoNetwork,
|
|
315
245
|
RialoChain,
|
|
316
|
-
} from '@
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## Building a Compatible Wallet
|
|
320
|
-
|
|
321
|
-
To make your wallet compatible with this adapter, inject a provider at `window.rialo`:
|
|
322
|
-
|
|
323
|
-
```typescript
|
|
324
|
-
window.rialo = {
|
|
325
|
-
isRialo: true,
|
|
326
|
-
version: '1.0.0',
|
|
327
|
-
|
|
328
|
-
// Connection
|
|
329
|
-
connect: async () => ['5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'],
|
|
330
|
-
disconnect: async () => {},
|
|
331
|
-
isConnected: async () => true,
|
|
332
|
-
getAccounts: async () => ['5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'],
|
|
333
|
-
|
|
334
|
-
// Transactions - MUST use real signing via window.rialo provider
|
|
335
|
-
signTransaction: async (tx) => ({ signature: '...real signature...' }),
|
|
336
|
-
sendTransaction: async (tx) => ({ hash: '...real tx hash...', status: 'pending' }),
|
|
337
|
-
signAndSendTransaction: async (tx) => ({ hash: '...real tx hash...', status: 'pending' }),
|
|
338
|
-
|
|
339
|
-
// Message signing
|
|
340
|
-
signMessage: async (message) => ({
|
|
341
|
-
signature: '...real signature...',
|
|
342
|
-
message,
|
|
343
|
-
address: '5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8'
|
|
344
|
-
}),
|
|
345
|
-
|
|
346
|
-
// Network
|
|
347
|
-
getNetwork: async () => 'rialo:devnet',
|
|
348
|
-
switchNetwork: async (network) => {},
|
|
349
|
-
getBalance: async (address) => '1000000000',
|
|
350
|
-
|
|
351
|
-
// Events
|
|
352
|
-
on: (event, callback) => () => {},
|
|
353
|
-
removeListener: (event, callback) => {},
|
|
354
|
-
removeAllListeners: (event) => {},
|
|
355
|
-
};
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
## Publishing to NPM
|
|
359
|
-
|
|
360
|
-
```bash
|
|
361
|
-
cd packages/wallet-adapter
|
|
362
|
-
npm install
|
|
363
|
-
npm run build
|
|
364
|
-
npm publish --access public
|
|
246
|
+
} from '@cookill/wallet-adapter';
|
|
365
247
|
```
|
|
366
248
|
|
|
367
249
|
## License
|
|
368
250
|
|
|
369
|
-
MIT
|
|
251
|
+
MIT
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
// src/ErrorBoundary.tsx
|
|
9
|
+
var WalletErrorBoundary = class extends react.Component {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.state = {
|
|
13
|
+
hasError: false,
|
|
14
|
+
error: null
|
|
15
|
+
};
|
|
16
|
+
this.handleRetry = () => {
|
|
17
|
+
this.setState({ hasError: false, error: null });
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
static getDerivedStateFromError(error) {
|
|
21
|
+
return { hasError: true, error };
|
|
22
|
+
}
|
|
23
|
+
componentDidCatch(error, errorInfo) {
|
|
24
|
+
console.error("[WalletAdapter] Error caught by boundary:", error, errorInfo);
|
|
25
|
+
this.props.onError?.(error, errorInfo);
|
|
26
|
+
}
|
|
27
|
+
render() {
|
|
28
|
+
if (this.state.hasError) {
|
|
29
|
+
if (this.props.fallback) {
|
|
30
|
+
return this.props.fallback;
|
|
31
|
+
}
|
|
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
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return this.props.children;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var ErrorBoundary_default = WalletErrorBoundary;
|
|
103
|
+
|
|
104
|
+
exports.WalletErrorBoundary = WalletErrorBoundary;
|
|
105
|
+
exports.default = ErrorBoundary_default;
|
|
106
|
+
//# sourceMappingURL=ErrorBoundary.cjs.map
|
|
107
|
+
//# sourceMappingURL=ErrorBoundary.cjs.map
|
|
@@ -0,0 +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,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A;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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { Component, ReactNode, ErrorInfo } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
fallback?: ReactNode;
|
|
7
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
8
|
+
}
|
|
9
|
+
interface State {
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
declare class WalletErrorBoundary extends Component<Props, State> {
|
|
14
|
+
state: State;
|
|
15
|
+
static getDerivedStateFromError(error: Error): State;
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { WalletErrorBoundary, WalletErrorBoundary as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { Component, ReactNode, ErrorInfo } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
fallback?: ReactNode;
|
|
7
|
+
onError?: (error: Error, errorInfo: ErrorInfo) => void;
|
|
8
|
+
}
|
|
9
|
+
interface State {
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
declare class WalletErrorBoundary extends Component<Props, State> {
|
|
14
|
+
state: State;
|
|
15
|
+
static getDerivedStateFromError(error: Error): State;
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { WalletErrorBoundary, WalletErrorBoundary as default };
|