@volr/react 0.1.49 → 0.1.54

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @volr/react
2
2
 
3
- Volr React SDK - React hooks and UI components for Volr Web3 Payment Builder.
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, useVolrWallet } from '@volr/react';
16
+ import { VolrProvider, useVolr } from '@volr/react';
17
17
 
18
18
  function App() {
19
19
  return (
@@ -29,58 +29,109 @@ function App() {
29
29
  }
30
30
 
31
31
  function YourApp() {
32
- const { evm } = useVolrWallet();
32
+ const { evm, 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: ['0x...'],
43
+ args: [evm.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
- to: '0x...',
46
- data: '0x...',
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
- ### Advanced Usage
64
+ ## API
65
+
66
+ ### useVolr
57
67
 
58
- For advanced users who need more control, you can use the low-level hooks:
68
+ Main hook for wallet operations.
59
69
 
60
70
  ```tsx
61
- import { usePrecheck, useRelay, buildCall } from '@volr/react';
71
+ const {
72
+ evm, // EvmNamespace - chain client factory + address
73
+ email, // string | undefined
74
+ isLoggedIn, // boolean
75
+ signerType, // 'passkey' | 'external_wallet' | 'mpc' | undefined
76
+ logout, // () => Promise<void>
77
+ isLoading, // boolean
78
+ error, // Error | null
79
+ } = useVolr();
80
+
81
+ // Get EVM address
82
+ const address = evm.address;
83
+
84
+ // Get chain client
85
+ const client = evm(8453);
86
+ ```
62
87
 
63
- function AdvancedComponent() {
64
- const { precheck } = usePrecheck();
65
- const { relay } = useRelay();
88
+ ### EvmClient
66
89
 
67
- // Build call manually
68
- const call = buildCall({
69
- target: '0x...',
90
+ Returned by `evm(chainId)`.
91
+
92
+ ```tsx
93
+ const client = evm(8453);
94
+
95
+ // Read contract
96
+ const balance = await client.readContract({
97
+ address: tokenAddress,
98
+ abi: erc20Abi,
99
+ functionName: 'balanceOf',
100
+ args: [userAddress],
101
+ });
102
+
103
+ // Send single transaction
104
+ const result = await client.sendTransaction({
105
+ to: '0x...',
106
+ data: '0x...',
107
+ value: 0n,
108
+ });
109
+
110
+ // Send batch (with ABI)
111
+ const result = await client.sendBatch([
112
+ {
113
+ target: tokenAddress,
70
114
  abi: erc20Abi,
71
115
  functionName: 'transfer',
72
- args: ['0x...', BigInt(1000000)],
73
- });
74
-
75
- // Use precheck and relay directly
76
- const quote = await precheck({ auth, calls: [call] });
77
- const result = await relay(input, { signer, rpcClient });
78
- }
116
+ args: [recipient, amount],
117
+ gasLimit: 100000n,
118
+ },
119
+ ]);
120
+
121
+ // Send batch (raw calls)
122
+ const result = await client.sendBatch([
123
+ {
124
+ target: '0x...',
125
+ data: '0x...',
126
+ value: 0n,
127
+ gasLimit: 100000n,
128
+ },
129
+ ]);
79
130
  ```
80
131
 
81
132
  ## Features
82
133
 
83
- - **Developer-Friendly API**: `useVolrWallet()` provides a simple, intuitive interface
134
+ - **Simple API**: `useVolr()` provides everything you need
84
135
  - **Session Management**: Automatic token refresh and tab synchronization
85
136
  - **EIP-7702 Support**: Gasless transactions with session keys
86
137
  - **Passkey Integration**: Secure signing with device passkeys
@@ -90,7 +141,7 @@ function AdvancedComponent() {
90
141
 
91
142
  ## OAuth Handling
92
143
 
93
- The SDK provides a dedicated hook `useVolrAuthCallback` to simplify handling OAuth redirects. This is useful for custom login flows where you need to process the callback from social providers (Google, Twitter, Apple).
144
+ The SDK provides `useVolrAuthCallback` to handle OAuth redirects:
94
145
 
95
146
  ```tsx
96
147
  import { useVolrAuthCallback } from '@volr/react';
@@ -99,11 +150,9 @@ function AuthCallback() {
99
150
  const { isLoading, error, isNewUser, user } = useVolrAuthCallback({
100
151
  onSuccess: (user) => {
101
152
  console.log('Logged in:', user);
102
- // Navigate to dashboard or home
103
153
  },
104
154
  onError: (err) => {
105
155
  console.error('Login failed:', err);
106
- // Show error message or redirect to login
107
156
  },
108
157
  });
109
158
 
@@ -114,33 +163,21 @@ function AuthCallback() {
114
163
  }
115
164
  ```
116
165
 
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
166
  ## Failure Semantics
124
167
 
125
- - Relay enforces strict failure-by-default:
126
- - `revertOnFail` defaults to `true` and any failed call reverts the entire batch.
127
- - Calls to non-contract addresses are rejected.
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.
168
+ - `revertOnFail` defaults to `true` - any failed call reverts the entire batch
169
+ - Calls to non-contract addresses are rejected
170
+ - For ERC20 methods, if a token returns `false`, the batch is treated as failed
130
171
 
131
172
  ## Diagnostics
132
173
 
133
- When gas estimation or simulation fails, the backend includes a `developerDiagnostics` object in the error response (and FAILED transaction meta). This contains:
174
+ When gas estimation or simulation fails, the backend includes `developerDiagnostics` in the error response:
175
+
176
+ - `topLevel.reason`: Decoded revert reason
177
+ - `calls[]`: Per-call diagnostics with `target`, `selector`, `isContract`, `callResult`, `decodedRevert`
134
178
 
135
- - `topLevel.reason`: Decoded revert reason for the overall execution attempt
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)
179
+ Use these to pinpoint which call failed and why.
141
180
 
142
- The SDK surfaces these in console for convenience:
143
- - Precheck errors: `[volr][precheck] developerDiagnostics: ...`
144
- - Relay errors: `[volr][relay] developerDiagnostics: ...`
181
+ ## License
145
182
 
146
- Use these to pinpoint which call failed and why (e.g., EOA target, ERC20 returned false, custom revert).
183
+ 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 useVolr() {
10107
+ function useVolrContext() {
10108
10108
  const context = react.useContext(VolrContext);
10109
10109
  if (!context) {
10110
- throw new Error("useVolr must be used within VolrProvider");
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 } = useVolr();
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 } = useVolr();
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 await relayContext(relayInput, {
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/useVolrWallet.ts
18387
- function useVolrWallet() {
18388
- const { user, config, provider, setProvider } = useVolr();
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();
@@ -18393,7 +18393,7 @@ function useVolrWallet() {
18393
18393
  createGetRpcUrl({ client, rpcOverrides: config.rpcOverrides }),
18394
18394
  [client, config.rpcOverrides]
18395
18395
  );
18396
- const evm = react.useCallback(
18396
+ const evmFactory = react.useCallback(
18397
18397
  (chainId) => {
18398
18398
  if (chainId === 0) {
18399
18399
  throw new Error("chainId cannot be 0");
@@ -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 set user.evmAddress in VolrProvider. If you haven't set up a wallet provider yet, please complete the onboarding flow."
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 set user.evmAddress in VolrProvider. If you haven't set up a wallet provider yet, please complete the onboarding flow."
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,23 @@ 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 { evm };
18487
+ const evm = Object.assign(evmFactory, {
18488
+ address: user?.evmAddress
18489
+ });
18490
+ return {
18491
+ evm,
18492
+ email: user?.email,
18493
+ isLoggedIn: user !== null,
18494
+ signerType: user?.signerType,
18495
+ logout,
18496
+ isLoading,
18497
+ error
18498
+ };
18488
18499
  }
18489
18500
  function useVolrLogin() {
18490
- const { config, setUser } = useVolr();
18501
+ const { config, setUser } = useVolrContext();
18491
18502
  const { setAccessToken, setRefreshToken, client } = useInternalAuth();
18492
18503
  const toVolrUser = react.useCallback((u) => {
18493
18504
  return {
@@ -18654,7 +18665,7 @@ function createAxiosInstance(baseUrl, apiKey) {
18654
18665
 
18655
18666
  // src/hooks/useVolrAuthCallback.ts
18656
18667
  function useVolrAuthCallback(options = {}) {
18657
- const { config, setUser } = useVolr();
18668
+ const { config, setUser } = useVolrContext();
18658
18669
  const { refreshAccessToken, setAccessToken, setRefreshToken, client } = useInternalAuth();
18659
18670
  const [isLoading, setIsLoading] = react.useState(true);
18660
18671
  const [error, setError] = react.useState(null);
@@ -18779,7 +18790,7 @@ function balanceOfCalldata(address) {
18779
18790
  return `${selector}${pad32(address).slice(2)}`;
18780
18791
  }
18781
18792
  function useDepositListener(input) {
18782
- const { config } = useVolr();
18793
+ const { config } = useVolrContext();
18783
18794
  const { client } = useInternalAuth();
18784
18795
  const [status, setStatus] = react.useState({ state: "idle" });
18785
18796
  const intervalRef = react.useRef(null);
@@ -19033,7 +19044,7 @@ async function enrollPasskey(params) {
19033
19044
  }
19034
19045
  }
19035
19046
  function usePasskeyEnrollment() {
19036
- const { config, setProvider, setUser, user } = useVolr();
19047
+ const { config, setProvider, setUser, user } = useVolrContext();
19037
19048
  const { client } = useInternalAuth();
19038
19049
  const [step, setStep] = react.useState("idle");
19039
19050
  const [isEnrolling, setIsEnrolling] = react.useState(false);
@@ -19222,7 +19233,7 @@ async function registerWalletProvider(params) {
19222
19233
  });
19223
19234
  }
19224
19235
  function useMpcConnection() {
19225
- const { setProvider } = useVolr();
19236
+ const { setProvider } = useVolrContext();
19226
19237
  const { client } = useInternalAuth();
19227
19238
  const [step, setStep] = react.useState("idle");
19228
19239
  const [isConnecting, setIsConnecting] = react.useState(false);
@@ -19566,11 +19577,9 @@ exports.useDepositListener = useDepositListener;
19566
19577
  exports.useInternalAuth = useInternalAuth;
19567
19578
  exports.useMpcConnection = useMpcConnection;
19568
19579
  exports.usePasskeyEnrollment = usePasskeyEnrollment;
19569
- exports.usePrecheck = usePrecheck;
19570
- exports.useRelay = useRelay;
19571
19580
  exports.useVolr = useVolr;
19572
19581
  exports.useVolrAuthCallback = useVolrAuthCallback;
19582
+ exports.useVolrContext = useVolrContext;
19573
19583
  exports.useVolrLogin = useVolrLogin;
19574
- exports.useVolrWallet = useVolrWallet;
19575
19584
  //# sourceMappingURL=index.cjs.map
19576
19585
  //# sourceMappingURL=index.cjs.map