@rialo/frost 0.1.0 → 0.1.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 +107 -28
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ That's it. You now have a working wallet connection button.
|
|
|
38
38
|
- [Installation](#installation)
|
|
39
39
|
- [Step-by-Step Guide](#step-by-step-guide)
|
|
40
40
|
- [Hooks Reference](#hooks-reference)
|
|
41
|
+
- [Async/Await with mutateAsync](#asyncawait-with-mutateasync)
|
|
41
42
|
- [Components](#components)
|
|
42
43
|
- [Error Handling](#error-handling)
|
|
43
44
|
- [Advanced Usage](#advanced-usage)
|
|
@@ -322,13 +323,118 @@ function SendTx({ transaction }: { transaction: Uint8Array }) {
|
|
|
322
323
|
| Hook | Description |
|
|
323
324
|
|------|-------------|
|
|
324
325
|
| `useSignMessage()` | Sign arbitrary messages |
|
|
325
|
-
| `useSignIn()` | Sign-In with Wallet (SIWS authentication) |
|
|
326
326
|
| `useSignTransaction()` | Sign transaction without sending |
|
|
327
327
|
| `useSendTransaction()` | Sign and send via wallet |
|
|
328
328
|
| `useSignAndSendTransaction()` | Sign via wallet, send via Frost's RPC |
|
|
329
329
|
|
|
330
330
|
---
|
|
331
331
|
|
|
332
|
+
## Async/Await with mutateAsync
|
|
333
|
+
|
|
334
|
+
All mutation hooks (`useConnectWallet`, `useSignMessage`, `useSignTransaction`, `useSendTransaction`, `useSignAndSendTransaction`, `useDisconnectWallet`, `useSwitchChain`) return both `mutate` and `mutateAsync`.
|
|
335
|
+
|
|
336
|
+
### Callback Pattern (mutate)
|
|
337
|
+
|
|
338
|
+
The `mutate` function is fire-and-forget with callbacks:
|
|
339
|
+
|
|
340
|
+
```tsx
|
|
341
|
+
const { mutate: send } = useSendTransaction({
|
|
342
|
+
onSuccess: (result) => console.log("Sent:", result.signature),
|
|
343
|
+
onError: (error) => console.error("Failed:", error),
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Fire and forget - no await, no return value
|
|
347
|
+
send({ transaction });
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Async/Await Pattern (mutateAsync)
|
|
351
|
+
|
|
352
|
+
The `mutateAsync` function returns a Promise you can await:
|
|
353
|
+
|
|
354
|
+
```tsx
|
|
355
|
+
const { mutateAsync: sendAsync } = useSendTransaction();
|
|
356
|
+
|
|
357
|
+
async function handleSend() {
|
|
358
|
+
try {
|
|
359
|
+
const result = await sendAsync({ transaction });
|
|
360
|
+
console.log("Transaction signature:", result.signature);
|
|
361
|
+
// Continue with next steps...
|
|
362
|
+
} catch (error) {
|
|
363
|
+
console.error("Transaction failed:", error);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### When to Use Each
|
|
369
|
+
|
|
370
|
+
| Pattern | Use When |
|
|
371
|
+
|---------|----------|
|
|
372
|
+
| `mutate` | Simple fire-and-forget, UI updates via hook state |
|
|
373
|
+
| `mutateAsync` | Sequential operations, custom error handling, chaining actions |
|
|
374
|
+
|
|
375
|
+
### Real-World Example: Sign Then Send
|
|
376
|
+
|
|
377
|
+
```tsx
|
|
378
|
+
function TransactionFlow() {
|
|
379
|
+
const { mutateAsync: signAsync } = useSignTransaction();
|
|
380
|
+
const { mutateAsync: sendAsync } = useSendTransaction();
|
|
381
|
+
const [status, setStatus] = useState<string>("");
|
|
382
|
+
|
|
383
|
+
async function handleTransaction(transaction: Uint8Array) {
|
|
384
|
+
try {
|
|
385
|
+
setStatus("Signing...");
|
|
386
|
+
const { signedTransaction } = await signAsync({ transaction });
|
|
387
|
+
|
|
388
|
+
setStatus("Sending...");
|
|
389
|
+
const { signature } = await sendAsync({ transaction: signedTransaction });
|
|
390
|
+
|
|
391
|
+
setStatus(`Success! Signature: ${signature}`);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
setStatus(`Error: ${error.message}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return (
|
|
398
|
+
<div>
|
|
399
|
+
<button onClick={() => handleTransaction(myTx)}>Execute</button>
|
|
400
|
+
<p>{status}</p>
|
|
401
|
+
</div>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### All Mutation Hooks Support Both Patterns
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
// Connection
|
|
410
|
+
const { mutateAsync: connectAsync } = useConnectWallet();
|
|
411
|
+
const result = await connectAsync({ walletName: "Rialo" });
|
|
412
|
+
|
|
413
|
+
// Signing
|
|
414
|
+
const { mutateAsync: signMessageAsync } = useSignMessage();
|
|
415
|
+
const { signature } = await signMessageAsync({ message: "Hello" });
|
|
416
|
+
|
|
417
|
+
// Transactions
|
|
418
|
+
const { mutateAsync: signTxAsync } = useSignTransaction();
|
|
419
|
+
const { signedTransaction } = await signTxAsync({ transaction });
|
|
420
|
+
|
|
421
|
+
const { mutateAsync: sendTxAsync } = useSendTransaction();
|
|
422
|
+
const { signature } = await sendTxAsync({ transaction });
|
|
423
|
+
|
|
424
|
+
const { mutateAsync: signAndSendAsync } = useSignAndSendTransaction();
|
|
425
|
+
const { signature } = await signAndSendAsync({ transaction });
|
|
426
|
+
|
|
427
|
+
// Disconnect
|
|
428
|
+
const { mutateAsync: disconnectAsync } = useDisconnectWallet();
|
|
429
|
+
await disconnectAsync();
|
|
430
|
+
|
|
431
|
+
// Switch chain
|
|
432
|
+
const { mutateAsync: switchChainAsync } = useSwitchChain();
|
|
433
|
+
await switchChainAsync(getDefaultRialoClientConfig("mainnet"));
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
332
438
|
## Hooks in Detail
|
|
333
439
|
|
|
334
440
|
### useConnectWallet
|
|
@@ -371,33 +477,6 @@ signMessage({ message: "Hello World" });
|
|
|
371
477
|
signMessage({ message: new Uint8Array([1, 2, 3]) });
|
|
372
478
|
```
|
|
373
479
|
|
|
374
|
-
### useSignIn
|
|
375
|
-
|
|
376
|
-
SIWS (Sign-In with Wallet) for authentication:
|
|
377
|
-
|
|
378
|
-
```tsx
|
|
379
|
-
const { mutate: signIn } = useSignIn({
|
|
380
|
-
onSuccess: async (result) => {
|
|
381
|
-
// Send to your backend for verification
|
|
382
|
-
await fetch("/api/auth", {
|
|
383
|
-
method: "POST",
|
|
384
|
-
body: JSON.stringify({
|
|
385
|
-
signature: Array.from(result.signature),
|
|
386
|
-
message: Array.from(result.signedMessage),
|
|
387
|
-
address: result.account.address,
|
|
388
|
-
}),
|
|
389
|
-
});
|
|
390
|
-
},
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
signIn({
|
|
394
|
-
domain: window.location.host,
|
|
395
|
-
statement: "Sign in to MyApp",
|
|
396
|
-
nonce: crypto.randomUUID(),
|
|
397
|
-
expirationTime: new Date(Date.now() + 3600000).toISOString(),
|
|
398
|
-
});
|
|
399
|
-
```
|
|
400
|
-
|
|
401
480
|
### useNativeBalance
|
|
402
481
|
|
|
403
482
|
```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rialo/frost",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React wallet integration library for Rialo DApps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rialo",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"react": "^18.0.0 || ^19.0.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@rialo/ts-cdk": "0.1.
|
|
45
|
+
"@rialo/ts-cdk": "0.1.9",
|
|
46
46
|
"@tanstack/react-query": "5.90.10",
|
|
47
47
|
"@tanstack/react-store": "0.8.0",
|
|
48
|
-
"@rialo/frost-core": "^0.1.
|
|
48
|
+
"@rialo/frost-core": "^0.1.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@testing-library/jest-dom": "6.9.1",
|