@naculus/connect-appkit-react 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/README.md +50 -14
  2. package/package.json +13 -13
package/README.md CHANGED
@@ -88,27 +88,63 @@ authorizations and refreshes after `revoke(entry)`. Inspect the returned
88
88
  verifies its settlement in the background. Pending verification retries five
89
89
  times at four-second intervals by default; pass `verifyRetry` to change that.
90
90
 
91
- For x402 with the connected browser wallet, build the paying fetch from the
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`:
91
+ ### Pay x402 from the connected wallet
95
92
 
96
- ```tsx
97
- const { signer } = useX402Signer();
98
- const pay = useMemo(
99
- () => signer && createX402Fetch({ signer }),
100
- [signer],
101
- );
93
+ `useX402Signer()` reads the connected session from `Web3ConnectProvider` and
94
+ returns `{ signer, reason }`. Build the paying fetch with
95
+ `createX402Fetch({ signer })` from `@naculus/payments-x402`, then hand it to
96
+ `usePaymentFetch`. `usePaymentFetch` takes a paying fetch, not `null`, so
97
+ render the component that calls it only once `signer` exists:
102
98
 
103
- if (!pay) return null;
104
- return <PaidResource pay={pay} />;
99
+ ```tsx
100
+ import type { PaymentFetch } from "@naculus/connect-appkit-core";
101
+ import { usePaymentFetch, useX402Signer } from "@naculus/connect-appkit-react";
102
+ import { createX402Fetch } from "@naculus/payments-x402";
103
+ import { useMemo } from "react";
104
+
105
+ const REASON_TEXT = {
106
+ "no-session": "Connect a wallet to pay.",
107
+ "not-evm": "Switch to an EVM account to pay with x402.",
108
+ "unsupported-wallet-type":
109
+ "This wallet cannot sign x402 payments here. Connect a browser wallet or use WalletConnect.",
110
+ } as const;
111
+
112
+ function PayWithWallet() {
113
+ const { signer, reason } = useX402Signer();
114
+ const pay = useMemo(
115
+ () => (signer ? createX402Fetch({ signer }) : null),
116
+ [signer],
117
+ );
118
+
119
+ if (!pay) return <p>{reason ? REASON_TEXT[reason] : null}</p>;
120
+ return <PaidResource pay={pay} />;
121
+ }
105
122
 
106
123
  function PaidResource({ pay }: { pay: PaymentFetch }) {
107
- const { payFetch } = usePaymentFetch(pay);
108
- // Call payFetch(url) from an event or effect.
124
+ const { payFetch, isPending, lastPayment, error } = usePaymentFetch(pay);
125
+ // Call payFetch(url) from an event handler; render isPending, lastPayment
126
+ // and error.
127
+ return null;
109
128
  }
110
129
  ```
111
130
 
131
+ `reason` is `null` whenever `signer` is set. Otherwise it says why there is no
132
+ signer, and what to show for it:
133
+
134
+ | `reason` | Meaning | Show |
135
+ |----------|---------|------|
136
+ | `"no-session"` | No wallet is connected. | The connect button. |
137
+ | `"not-evm"` | The session has no EVM (`eip155`) account, for example a Solana-only wallet. | Ask for an EVM account or an EVM wallet. |
138
+ | `"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. |
139
+
140
+ The signer switches the wallet to the chain the server asks for before it
141
+ signs, so a wallet on another EVM chain is not a `reason`.
142
+
143
+ WalletConnect sessions are supported: the hook signs through the WalletConnect
144
+ connector. The injected (EIP-6963) path is the one verified end to end with
145
+ real wallets; test WalletConnect against the wallets you target before you rely
146
+ on it.
147
+
112
148
  ### Ask before executing
113
149
 
114
150
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naculus/connect-appkit-react",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
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.9.0",
26
- "@naculus/connector-embedded": "^0.9.0",
27
- "@naculus/connector-evm-injected": "^0.9.0",
28
- "@naculus/connector-passkeys": "^0.9.0",
29
- "@naculus/connector-solana": "^0.9.0",
30
- "@naculus/connector-walletconnect": "^0.9.0",
31
- "@naculus/payments-x402": "^0.9.0",
32
- "@naculus/siwx": "^0.9.0",
33
- "@naculus/wallet-engine": "^0.9.0",
25
+ "@naculus/connect-core": "^0.10.0",
26
+ "@naculus/connector-embedded": "^0.10.0",
27
+ "@naculus/connector-evm-injected": "^0.10.0",
28
+ "@naculus/connector-passkeys": "^0.10.0",
29
+ "@naculus/connector-solana": "^0.10.0",
30
+ "@naculus/connector-walletconnect": "^0.10.0",
31
+ "@naculus/payments-x402": "^0.10.0",
32
+ "@naculus/siwx": "^0.10.0",
33
+ "@naculus/wallet-engine": "^0.10.0",
34
34
  "@stencil/react-output-target": "^1.6.2",
35
35
  "viem": "^2.56.9",
36
- "@naculus/connect-appkit-core": "0.10.0",
37
- "@naculus/connect-appkit-wc": "0.10.0"
36
+ "@naculus/connect-appkit-core": "0.11.0",
37
+ "@naculus/connect-appkit-wc": "0.11.0"
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.10.0"
71
+ "@naculus/connect-appkit-ui": "0.11.0"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "tsup",