@volr/react 0.1.49 → 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 +28 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -57
- package/dist/index.d.ts +49 -57
- package/dist/index.js +29 -20
- 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();
|
|
@@ -18415,12 +18415,12 @@ function useVolrWallet() {
|
|
|
18415
18415
|
const { publicClient: client2 } = await ensureRpcClient();
|
|
18416
18416
|
return client2.readContract(args);
|
|
18417
18417
|
},
|
|
18418
|
-
sendTransaction: async (tx, opts) => {
|
|
18418
|
+
sendTransaction: async (tx, opts = {}) => {
|
|
18419
18419
|
const { publicClient: publicClient2, extendedRpcClient: rpcClient } = await ensureRpcClient();
|
|
18420
18420
|
const from14 = opts.from ?? user?.evmAddress;
|
|
18421
18421
|
if (!from14) {
|
|
18422
18422
|
throw new Error(
|
|
18423
|
-
"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."
|
|
18424
18424
|
);
|
|
18425
18425
|
}
|
|
18426
18426
|
const call2 = {
|
|
@@ -18451,7 +18451,7 @@ function useVolrWallet() {
|
|
|
18451
18451
|
const from14 = opts.from ?? user?.evmAddress;
|
|
18452
18452
|
if (!from14) {
|
|
18453
18453
|
throw new Error(
|
|
18454
|
-
"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."
|
|
18455
18455
|
);
|
|
18456
18456
|
}
|
|
18457
18457
|
const isCallArray = (calls2) => {
|
|
@@ -18482,12 +18482,21 @@ function useVolrWallet() {
|
|
|
18482
18482
|
})
|
|
18483
18483
|
};
|
|
18484
18484
|
},
|
|
18485
|
-
[user, config, provider, precheck, relay, getRpcUrl]
|
|
18485
|
+
[user, config, provider, precheck, relay, getRpcUrl, setProvider, client]
|
|
18486
18486
|
);
|
|
18487
|
-
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
|
+
};
|
|
18488
18497
|
}
|
|
18489
18498
|
function useVolrLogin() {
|
|
18490
|
-
const { config, setUser } =
|
|
18499
|
+
const { config, setUser } = useVolrContext();
|
|
18491
18500
|
const { setAccessToken, setRefreshToken, client } = useInternalAuth();
|
|
18492
18501
|
const toVolrUser = react.useCallback((u) => {
|
|
18493
18502
|
return {
|
|
@@ -18654,7 +18663,7 @@ function createAxiosInstance(baseUrl, apiKey) {
|
|
|
18654
18663
|
|
|
18655
18664
|
// src/hooks/useVolrAuthCallback.ts
|
|
18656
18665
|
function useVolrAuthCallback(options = {}) {
|
|
18657
|
-
const { config, setUser } =
|
|
18666
|
+
const { config, setUser } = useVolrContext();
|
|
18658
18667
|
const { refreshAccessToken, setAccessToken, setRefreshToken, client } = useInternalAuth();
|
|
18659
18668
|
const [isLoading, setIsLoading] = react.useState(true);
|
|
18660
18669
|
const [error, setError] = react.useState(null);
|
|
@@ -18779,7 +18788,7 @@ function balanceOfCalldata(address) {
|
|
|
18779
18788
|
return `${selector}${pad32(address).slice(2)}`;
|
|
18780
18789
|
}
|
|
18781
18790
|
function useDepositListener(input) {
|
|
18782
|
-
const { config } =
|
|
18791
|
+
const { config } = useVolrContext();
|
|
18783
18792
|
const { client } = useInternalAuth();
|
|
18784
18793
|
const [status, setStatus] = react.useState({ state: "idle" });
|
|
18785
18794
|
const intervalRef = react.useRef(null);
|
|
@@ -19033,7 +19042,7 @@ async function enrollPasskey(params) {
|
|
|
19033
19042
|
}
|
|
19034
19043
|
}
|
|
19035
19044
|
function usePasskeyEnrollment() {
|
|
19036
|
-
const { config, setProvider, setUser, user } =
|
|
19045
|
+
const { config, setProvider, setUser, user } = useVolrContext();
|
|
19037
19046
|
const { client } = useInternalAuth();
|
|
19038
19047
|
const [step, setStep] = react.useState("idle");
|
|
19039
19048
|
const [isEnrolling, setIsEnrolling] = react.useState(false);
|
|
@@ -19222,7 +19231,7 @@ async function registerWalletProvider(params) {
|
|
|
19222
19231
|
});
|
|
19223
19232
|
}
|
|
19224
19233
|
function useMpcConnection() {
|
|
19225
|
-
const { setProvider } =
|
|
19234
|
+
const { setProvider } = useVolrContext();
|
|
19226
19235
|
const { client } = useInternalAuth();
|
|
19227
19236
|
const [step, setStep] = react.useState("idle");
|
|
19228
19237
|
const [isConnecting, setIsConnecting] = react.useState(false);
|
|
@@ -19566,11 +19575,9 @@ exports.useDepositListener = useDepositListener;
|
|
|
19566
19575
|
exports.useInternalAuth = useInternalAuth;
|
|
19567
19576
|
exports.useMpcConnection = useMpcConnection;
|
|
19568
19577
|
exports.usePasskeyEnrollment = usePasskeyEnrollment;
|
|
19569
|
-
exports.usePrecheck = usePrecheck;
|
|
19570
|
-
exports.useRelay = useRelay;
|
|
19571
19578
|
exports.useVolr = useVolr;
|
|
19572
19579
|
exports.useVolrAuthCallback = useVolrAuthCallback;
|
|
19580
|
+
exports.useVolrContext = useVolrContext;
|
|
19573
19581
|
exports.useVolrLogin = useVolrLogin;
|
|
19574
|
-
exports.useVolrWallet = useVolrWallet;
|
|
19575
19582
|
//# sourceMappingURL=index.cjs.map
|
|
19576
19583
|
//# sourceMappingURL=index.cjs.map
|