@volr/react 0.1.48 → 0.1.53
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 +86 -54
- package/dist/index.cjs +29 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -79
- package/dist/index.d.ts +68 -79
- package/dist/index.js +30 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @volr/react
|
|
2
2
|
|
|
3
|
-
Volr React SDK - React hooks
|
|
3
|
+
Volr React SDK - React hooks for Volr Web3 Payment Builder.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ yarn add @volr/react
|
|
|
13
13
|
### Basic Setup
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import { VolrProvider,
|
|
16
|
+
import { VolrProvider, useVolr } from '@volr/react';
|
|
17
17
|
|
|
18
18
|
function App() {
|
|
19
19
|
return (
|
|
@@ -29,58 +29,104 @@ function App() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function YourApp() {
|
|
32
|
-
const { evm } =
|
|
32
|
+
const { evm, address, isLoggedIn, logout } = useVolr();
|
|
33
|
+
|
|
34
|
+
if (!isLoggedIn) {
|
|
35
|
+
return <div>Please login</div>;
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
// Read contract
|
|
35
39
|
const balance = await evm(8453).readContract({
|
|
36
40
|
address: '0x...',
|
|
37
41
|
abi: erc20Abi,
|
|
38
42
|
functionName: 'balanceOf',
|
|
39
|
-
args: [
|
|
43
|
+
args: [address],
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
// Send transaction
|
|
43
|
-
const result = await evm(8453).sendTransaction(
|
|
47
|
+
const result = await evm(8453).sendTransaction({
|
|
48
|
+
to: '0x...',
|
|
49
|
+
data: '0x...',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Send batch
|
|
53
|
+
const result = await evm(8453).sendBatch([
|
|
44
54
|
{
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
target: '0x...',
|
|
56
|
+
abi: erc20Abi,
|
|
57
|
+
functionName: 'transfer',
|
|
58
|
+
args: ['0x...', BigInt(1000000)],
|
|
47
59
|
},
|
|
48
|
-
|
|
49
|
-
policyId: '0x' + '0'.repeat(64),
|
|
50
|
-
signer: mySigner,
|
|
51
|
-
}
|
|
52
|
-
);
|
|
60
|
+
]);
|
|
53
61
|
}
|
|
54
62
|
```
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
## API
|
|
65
|
+
|
|
66
|
+
### useVolr
|
|
57
67
|
|
|
58
|
-
|
|
68
|
+
Main hook for wallet operations.
|
|
59
69
|
|
|
60
70
|
```tsx
|
|
61
|
-
|
|
71
|
+
const {
|
|
72
|
+
evm, // (chainId: number) => EvmClient
|
|
73
|
+
address, // `0x${string}` | undefined
|
|
74
|
+
email, // string | undefined
|
|
75
|
+
isLoggedIn, // boolean
|
|
76
|
+
signerType, // 'passkey' | 'external_wallet' | 'mpc' | undefined
|
|
77
|
+
logout, // () => Promise<void>
|
|
78
|
+
isLoading, // boolean
|
|
79
|
+
error, // Error | null
|
|
80
|
+
} = useVolr();
|
|
81
|
+
```
|
|
62
82
|
|
|
63
|
-
|
|
64
|
-
const { precheck } = usePrecheck();
|
|
65
|
-
const { relay } = useRelay();
|
|
83
|
+
### EvmClient
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
Returned by `evm(chainId)`.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
const client = evm(8453);
|
|
89
|
+
|
|
90
|
+
// Read contract
|
|
91
|
+
const balance = await client.readContract({
|
|
92
|
+
address: tokenAddress,
|
|
93
|
+
abi: erc20Abi,
|
|
94
|
+
functionName: 'balanceOf',
|
|
95
|
+
args: [userAddress],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Send single transaction
|
|
99
|
+
const result = await client.sendTransaction({
|
|
100
|
+
to: '0x...',
|
|
101
|
+
data: '0x...',
|
|
102
|
+
value: 0n,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Send batch (with ABI)
|
|
106
|
+
const result = await client.sendBatch([
|
|
107
|
+
{
|
|
108
|
+
target: tokenAddress,
|
|
70
109
|
abi: erc20Abi,
|
|
71
110
|
functionName: 'transfer',
|
|
72
|
-
args: [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
111
|
+
args: [recipient, amount],
|
|
112
|
+
gasLimit: 100000n,
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
// Send batch (raw calls)
|
|
117
|
+
const result = await client.sendBatch([
|
|
118
|
+
{
|
|
119
|
+
target: '0x...',
|
|
120
|
+
data: '0x...',
|
|
121
|
+
value: 0n,
|
|
122
|
+
gasLimit: 100000n,
|
|
123
|
+
},
|
|
124
|
+
]);
|
|
79
125
|
```
|
|
80
126
|
|
|
81
127
|
## Features
|
|
82
128
|
|
|
83
|
-
- **
|
|
129
|
+
- **Simple API**: `useVolr()` provides everything you need
|
|
84
130
|
- **Session Management**: Automatic token refresh and tab synchronization
|
|
85
131
|
- **EIP-7702 Support**: Gasless transactions with session keys
|
|
86
132
|
- **Passkey Integration**: Secure signing with device passkeys
|
|
@@ -90,7 +136,7 @@ function AdvancedComponent() {
|
|
|
90
136
|
|
|
91
137
|
## OAuth Handling
|
|
92
138
|
|
|
93
|
-
The SDK provides
|
|
139
|
+
The SDK provides `useVolrAuthCallback` to handle OAuth redirects:
|
|
94
140
|
|
|
95
141
|
```tsx
|
|
96
142
|
import { useVolrAuthCallback } from '@volr/react';
|
|
@@ -99,11 +145,9 @@ function AuthCallback() {
|
|
|
99
145
|
const { isLoading, error, isNewUser, user } = useVolrAuthCallback({
|
|
100
146
|
onSuccess: (user) => {
|
|
101
147
|
console.log('Logged in:', user);
|
|
102
|
-
// Navigate to dashboard or home
|
|
103
148
|
},
|
|
104
149
|
onError: (err) => {
|
|
105
150
|
console.error('Login failed:', err);
|
|
106
|
-
// Show error message or redirect to login
|
|
107
151
|
},
|
|
108
152
|
});
|
|
109
153
|
|
|
@@ -114,33 +158,21 @@ function AuthCallback() {
|
|
|
114
158
|
}
|
|
115
159
|
```
|
|
116
160
|
|
|
117
|
-
This hook automatically:
|
|
118
|
-
1. Parses URL parameters (`success`, `userId`, `isNewUser`, `error`)
|
|
119
|
-
2. Refreshes the session to establish the authentication cookie
|
|
120
|
-
3. Fetches the full user profile
|
|
121
|
-
4. Updates the global `VolrProvider` context state
|
|
122
|
-
|
|
123
161
|
## Failure Semantics
|
|
124
162
|
|
|
125
|
-
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- For ERC20 methods (`transfer`, `transferFrom`, `approve`, `increaseAllowance`, `decreaseAllowance`), if a token returns `false`, the batch is treated as failed (even if it doesn't revert).
|
|
129
|
-
- Backend precheck rejects obvious failures (non-contract targets; ERC20 `false` on simulation) before submitting.
|
|
163
|
+
- `revertOnFail` defaults to `true` - any failed call reverts the entire batch
|
|
164
|
+
- Calls to non-contract addresses are rejected
|
|
165
|
+
- For ERC20 methods, if a token returns `false`, the batch is treated as failed
|
|
130
166
|
|
|
131
167
|
## Diagnostics
|
|
132
168
|
|
|
133
|
-
When gas estimation or simulation fails, the backend includes
|
|
169
|
+
When gas estimation or simulation fails, the backend includes `developerDiagnostics` in the error response:
|
|
170
|
+
|
|
171
|
+
- `topLevel.reason`: Decoded revert reason
|
|
172
|
+
- `calls[]`: Per-call diagnostics with `target`, `selector`, `isContract`, `callResult`, `decodedRevert`
|
|
134
173
|
|
|
135
|
-
|
|
136
|
-
- `calls[]`: Per-call diagnostics with:
|
|
137
|
-
- `index`, `target`, `selector`
|
|
138
|
-
- `isContract` (EOA detection)
|
|
139
|
-
- `callResult` (raw `eth_call` return data)
|
|
140
|
-
- `decodedRevert` (human-readable when available)
|
|
174
|
+
Use these to pinpoint which call failed and why.
|
|
141
175
|
|
|
142
|
-
|
|
143
|
-
- Precheck errors: `[volr][precheck] developerDiagnostics: ...`
|
|
144
|
-
- Relay errors: `[volr][relay] developerDiagnostics: ...`
|
|
176
|
+
## License
|
|
145
177
|
|
|
146
|
-
|
|
178
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -10104,10 +10104,10 @@ function VolrProvider({ config, children }) {
|
|
|
10104
10104
|
);
|
|
10105
10105
|
return /* @__PURE__ */ jsxRuntime.jsx(VolrContext.Provider, { value: publicValue, children: /* @__PURE__ */ jsxRuntime.jsx(InternalAuthContext.Provider, { value: internalValue, children }) });
|
|
10106
10106
|
}
|
|
10107
|
-
function
|
|
10107
|
+
function useVolrContext() {
|
|
10108
10108
|
const context = react.useContext(VolrContext);
|
|
10109
10109
|
if (!context) {
|
|
10110
|
-
throw new Error("
|
|
10110
|
+
throw new Error("useVolrContext must be used within VolrProvider");
|
|
10111
10111
|
}
|
|
10112
10112
|
return context;
|
|
10113
10113
|
}
|
|
@@ -10189,7 +10189,7 @@ function validateRelayInput(input, config = {}) {
|
|
|
10189
10189
|
|
|
10190
10190
|
// src/hooks/usePrecheck.ts
|
|
10191
10191
|
function usePrecheck() {
|
|
10192
|
-
const { precheck: precheckContext } =
|
|
10192
|
+
const { precheck: precheckContext } = useVolrContext();
|
|
10193
10193
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
10194
10194
|
const [error, setError] = react.useState(null);
|
|
10195
10195
|
const precheck = react.useCallback(
|
|
@@ -10223,7 +10223,7 @@ function useInternalAuth() {
|
|
|
10223
10223
|
return context;
|
|
10224
10224
|
}
|
|
10225
10225
|
function useRelay() {
|
|
10226
|
-
const { relay: relayContext } =
|
|
10226
|
+
const { relay: relayContext } = useVolrContext();
|
|
10227
10227
|
const { client } = useInternalAuth();
|
|
10228
10228
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
10229
10229
|
const [error, setError] = react.useState(null);
|
|
@@ -10279,7 +10279,7 @@ function useRelay() {
|
|
|
10279
10279
|
authorizationList: [authorizationTuple]
|
|
10280
10280
|
};
|
|
10281
10281
|
validateRelayInput(relayInput);
|
|
10282
|
-
return
|
|
10282
|
+
return relayContext(relayInput, {
|
|
10283
10283
|
idempotencyKey: opts.idempotencyKey
|
|
10284
10284
|
});
|
|
10285
10285
|
} catch (err) {
|
|
@@ -18383,9 +18383,9 @@ async function sendCalls(args) {
|
|
|
18383
18383
|
}
|
|
18384
18384
|
}
|
|
18385
18385
|
|
|
18386
|
-
// src/hooks/
|
|
18387
|
-
function
|
|
18388
|
-
const { user, config, provider, setProvider } =
|
|
18386
|
+
// src/hooks/useVolr.ts
|
|
18387
|
+
function useVolr() {
|
|
18388
|
+
const { user, config, provider, setProvider, logout, isLoading, error } = useVolrContext();
|
|
18389
18389
|
const { precheck } = usePrecheck();
|
|
18390
18390
|
const { relay } = useRelay();
|
|
18391
18391
|
const { client } = useInternalAuth();
|
|
@@ -18402,14 +18402,11 @@ function useVolrWallet() {
|
|
|
18402
18402
|
let extendedRpcClient = null;
|
|
18403
18403
|
const ensureRpcClient = async () => {
|
|
18404
18404
|
if (!publicClient) {
|
|
18405
|
-
console.log("[ensureRpcClient] Getting RPC URL for chainId:", chainId);
|
|
18406
18405
|
const rpcUrl = await getRpcUrl(chainId);
|
|
18407
|
-
console.log("[ensureRpcClient] Got RPC URL:", rpcUrl);
|
|
18408
18406
|
publicClient = createPublicClient({
|
|
18409
18407
|
transport: http(rpcUrl)
|
|
18410
18408
|
});
|
|
18411
18409
|
extendedRpcClient = createExtendedRPCClient(publicClient);
|
|
18412
|
-
console.log("[ensureRpcClient] Public client created");
|
|
18413
18410
|
}
|
|
18414
18411
|
return { publicClient, extendedRpcClient };
|
|
18415
18412
|
};
|
|
@@ -18418,12 +18415,12 @@ function useVolrWallet() {
|
|
|
18418
18415
|
const { publicClient: client2 } = await ensureRpcClient();
|
|
18419
18416
|
return client2.readContract(args);
|
|
18420
18417
|
},
|
|
18421
|
-
sendTransaction: async (tx, opts) => {
|
|
18418
|
+
sendTransaction: async (tx, opts = {}) => {
|
|
18422
18419
|
const { publicClient: publicClient2, extendedRpcClient: rpcClient } = await ensureRpcClient();
|
|
18423
18420
|
const from14 = opts.from ?? user?.evmAddress;
|
|
18424
18421
|
if (!from14) {
|
|
18425
18422
|
throw new Error(
|
|
18426
|
-
"from address is required. Provide it in opts.from or
|
|
18423
|
+
"from address is required. Provide it in opts.from or ensure user is logged in."
|
|
18427
18424
|
);
|
|
18428
18425
|
}
|
|
18429
18426
|
const call2 = {
|
|
@@ -18449,25 +18446,18 @@ function useVolrWallet() {
|
|
|
18449
18446
|
}
|
|
18450
18447
|
});
|
|
18451
18448
|
},
|
|
18452
|
-
sendBatch: (async (calls, opts) => {
|
|
18453
|
-
console.log("[sendBatch] Starting sendBatch...", { chainId, callsCount: calls.length });
|
|
18454
|
-
console.log("[sendBatch] Ensuring RPC client...");
|
|
18449
|
+
sendBatch: (async (calls, opts = {}) => {
|
|
18455
18450
|
const { publicClient: publicClient2, extendedRpcClient: rpcClient } = await ensureRpcClient();
|
|
18456
|
-
console.log("[sendBatch] RPC client ready");
|
|
18457
18451
|
const from14 = opts.from ?? user?.evmAddress;
|
|
18458
|
-
console.log("[sendBatch] From address:", from14);
|
|
18459
18452
|
if (!from14) {
|
|
18460
18453
|
throw new Error(
|
|
18461
|
-
"from address is required. Provide it in opts.from or
|
|
18454
|
+
"from address is required. Provide it in opts.from or ensure user is logged in."
|
|
18462
18455
|
);
|
|
18463
18456
|
}
|
|
18464
18457
|
const isCallArray = (calls2) => {
|
|
18465
18458
|
return Array.isArray(calls2) && calls2.length > 0 && "data" in calls2[0] && !("abi" in calls2[0]);
|
|
18466
18459
|
};
|
|
18467
|
-
console.log("[sendBatch] Building calls...");
|
|
18468
18460
|
const builtCalls = isCallArray(calls) ? calls : buildCalls(calls);
|
|
18469
|
-
console.log("[sendBatch] Calls built:", builtCalls.length);
|
|
18470
|
-
console.log("[sendBatch] Calling sendCalls...");
|
|
18471
18461
|
return sendCalls({
|
|
18472
18462
|
chainId,
|
|
18473
18463
|
from: getAddress(from14),
|
|
@@ -18492,12 +18482,21 @@ function useVolrWallet() {
|
|
|
18492
18482
|
})
|
|
18493
18483
|
};
|
|
18494
18484
|
},
|
|
18495
|
-
[user, config, provider, precheck, relay, getRpcUrl]
|
|
18485
|
+
[user, config, provider, precheck, relay, getRpcUrl, setProvider, client]
|
|
18496
18486
|
);
|
|
18497
|
-
return {
|
|
18487
|
+
return {
|
|
18488
|
+
evm,
|
|
18489
|
+
address: user?.evmAddress,
|
|
18490
|
+
email: user?.email,
|
|
18491
|
+
isLoggedIn: user !== null,
|
|
18492
|
+
signerType: user?.signerType,
|
|
18493
|
+
logout,
|
|
18494
|
+
isLoading,
|
|
18495
|
+
error
|
|
18496
|
+
};
|
|
18498
18497
|
}
|
|
18499
18498
|
function useVolrLogin() {
|
|
18500
|
-
const { config, setUser } =
|
|
18499
|
+
const { config, setUser } = useVolrContext();
|
|
18501
18500
|
const { setAccessToken, setRefreshToken, client } = useInternalAuth();
|
|
18502
18501
|
const toVolrUser = react.useCallback((u) => {
|
|
18503
18502
|
return {
|
|
@@ -18664,7 +18663,7 @@ function createAxiosInstance(baseUrl, apiKey) {
|
|
|
18664
18663
|
|
|
18665
18664
|
// src/hooks/useVolrAuthCallback.ts
|
|
18666
18665
|
function useVolrAuthCallback(options = {}) {
|
|
18667
|
-
const { config, setUser } =
|
|
18666
|
+
const { config, setUser } = useVolrContext();
|
|
18668
18667
|
const { refreshAccessToken, setAccessToken, setRefreshToken, client } = useInternalAuth();
|
|
18669
18668
|
const [isLoading, setIsLoading] = react.useState(true);
|
|
18670
18669
|
const [error, setError] = react.useState(null);
|
|
@@ -18789,7 +18788,7 @@ function balanceOfCalldata(address) {
|
|
|
18789
18788
|
return `${selector}${pad32(address).slice(2)}`;
|
|
18790
18789
|
}
|
|
18791
18790
|
function useDepositListener(input) {
|
|
18792
|
-
const { config } =
|
|
18791
|
+
const { config } = useVolrContext();
|
|
18793
18792
|
const { client } = useInternalAuth();
|
|
18794
18793
|
const [status, setStatus] = react.useState({ state: "idle" });
|
|
18795
18794
|
const intervalRef = react.useRef(null);
|
|
@@ -19043,7 +19042,7 @@ async function enrollPasskey(params) {
|
|
|
19043
19042
|
}
|
|
19044
19043
|
}
|
|
19045
19044
|
function usePasskeyEnrollment() {
|
|
19046
|
-
const { config, setProvider, setUser, user } =
|
|
19045
|
+
const { config, setProvider, setUser, user } = useVolrContext();
|
|
19047
19046
|
const { client } = useInternalAuth();
|
|
19048
19047
|
const [step, setStep] = react.useState("idle");
|
|
19049
19048
|
const [isEnrolling, setIsEnrolling] = react.useState(false);
|
|
@@ -19232,7 +19231,7 @@ async function registerWalletProvider(params) {
|
|
|
19232
19231
|
});
|
|
19233
19232
|
}
|
|
19234
19233
|
function useMpcConnection() {
|
|
19235
|
-
const { setProvider } =
|
|
19234
|
+
const { setProvider } = useVolrContext();
|
|
19236
19235
|
const { client } = useInternalAuth();
|
|
19237
19236
|
const [step, setStep] = react.useState("idle");
|
|
19238
19237
|
const [isConnecting, setIsConnecting] = react.useState(false);
|
|
@@ -19576,11 +19575,9 @@ exports.useDepositListener = useDepositListener;
|
|
|
19576
19575
|
exports.useInternalAuth = useInternalAuth;
|
|
19577
19576
|
exports.useMpcConnection = useMpcConnection;
|
|
19578
19577
|
exports.usePasskeyEnrollment = usePasskeyEnrollment;
|
|
19579
|
-
exports.usePrecheck = usePrecheck;
|
|
19580
|
-
exports.useRelay = useRelay;
|
|
19581
19578
|
exports.useVolr = useVolr;
|
|
19582
19579
|
exports.useVolrAuthCallback = useVolrAuthCallback;
|
|
19580
|
+
exports.useVolrContext = useVolrContext;
|
|
19583
19581
|
exports.useVolrLogin = useVolrLogin;
|
|
19584
|
-
exports.useVolrWallet = useVolrWallet;
|
|
19585
19582
|
//# sourceMappingURL=index.cjs.map
|
|
19586
19583
|
//# sourceMappingURL=index.cjs.map
|