@naculus/connect-appkit-vue 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 +84 -5
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -94,11 +94,90 @@ authorizations and refreshes after `revoke(entry)`. Inspect the returned
94
94
  verifies its settlement in the background. Pending verification retries five
95
95
  times at four-second intervals by default; pass `verifyRetry` to change that.
96
96
 
97
- `useX402Signer(session, provider, switchChain, chainId)` creates the same x402
98
- signer from caller-owned reactive connection values. Its `signer` and `reason`
99
- are computed refs; pass `signer.value` to `createX402Fetch` only when it is
100
- non-null. Injected EIP-6963 sessions are supported, as is WalletConnect when
101
- the caller can supply its EIP-1193-shaped request facade.
97
+ ### Pay x402 from the connected wallet
98
+
99
+ Vue has no provider component, so `useX402Signer` takes the connection from
100
+ you: `useX402Signer(session, provider, switchChain, chainId)`. Pick the
101
+ provider with `findX402Provider` from `@naculus/connect-appkit-core`, which
102
+ chooses it by the session's wallet type, the same rule the React hook uses.
103
+ The injected wallets come from `@naculus/connector-evm-injected` and the
104
+ WalletConnect connector from `@naculus/connector-walletconnect`; install
105
+ whichever your app connects with.
106
+
107
+ ```ts
108
+ import {
109
+ findX402Provider,
110
+ type PaymentFetch,
111
+ } from "@naculus/connect-appkit-core";
112
+ import type { SessionManager } from "@naculus/connect-core";
113
+ import {
114
+ usePaymentFetch,
115
+ useSession,
116
+ useX402Signer,
117
+ } from "@naculus/connect-appkit-vue";
118
+ import { eip6963Connector } from "@naculus/connector-evm-injected";
119
+ import type { WalletConnectConnector } from "@naculus/connector-walletconnect";
120
+ import { createX402Fetch } from "@naculus/payments-x402";
121
+ import { computed } from "vue";
122
+
123
+ // Your app's SessionManager, and its WalletConnect connector if it has one.
124
+ declare const manager: SessionManager;
125
+ declare const walletConnect: WalletConnectConnector | null;
126
+
127
+ const { session, activeChainId } = useSession(manager);
128
+ const provider = computed(() =>
129
+ findX402Provider(session.value, {
130
+ injected: eip6963Connector.getDiscoveredWallets(),
131
+ walletConnect,
132
+ }),
133
+ );
134
+ const switchChain = (chainId: string) => manager.switchChain(chainId);
135
+
136
+ const { signer, reason } = useX402Signer(
137
+ session,
138
+ provider,
139
+ switchChain,
140
+ activeChainId,
141
+ );
142
+ const pay = computed<PaymentFetch | null>(() =>
143
+ signer.value ? createX402Fetch({ signer: signer.value }) : null,
144
+ );
145
+ ```
146
+
147
+ `signer` and `reason` are computed refs. `usePaymentFetch` takes a paying
148
+ fetch, not `null`, so call it in a child component that is rendered only once
149
+ `pay` is set (`<PaidResource v-if="pay" :pay="pay" />`):
150
+
151
+ ```ts
152
+ // PaidResource.vue, <script setup lang="ts">
153
+ import type { PaymentFetch } from "@naculus/connect-appkit-core";
154
+ import { usePaymentFetch } from "@naculus/connect-appkit-vue";
155
+ import { toRef } from "vue";
156
+
157
+ const props = defineProps<{ pay: PaymentFetch }>();
158
+ const { payFetch, isPending, lastPayment, error } = usePaymentFetch(
159
+ toRef(props, "pay"),
160
+ );
161
+ // Call payFetch(url) from an event handler.
162
+ ```
163
+
164
+ `reason` is `null` whenever `signer` is set. Otherwise it says why there is no
165
+ signer, and what to show for it:
166
+
167
+ | `reason` | Meaning | Show |
168
+ |----------|---------|------|
169
+ | `"no-session"` | No wallet is connected. | The connect button. |
170
+ | `"not-evm"` | The session has no EVM (`eip155`) account, for example a Solana-only wallet. | Ask for an EVM account or an EVM wallet. |
171
+ | `"unsupported-wallet-type"` | The session is not an injected (EIP-6963) or WalletConnect wallet, or no provider was found for it. Embedded and passkey EVM wallets land here. | Offer a browser wallet or WalletConnect instead. |
172
+
173
+ The signer switches the wallet to the chain the server asks for before it
174
+ signs, through the `switchChain` you pass, so a wallet on another EVM chain is
175
+ not a `reason`.
176
+
177
+ WalletConnect sessions are supported when you pass the WalletConnect connector
178
+ to `findX402Provider`. The injected (EIP-6963) path is the one verified end to
179
+ end with real wallets; test WalletConnect against the wallets you target before
180
+ you rely on it.
102
181
 
103
182
  ## License
104
183
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naculus/connect-appkit-vue",
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",
@@ -17,23 +17,23 @@
17
17
  "README.md"
18
18
  ],
19
19
  "dependencies": {
20
- "@naculus/payments-x402": "^0.9.0",
20
+ "@naculus/payments-x402": "^0.10.0",
21
21
  "@stencil/vue-output-target": "^0.14.3",
22
- "@naculus/connect-appkit-wc": "0.10.0"
22
+ "@naculus/connect-appkit-wc": "0.11.0"
23
23
  },
24
24
  "peerDependencies": {
25
- "@naculus/connect-appkit-core": "^0.10.0",
26
- "@naculus/connect-core": "^0.9.0",
25
+ "@naculus/connect-appkit-core": "^0.11.0",
26
+ "@naculus/connect-core": "^0.10.0",
27
27
  "vue": "^3.5.0"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
32
  "devDependencies": {
33
- "@naculus/connect-core": "^0.9.0",
33
+ "@naculus/connect-core": "^0.10.0",
34
34
  "vitest": "^5.0.0",
35
35
  "vue": "^3.5.43",
36
- "@naculus/connect-appkit-core": "0.10.0"
36
+ "@naculus/connect-appkit-core": "0.11.0"
37
37
  },
38
38
  "repository": {
39
39
  "type": "git",