@volr/react 0.1.29 → 0.1.31
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/dist/index.cjs +11 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -71
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9066,20 +9066,16 @@ var APIClient = class {
|
|
|
9066
9066
|
(response) => response,
|
|
9067
9067
|
async (error) => {
|
|
9068
9068
|
const originalRequest = error.config;
|
|
9069
|
-
console.log(`[APIClient] Response error:`, error.response?.status, originalRequest?.url);
|
|
9070
9069
|
if (originalRequest?.url?.includes("/auth/refresh")) {
|
|
9071
|
-
console.log("[APIClient] Refresh endpoint failed, not retrying");
|
|
9072
9070
|
return Promise.reject(error);
|
|
9073
9071
|
}
|
|
9074
9072
|
if (error.response?.status === 401 && !originalRequest._retry) {
|
|
9075
|
-
console.log("[APIClient] 401 received, attempting token refresh...");
|
|
9076
9073
|
originalRequest._retry = true;
|
|
9077
9074
|
try {
|
|
9078
9075
|
await this.refreshAccessToken();
|
|
9079
9076
|
if (this.accessToken) {
|
|
9080
9077
|
originalRequest.headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
9081
9078
|
}
|
|
9082
|
-
console.log("[APIClient] Token refreshed, retrying original request");
|
|
9083
9079
|
return this.api(originalRequest);
|
|
9084
9080
|
} catch (refreshError) {
|
|
9085
9081
|
console.error("[APIClient] Token refresh failed:", refreshError);
|
|
@@ -9251,7 +9247,6 @@ var APIClient = class {
|
|
|
9251
9247
|
*/
|
|
9252
9248
|
async post(endpoint, body, idempotencyKey) {
|
|
9253
9249
|
const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
|
|
9254
|
-
console.log(`[APIClient] POST ${normalizedEndpoint}`);
|
|
9255
9250
|
const config = {
|
|
9256
9251
|
method: "POST",
|
|
9257
9252
|
url: normalizedEndpoint,
|
|
@@ -9264,7 +9259,6 @@ var APIClient = class {
|
|
|
9264
9259
|
}
|
|
9265
9260
|
try {
|
|
9266
9261
|
const response = await this.api.request(config);
|
|
9267
|
-
console.log(`[APIClient] POST ${normalizedEndpoint} response:`, response.data);
|
|
9268
9262
|
return unwrapResponse(response.data);
|
|
9269
9263
|
} catch (error) {
|
|
9270
9264
|
console.error(`[APIClient] POST ${normalizedEndpoint} error:`, error);
|
|
@@ -9656,29 +9650,12 @@ async function restorePasskey(params) {
|
|
|
9656
9650
|
"Credential ID not found. Please provide credentialId in params, prfInput, or ensure it is stored in localStorage. If you recently enrolled a passkey, try refreshing the page or re-enrolling."
|
|
9657
9651
|
);
|
|
9658
9652
|
}
|
|
9659
|
-
console.log("[restorePasskey] Using credentialId:", credentialId ? "present" : "MISSING");
|
|
9660
|
-
console.log(
|
|
9661
|
-
"[restorePasskey] credentialId source:",
|
|
9662
|
-
providedCredentialId ? "params" : prfInput.credentialId ? "prfInput" : "localStorage"
|
|
9663
|
-
);
|
|
9664
|
-
console.log("[restorePasskey] prfInput:", prfInput);
|
|
9665
|
-
console.log("[restorePasskey] Step 1: Ensuring access token is fresh...");
|
|
9666
|
-
try {
|
|
9667
|
-
await client.ensureAccessToken();
|
|
9668
|
-
console.log("[restorePasskey] Access token ensured");
|
|
9669
|
-
} catch (error) {
|
|
9670
|
-
console.error("[restorePasskey] Failed to ensure access token:", error);
|
|
9671
|
-
throw new Error("Failed to refresh access token. Please log in again.");
|
|
9672
|
-
}
|
|
9673
|
-
console.log("[restorePasskey] Step 2: Downloading blob via backend proxy for blobUrl:", blobUrl);
|
|
9674
9653
|
const apiKey = client.getApiKey();
|
|
9675
9654
|
if (!apiKey) {
|
|
9676
|
-
console.error("[restorePasskey] API key not set in client. This is required for blob download.");
|
|
9677
9655
|
throw new Error(
|
|
9678
9656
|
"API key not configured. Please ensure VolrProvider is initialized with projectApiKey in config."
|
|
9679
9657
|
);
|
|
9680
9658
|
}
|
|
9681
|
-
console.log("[restorePasskey] API key is set:", apiKey ? "present" : "MISSING");
|
|
9682
9659
|
const arrayBuffer = await client.postBinary("/blob/download", { key: blobUrl });
|
|
9683
9660
|
const blobBytes = new Uint8Array(arrayBuffer);
|
|
9684
9661
|
const nonceLength = 12;
|
|
@@ -9699,7 +9676,6 @@ async function restorePasskey(params) {
|
|
|
9699
9676
|
prfInput: {
|
|
9700
9677
|
...prfInput,
|
|
9701
9678
|
credentialId
|
|
9702
|
-
// Add credentialId to prfInput
|
|
9703
9679
|
},
|
|
9704
9680
|
encryptedBlob: {
|
|
9705
9681
|
cipher,
|
|
@@ -9707,10 +9683,7 @@ async function restorePasskey(params) {
|
|
|
9707
9683
|
},
|
|
9708
9684
|
aad: aadBytes
|
|
9709
9685
|
});
|
|
9710
|
-
|
|
9711
|
-
return {
|
|
9712
|
-
provider
|
|
9713
|
-
};
|
|
9686
|
+
return { provider };
|
|
9714
9687
|
}
|
|
9715
9688
|
|
|
9716
9689
|
// src/react/hooks/useAutoRecover.ts
|
|
@@ -18217,13 +18190,17 @@ function extractFailureReason(response) {
|
|
|
18217
18190
|
}
|
|
18218
18191
|
return "Transaction failed on-chain (no specific reason provided)";
|
|
18219
18192
|
}
|
|
18220
|
-
|
|
18193
|
+
function getPollingInterval(attempt) {
|
|
18194
|
+
if (attempt < 3) return 1e3;
|
|
18195
|
+
if (attempt < 8) return 2e3;
|
|
18196
|
+
return 5e3;
|
|
18197
|
+
}
|
|
18198
|
+
async function pollTransactionStatus(txId, client, maxAttempts = 60) {
|
|
18221
18199
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
18222
18200
|
try {
|
|
18223
18201
|
const response = await client.get(`/wallet/transactions/${txId}`);
|
|
18224
18202
|
const { status, txHash } = response;
|
|
18225
18203
|
if (status === "CONFIRMED") {
|
|
18226
|
-
console.log(`[pollTransactionStatus] Transaction ${txId} confirmed with txHash ${txHash}`);
|
|
18227
18204
|
return {
|
|
18228
18205
|
txId,
|
|
18229
18206
|
status: "CONFIRMED",
|
|
@@ -18247,10 +18224,11 @@ async function pollTransactionStatus(txId, client, maxAttempts = 60, intervalMs
|
|
|
18247
18224
|
};
|
|
18248
18225
|
return failedResult;
|
|
18249
18226
|
}
|
|
18250
|
-
|
|
18227
|
+
const intervalMs = getPollingInterval(attempt);
|
|
18251
18228
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
18252
18229
|
} catch (error) {
|
|
18253
18230
|
console.error(`[pollTransactionStatus] Error polling transaction ${txId}:`, error);
|
|
18231
|
+
const intervalMs = getPollingInterval(attempt);
|
|
18254
18232
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
18255
18233
|
}
|
|
18256
18234
|
}
|
|
@@ -18263,24 +18241,19 @@ async function pollTransactionStatus(txId, client, maxAttempts = 60, intervalMs
|
|
|
18263
18241
|
|
|
18264
18242
|
// src/wallet/sender.ts
|
|
18265
18243
|
async function sendCalls(args) {
|
|
18266
|
-
console.log("[sendCalls] Starting sendCalls...");
|
|
18267
18244
|
const { chainId, from: from14, calls, opts, deps } = args;
|
|
18268
18245
|
if (chainId === 0) {
|
|
18269
18246
|
throw new Error("chainId cannot be 0");
|
|
18270
18247
|
}
|
|
18271
|
-
console.log("[sendCalls] Normalizing calls...");
|
|
18272
18248
|
const normalizedFrom = from14;
|
|
18273
18249
|
const normalizedCalls = normalizeCalls(calls);
|
|
18274
18250
|
validateCalls2(normalizedCalls);
|
|
18275
|
-
console.log("[sendCalls] Calls normalized");
|
|
18276
18251
|
let currentUser = deps.user;
|
|
18277
18252
|
if (deps.user?.keyStorageType === "passkey" && !deps.provider) {
|
|
18278
|
-
console.log("[sendCalls] Refreshing user data (provider not available)...");
|
|
18279
18253
|
try {
|
|
18280
18254
|
const refreshedUser = await deps.client.refreshSession();
|
|
18281
18255
|
if (refreshedUser) {
|
|
18282
18256
|
currentUser = refreshedUser;
|
|
18283
|
-
console.log("[sendCalls] User data refreshed successfully");
|
|
18284
18257
|
}
|
|
18285
18258
|
} catch (error) {
|
|
18286
18259
|
console.error("[sendCalls] Failed to refresh session:", error);
|
|
@@ -18288,13 +18261,7 @@ async function sendCalls(args) {
|
|
|
18288
18261
|
`Failed to refresh session before transaction. ${error instanceof Error ? error.message : "Unknown error"}. Please try logging in again.`
|
|
18289
18262
|
);
|
|
18290
18263
|
}
|
|
18291
|
-
} else {
|
|
18292
|
-
console.log("[sendCalls] Skipping user refresh:", {
|
|
18293
|
-
hasProvider: !!deps.provider,
|
|
18294
|
-
keyStorageType: deps.user?.keyStorageType
|
|
18295
|
-
});
|
|
18296
18264
|
}
|
|
18297
|
-
console.log("[sendCalls] Building temp auth for first precheck...");
|
|
18298
18265
|
const tempAuthForPrecheck = buildTempAuth({
|
|
18299
18266
|
chainId,
|
|
18300
18267
|
from: normalizedFrom,
|
|
@@ -18304,16 +18271,10 @@ async function sendCalls(args) {
|
|
|
18304
18271
|
});
|
|
18305
18272
|
let precheckQuote;
|
|
18306
18273
|
try {
|
|
18307
|
-
console.log("[sendCalls] Running first precheck...");
|
|
18308
18274
|
precheckQuote = await deps.precheck({
|
|
18309
18275
|
auth: tempAuthForPrecheck,
|
|
18310
18276
|
calls: normalizedCalls
|
|
18311
18277
|
});
|
|
18312
|
-
console.log("[sendCalls] First precheck done:", {
|
|
18313
|
-
policyId: precheckQuote.policyId,
|
|
18314
|
-
simulationSuccess: precheckQuote.simulationSuccess,
|
|
18315
|
-
estimatedGasPerCall: precheckQuote.estimatedGasPerCall
|
|
18316
|
-
});
|
|
18317
18278
|
} catch (err) {
|
|
18318
18279
|
console.error("[sendCalls] First precheck failed:", err);
|
|
18319
18280
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -18327,14 +18288,10 @@ async function sendCalls(args) {
|
|
|
18327
18288
|
console.warn("[sendCalls] Proceeding despite simulation failure - EIP-7702 execution context may differ");
|
|
18328
18289
|
}
|
|
18329
18290
|
if (precheckQuote.estimatedGasPerCall?.length) {
|
|
18330
|
-
console.log("[sendCalls] Applying estimated gas limits from backend...");
|
|
18331
18291
|
for (let i = 0; i < normalizedCalls.length && i < precheckQuote.estimatedGasPerCall.length; i++) {
|
|
18332
18292
|
const estimatedGas = BigInt(precheckQuote.estimatedGasPerCall[i] ?? "0");
|
|
18333
18293
|
const currentGas = normalizedCalls[i]?.gasLimit ?? 0n;
|
|
18334
|
-
if (currentGas > 0n) {
|
|
18335
|
-
console.log(`[sendCalls] Call #${i}: keeping frontend gasLimit ${currentGas} (backend estimated: ${estimatedGas})`);
|
|
18336
|
-
} else if (estimatedGas > 0n) {
|
|
18337
|
-
console.log(`[sendCalls] Call #${i}: using backend gasLimit ${estimatedGas}`);
|
|
18294
|
+
if (currentGas === 0n && estimatedGas > 0n) {
|
|
18338
18295
|
normalizedCalls[i].gasLimit = estimatedGas;
|
|
18339
18296
|
}
|
|
18340
18297
|
}
|
|
@@ -18345,7 +18302,6 @@ async function sendCalls(args) {
|
|
|
18345
18302
|
}
|
|
18346
18303
|
const projectPolicyId = quotePolicyId;
|
|
18347
18304
|
validatePolicyId2(projectPolicyId);
|
|
18348
|
-
console.log("[sendCalls] Building temp auth for second precheck...");
|
|
18349
18305
|
const tempAuth = buildTempAuth({
|
|
18350
18306
|
chainId,
|
|
18351
18307
|
from: normalizedFrom,
|
|
@@ -18354,21 +18310,11 @@ async function sendCalls(args) {
|
|
|
18354
18310
|
// Now with updated gas limits
|
|
18355
18311
|
expiresInSec: opts.expiresInSec ?? DEFAULT_EXPIRES_IN_SEC
|
|
18356
18312
|
});
|
|
18357
|
-
|
|
18358
|
-
try {
|
|
18359
|
-
console.log("[sendCalls] Running second precheck...");
|
|
18360
|
-
quote = await deps.precheck({ auth: tempAuth, calls: normalizedCalls });
|
|
18361
|
-
console.log("[sendCalls] Second precheck done");
|
|
18362
|
-
} catch (err) {
|
|
18363
|
-
console.warn("[sendCalls] Second precheck failed:", err);
|
|
18364
|
-
}
|
|
18365
|
-
console.log("[sendCalls] Finalizing auth with nonce...");
|
|
18366
|
-
const auth = finalizeAuthWithNonce(tempAuth, quote);
|
|
18313
|
+
const auth = finalizeAuthWithNonce(tempAuth, precheckQuote);
|
|
18367
18314
|
const idempotencyKey = opts.idempotencyKey ?? defaultIdempotencyKey();
|
|
18368
18315
|
let signer;
|
|
18369
18316
|
let activeProvider = null;
|
|
18370
18317
|
try {
|
|
18371
|
-
console.log("[sendCalls] Resolving signer...");
|
|
18372
18318
|
const resolved = await resolveSigner({
|
|
18373
18319
|
explicitSigner: void 0,
|
|
18374
18320
|
// Always resolve internally
|
|
@@ -18380,17 +18326,11 @@ async function sendCalls(args) {
|
|
|
18380
18326
|
});
|
|
18381
18327
|
signer = resolved.signer;
|
|
18382
18328
|
activeProvider = resolved.activeProvider;
|
|
18383
|
-
console.log("[sendCalls] Signer resolved");
|
|
18384
|
-
console.log("[sendCalls] Calling relay...");
|
|
18385
18329
|
const result = await deps.relay(
|
|
18386
18330
|
{ chainId, from: normalizedFrom, auth, calls: normalizedCalls },
|
|
18387
18331
|
{ signer, rpcClient: deps.rpcClient, idempotencyKey }
|
|
18388
18332
|
);
|
|
18389
|
-
console.log("[sendCalls] Relay result:", result.status, result.txId);
|
|
18390
18333
|
if (result.status === "QUEUED" || result.status === "PENDING") {
|
|
18391
|
-
console.log(
|
|
18392
|
-
`[sendCalls] Transaction ${result.txId} is ${result.status}, starting polling...`
|
|
18393
|
-
);
|
|
18394
18334
|
return pollTransactionStatus(result.txId, deps.client);
|
|
18395
18335
|
}
|
|
18396
18336
|
return result;
|