@naculus/connect-appkit-react 0.10.0 → 0.11.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 +58 -20
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -9,12 +9,14 @@ transaction lifecycle, reachable as hooks.
|
|
|
9
9
|
|
|
10
10
|
> **🔗 Wraps `@naculus/connect-appkit-wc`. If you need the raw Web Components or another framework, see the table below.**
|
|
11
11
|
|
|
12
|
-
| Framework | Package |
|
|
13
|
-
|
|
14
|
-
| Web Components (base) | `@naculus/connect-appkit-wc` |
|
|
15
|
-
| **React** | `@naculus/connect-appkit-react` |
|
|
16
|
-
| Vue | `@naculus/connect-appkit-vue` |
|
|
17
|
-
| UI (shared styles) | `@naculus/connect-appkit-ui` |
|
|
12
|
+
| Framework | Package |
|
|
13
|
+
|-----------|---------|
|
|
14
|
+
| Web Components (base) | `@naculus/connect-appkit-wc` |
|
|
15
|
+
| **React** | `@naculus/connect-appkit-react` |
|
|
16
|
+
| Vue | `@naculus/connect-appkit-vue` |
|
|
17
|
+
| UI (shared styles) | `@naculus/connect-appkit-ui` |
|
|
18
|
+
|
|
19
|
+
All four packages are released together on one version; install the same version of each.
|
|
18
20
|
|
|
19
21
|
## Install
|
|
20
22
|
|
|
@@ -88,27 +90,63 @@ authorizations and refreshes after `revoke(entry)`. Inspect the returned
|
|
|
88
90
|
verifies its settlement in the background. Pending verification retries five
|
|
89
91
|
times at four-second intervals by default; pass `verifyRetry` to change that.
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
hook's signer. Render the component that calls `usePaymentFetch` only after
|
|
93
|
-
`pay` is available, because `usePaymentFetch` accepts a paying fetch rather
|
|
94
|
-
than `null`:
|
|
93
|
+
### Pay x402 from the connected wallet
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
95
|
+
`useX402Signer()` reads the connected session from `Web3ConnectProvider` and
|
|
96
|
+
returns `{ signer, reason }`. Build the paying fetch with
|
|
97
|
+
`createX402Fetch({ signer })` from `@naculus/payments-x402`, then hand it to
|
|
98
|
+
`usePaymentFetch`. `usePaymentFetch` takes a paying fetch, not `null`, so
|
|
99
|
+
render the component that calls it only once `signer` exists:
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
```tsx
|
|
102
|
+
import type { PaymentFetch } from "@naculus/connect-appkit-core";
|
|
103
|
+
import { usePaymentFetch, useX402Signer } from "@naculus/connect-appkit-react";
|
|
104
|
+
import { createX402Fetch } from "@naculus/payments-x402";
|
|
105
|
+
import { useMemo } from "react";
|
|
106
|
+
|
|
107
|
+
const REASON_TEXT = {
|
|
108
|
+
"no-session": "Connect a wallet to pay.",
|
|
109
|
+
"not-evm": "Switch to an EVM account to pay with x402.",
|
|
110
|
+
"unsupported-wallet-type":
|
|
111
|
+
"This wallet cannot sign x402 payments here. Connect a browser wallet or use WalletConnect.",
|
|
112
|
+
} as const;
|
|
113
|
+
|
|
114
|
+
function PayWithWallet() {
|
|
115
|
+
const { signer, reason } = useX402Signer();
|
|
116
|
+
const pay = useMemo(
|
|
117
|
+
() => (signer ? createX402Fetch({ signer }) : null),
|
|
118
|
+
[signer],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
if (!pay) return <p>{reason ? REASON_TEXT[reason] : null}</p>;
|
|
122
|
+
return <PaidResource pay={pay} />;
|
|
123
|
+
}
|
|
105
124
|
|
|
106
125
|
function PaidResource({ pay }: { pay: PaymentFetch }) {
|
|
107
|
-
const { payFetch } = usePaymentFetch(pay);
|
|
108
|
-
// Call payFetch(url) from an event
|
|
126
|
+
const { payFetch, isPending, lastPayment, error } = usePaymentFetch(pay);
|
|
127
|
+
// Call payFetch(url) from an event handler; render isPending, lastPayment
|
|
128
|
+
// and error.
|
|
129
|
+
return null;
|
|
109
130
|
}
|
|
110
131
|
```
|
|
111
132
|
|
|
133
|
+
`reason` is `null` whenever `signer` is set. Otherwise it says why there is no
|
|
134
|
+
signer, and what to show for it:
|
|
135
|
+
|
|
136
|
+
| `reason` | Meaning | Show |
|
|
137
|
+
|----------|---------|------|
|
|
138
|
+
| `"no-session"` | No wallet is connected. | The connect button. |
|
|
139
|
+
| `"not-evm"` | The session has no EVM (`eip155`) account, for example a Solana-only wallet. | Ask for an EVM account or an EVM wallet. |
|
|
140
|
+
| `"unsupported-wallet-type"` | The session is not an injected (EIP-6963) or WalletConnect wallet, or its provider is no longer available. Embedded and passkey EVM wallets land here. | Offer a browser wallet or WalletConnect instead. |
|
|
141
|
+
|
|
142
|
+
The signer switches the wallet to the chain the server asks for before it
|
|
143
|
+
signs, so a wallet on another EVM chain is not a `reason`.
|
|
144
|
+
|
|
145
|
+
WalletConnect sessions are supported: the hook signs through the WalletConnect
|
|
146
|
+
connector. The injected (EIP-6963) path is the one verified end to end with
|
|
147
|
+
real wallets; test WalletConnect against the wallets you target before you rely
|
|
148
|
+
on it.
|
|
149
|
+
|
|
112
150
|
### Ask before executing
|
|
113
151
|
|
|
114
152
|
```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naculus/connect-appkit-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@naculus/connect-core": "^0.
|
|
26
|
-
"@naculus/connector-embedded": "^0.
|
|
27
|
-
"@naculus/connector-evm-injected": "^0.
|
|
28
|
-
"@naculus/connector-passkeys": "^0.
|
|
29
|
-
"@naculus/connector-solana": "^0.
|
|
30
|
-
"@naculus/connector-walletconnect": "^0.
|
|
31
|
-
"@naculus/payments-x402": "^0.
|
|
32
|
-
"@naculus/siwx": "^0.
|
|
33
|
-
"@naculus/wallet-engine": "^0.
|
|
25
|
+
"@naculus/connect-core": "^0.11.0",
|
|
26
|
+
"@naculus/connector-embedded": "^0.11.0",
|
|
27
|
+
"@naculus/connector-evm-injected": "^0.11.0",
|
|
28
|
+
"@naculus/connector-passkeys": "^0.11.0",
|
|
29
|
+
"@naculus/connector-solana": "^0.11.0",
|
|
30
|
+
"@naculus/connector-walletconnect": "^0.11.0",
|
|
31
|
+
"@naculus/payments-x402": "^0.11.0",
|
|
32
|
+
"@naculus/siwx": "^0.11.0",
|
|
33
|
+
"@naculus/wallet-engine": "^0.11.0",
|
|
34
34
|
"@stencil/react-output-target": "^1.6.2",
|
|
35
35
|
"viem": "^2.56.9",
|
|
36
|
-
"@naculus/connect-appkit-core": "0.
|
|
37
|
-
"@naculus/connect-appkit-wc": "0.
|
|
36
|
+
"@naculus/connect-appkit-core": "0.11.1",
|
|
37
|
+
"@naculus/connect-appkit-wc": "0.11.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "^18.0.0 || ^19.0.0"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"react"
|
|
69
69
|
],
|
|
70
70
|
"optionalDependencies": {
|
|
71
|
-
"@naculus/connect-appkit-ui": "0.
|
|
71
|
+
"@naculus/connect-appkit-ui": "0.11.1"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsup",
|