@cookill/wallet-adapter 3.1.4 → 3.1.6
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 +110 -111
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Wallet adapter for **Sheep Wallet** — the browser extension wallet for the Rialo blockchain.
|
|
4
4
|
|
|
5
|
-
Provides a drop-in React provider, responsive connect modal, and vanilla JS class so dApp developers can integrate Sheep Wallet without writing custom UI.
|
|
6
|
-
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
@@ -25,7 +23,9 @@ function App() {
|
|
|
25
23
|
}
|
|
26
24
|
```
|
|
27
25
|
|
|
28
|
-
`WalletProvider` renders a built-in connect modal automatically. On desktop
|
|
26
|
+
`WalletProvider` renders a built-in connect modal automatically. On desktop it opens centered; on mobile it slides up as a sheet.
|
|
27
|
+
|
|
28
|
+
> **Note:** The built-in modal has known interaction issues (tab switching may close the modal, connect button may not trigger the extension). For production use, we recommend building a custom modal using the `connect()` function directly — see [Custom Modal](#custom-modal) below.
|
|
29
29
|
|
|
30
30
|
## React Hooks
|
|
31
31
|
|
|
@@ -34,31 +34,29 @@ function App() {
|
|
|
34
34
|
```tsx
|
|
35
35
|
import { useWallet } from '@cookill/wallet-adapter/react';
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} = useWallet();
|
|
61
|
-
}
|
|
37
|
+
const {
|
|
38
|
+
connected, // boolean
|
|
39
|
+
connecting, // boolean
|
|
40
|
+
activeAccount, // WalletAccount | null
|
|
41
|
+
chainId, // string — e.g. "rialo:devnet"
|
|
42
|
+
isInstalled, // boolean — extension detected
|
|
43
|
+
|
|
44
|
+
// Actions
|
|
45
|
+
connect, // () => Promise<WalletAccount[]>
|
|
46
|
+
disconnect, // () => Promise<void>
|
|
47
|
+
switchNetwork, // (network) => Promise<void>
|
|
48
|
+
refreshBalance, // () => Promise<void>
|
|
49
|
+
|
|
50
|
+
// Signing & Transactions
|
|
51
|
+
signMessage, // (msg: string) => Promise<SignedMessage>
|
|
52
|
+
signTransaction, // (tx) => Promise<string>
|
|
53
|
+
sendTransaction, // (tx) => Promise<TransactionResult>
|
|
54
|
+
signAndSendTransaction, // (tx) => Promise<TransactionResult>
|
|
55
|
+
|
|
56
|
+
// Built-in modal control (has known issues — see note above)
|
|
57
|
+
openModal, // () => void
|
|
58
|
+
closeModal, // () => void
|
|
59
|
+
} = useWallet();
|
|
62
60
|
```
|
|
63
61
|
|
|
64
62
|
### Focused Hooks
|
|
@@ -72,30 +70,76 @@ const accounts = useAccounts();
|
|
|
72
70
|
const { balance, refresh } = useBalance();
|
|
73
71
|
const { network, chainId } = useNetwork();
|
|
74
72
|
const { switchNetwork } = useSwitchNetwork();
|
|
75
|
-
const { sendTransaction, signAndSendTransaction } = useSendTransaction();
|
|
73
|
+
const { sendTransaction, signAndSendTransaction, sendGaslessTransaction } = useSendTransaction();
|
|
76
74
|
const { signMessage } = useSignMessage();
|
|
77
75
|
```
|
|
78
76
|
|
|
79
|
-
|
|
77
|
+
### REX (Confidential Transactions)
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const { capabilities, supported, submitREXTransaction } = useREX();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### SfS (Stake-for-Service / Gasless)
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
```tsx
|
|
86
|
+
const { positions, credits, hasCredits, createPosition, sendGasless, refresh } = useSfS();
|
|
87
|
+
```
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
2. **Scan to Connect** — Generates a QR code that a mobile Sheep Wallet can scan to pair cross-device. Also supports the reverse flow (wallet shows QR, dApp scans).
|
|
89
|
+
### Scan-to-Connect
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
```tsx
|
|
92
|
+
const { scanURI, status, generateQR, approveSession, rejectSession } = useScanConnect();
|
|
93
|
+
```
|
|
87
94
|
|
|
88
|
-
|
|
95
|
+
## Custom Modal
|
|
89
96
|
|
|
90
|
-
|
|
97
|
+
The built-in modal rendered by `WalletProvider` has known issues with event propagation. For a reliable connection experience, build your own modal and call `connect()` directly:
|
|
91
98
|
|
|
92
99
|
```tsx
|
|
93
|
-
|
|
100
|
+
import { useConnectWallet, useScanConnect, isInstalled } from '@cookill/wallet-adapter/react';
|
|
101
|
+
|
|
102
|
+
function MyConnectModal({ open, onClose }) {
|
|
103
|
+
const { connect, connecting, error } = useConnectWallet();
|
|
104
|
+
const { scanURI, status, generateQR } = useScanConnect();
|
|
94
105
|
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
const handleConnect = async () => {
|
|
107
|
+
try {
|
|
108
|
+
const accounts = await connect();
|
|
109
|
+
console.log('Connected:', accounts[0].address);
|
|
110
|
+
onClose();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.error('Connection failed:', err);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (!open) return null;
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<div className="modal-overlay" onClick={onClose}>
|
|
120
|
+
<div className="modal-content" onClick={e => e.stopPropagation()}>
|
|
121
|
+
<h2>Connect Wallet</h2>
|
|
122
|
+
|
|
123
|
+
{isInstalled() ? (
|
|
124
|
+
<button onClick={handleConnect} disabled={connecting}>
|
|
125
|
+
{connecting ? 'Approve in extension...' : 'Connect Sheep Wallet'}
|
|
126
|
+
</button>
|
|
127
|
+
) : (
|
|
128
|
+
<a href="https://rialo.io/wallet" target="_blank">Install Sheep Wallet</a>
|
|
129
|
+
)}
|
|
130
|
+
|
|
131
|
+
{error && <p className="error">{error.message}</p>}
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
97
136
|
```
|
|
98
137
|
|
|
138
|
+
Key points:
|
|
139
|
+
- Use `connect()` from `useConnectWallet()` — this calls `window.rialo.connect()` which triggers the extension's approval popup
|
|
140
|
+
- The `connect()` call has a 20-second timeout to prevent dApp freezes
|
|
141
|
+
- Use `isInstalled()` to check if the extension is present before connecting
|
|
142
|
+
|
|
99
143
|
## Vanilla JavaScript
|
|
100
144
|
|
|
101
145
|
```typescript
|
|
@@ -108,8 +152,6 @@ if (!wallet.isInstalled) {
|
|
|
108
152
|
}
|
|
109
153
|
|
|
110
154
|
const accounts = await wallet.connect();
|
|
111
|
-
console.log('Address:', accounts[0].address);
|
|
112
|
-
|
|
113
155
|
const balance = await wallet.getBalance();
|
|
114
156
|
console.log('Balance:', formatBalance(balance));
|
|
115
157
|
|
|
@@ -125,27 +167,27 @@ await wallet.disconnect();
|
|
|
125
167
|
|
|
126
168
|
```tsx
|
|
127
169
|
<ConnectButton
|
|
128
|
-
connectLabel="Connect Wallet"
|
|
129
|
-
disconnectLabel="Disconnect"
|
|
130
|
-
showAddress={true}
|
|
131
|
-
showBalance={false}
|
|
170
|
+
connectLabel="Connect Wallet"
|
|
171
|
+
disconnectLabel="Disconnect"
|
|
172
|
+
showAddress={true}
|
|
173
|
+
showBalance={false}
|
|
174
|
+
showFeatures={false}
|
|
132
175
|
/>
|
|
133
176
|
```
|
|
134
177
|
|
|
178
|
+
> **Note:** When the extension is installed, `ConnectButton` calls `connect()` directly (no modal). When not installed, it opens the built-in modal with a download link.
|
|
179
|
+
|
|
135
180
|
## WalletProvider Props
|
|
136
181
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{children}
|
|
147
|
-
</WalletProvider>
|
|
148
|
-
```
|
|
182
|
+
| Prop | Type | Default | Description |
|
|
183
|
+
|------|------|---------|-------------|
|
|
184
|
+
| `network` | `RialoNetwork` | `'devnet'` | Default network |
|
|
185
|
+
| `autoConnect` | `boolean` | `true` | Silently restore previous session on load |
|
|
186
|
+
| `scanConnectRelay` | `string` | `'wss://relay.rialo.io'` | Relay URL for scan-to-connect |
|
|
187
|
+
| `onConnect` | `(accounts) => void` | — | Called after successful connection |
|
|
188
|
+
| `onDisconnect` | `() => void` | — | Called after disconnect |
|
|
189
|
+
| `onError` | `(error) => void` | — | Called on connection errors |
|
|
190
|
+
| `onNetworkChange` | `(network) => void` | — | Called when network changes |
|
|
149
191
|
|
|
150
192
|
## Networks
|
|
151
193
|
|
|
@@ -156,56 +198,6 @@ await wallet.disconnect();
|
|
|
156
198
|
| Devnet | rialo:devnet | https://devnet.rialo.io:4101 | dRLO |
|
|
157
199
|
| Localnet | rialo:localnet | http://localhost:4101 | lRLO |
|
|
158
200
|
|
|
159
|
-
## Provider Interface (window.rialo)
|
|
160
|
-
|
|
161
|
-
When the Sheep Wallet extension is installed, it injects `window.rialo` with this interface:
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
interface RialoProvider {
|
|
165
|
-
isRialo: boolean;
|
|
166
|
-
isSheepWallet: boolean;
|
|
167
|
-
version: string;
|
|
168
|
-
|
|
169
|
-
// Connection
|
|
170
|
-
connect(): Promise<WalletAccount[]>;
|
|
171
|
-
disconnect(): Promise<void>;
|
|
172
|
-
isConnected(): Promise<boolean>;
|
|
173
|
-
getAccounts(): Promise<WalletAccount[]>;
|
|
174
|
-
|
|
175
|
-
// Transactions
|
|
176
|
-
signTransaction(tx: TransactionRequest): Promise<{ signature: string }>;
|
|
177
|
-
sendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
|
|
178
|
-
signAndSendTransaction(tx: TransactionRequest): Promise<TransactionResult>;
|
|
179
|
-
|
|
180
|
-
// Message Signing
|
|
181
|
-
signMessage(message: string | Uint8Array): Promise<SignedMessage>;
|
|
182
|
-
|
|
183
|
-
// Network
|
|
184
|
-
getNetwork(): Promise<RialoNetwork>;
|
|
185
|
-
switchNetwork(network: RialoNetwork): Promise<void>;
|
|
186
|
-
getBalance(address?: string): Promise<BalanceResult>;
|
|
187
|
-
|
|
188
|
-
// Events
|
|
189
|
-
on(event: WalletEvent, callback: Function): () => void;
|
|
190
|
-
|
|
191
|
-
// State (synchronous getters)
|
|
192
|
-
readonly connected: boolean;
|
|
193
|
-
readonly accounts: WalletAccount[];
|
|
194
|
-
readonly address: string | null;
|
|
195
|
-
readonly network: RialoNetwork;
|
|
196
|
-
readonly chainId: string;
|
|
197
|
-
}
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Supported Events
|
|
201
|
-
|
|
202
|
-
| Event | Payload |
|
|
203
|
-
|-------------------|-----------------------------------|
|
|
204
|
-
| `connect` | `{ accounts: WalletAccount[] }` |
|
|
205
|
-
| `disconnect` | — |
|
|
206
|
-
| `accountsChanged` | `WalletAccount[]` |
|
|
207
|
-
| `networkChanged` | `{ network, chainId }` |
|
|
208
|
-
|
|
209
201
|
## Key Types
|
|
210
202
|
|
|
211
203
|
```typescript
|
|
@@ -219,6 +211,7 @@ interface TransactionRequest {
|
|
|
219
211
|
value: string; // amount in kelvins (1 RLO = 1_000_000_000 kelvins)
|
|
220
212
|
data?: string;
|
|
221
213
|
memo?: string;
|
|
214
|
+
gasless?: boolean; // set by sendGaslessTransaction
|
|
222
215
|
}
|
|
223
216
|
|
|
224
217
|
interface TransactionResult {
|
|
@@ -244,16 +237,22 @@ import {
|
|
|
244
237
|
formatBalance, // (kelvins, decimals?) => "1.0000"
|
|
245
238
|
parseBalance, // (rlo) => bigint (kelvins)
|
|
246
239
|
isValidAddress, // (address) => boolean
|
|
247
|
-
isInstalled, // () => boolean
|
|
240
|
+
isInstalled, // () => boolean — checks window.rialo
|
|
248
241
|
NETWORKS, // Record<RialoNetwork, NetworkConfig>
|
|
249
242
|
} from '@cookill/wallet-adapter';
|
|
250
243
|
```
|
|
251
244
|
|
|
252
245
|
## Architecture Notes
|
|
253
246
|
|
|
254
|
-
- All provider calls
|
|
255
|
-
- `autoConnect` uses
|
|
256
|
-
- The
|
|
247
|
+
- All provider calls have a 20-second timeout to prevent dApp freezes
|
|
248
|
+
- `autoConnect` uses `checkSession()` — never triggers a user-facing popup
|
|
249
|
+
- The built-in modal is rendered inside `WalletProvider` automatically
|
|
250
|
+
- `ConnectButton` bypasses the modal when the extension is installed
|
|
251
|
+
|
|
252
|
+
## Known Issues
|
|
253
|
+
|
|
254
|
+
1. **Built-in modal tab switching** — Clicking "Scan to Connect" tab may close the modal due to event propagation. Workaround: use a custom modal.
|
|
255
|
+
2. **Built-in modal connect button** — May not trigger the extension popup in some environments. Workaround: use `connect()` directly.
|
|
257
256
|
|
|
258
257
|
## License
|
|
259
258
|
|
package/package.json
CHANGED