Skip to content

Commit ca09ba7

Browse files
committed
chore(pr): comments
1 parent 69acbcb commit ca09ba7

4 files changed

Lines changed: 55 additions & 23 deletions

File tree

services/vault/src/components/simple/DepositProgressView/DepositProgressView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ export function DepositProgressView(props: DepositProgressViewProps) {
184184
const visualStep = isComplete
185185
? TOTAL_VISUAL_STEPS + 1
186186
: getVisualStep(currentStep);
187+
// `currentStep` is the active action, but split deposits can have each vault
188+
// lane land on a different step after a recoverable per-vault failure. The
189+
// aggregate progress bar and completed-group pill must therefore use the
190+
// slowest lane, while the split columns below keep rendering their own steps.
187191
const aggregateRawStep =
188192
vaultCount > 1 && perVaultSteps && perVaultSteps.length > 0
189193
? perVaultSteps.reduce((minStep, step) =>
190194
getVisualStep(step) < getVisualStep(minStep) ? step : minStep,
191195
)
192196
: currentStep;
193-
// Split aggregate chrome reflects the laggard lane; columns still render
194-
// from their own steps below.
195197
const aggregateVisualStep = isComplete
196198
? TOTAL_VISUAL_STEPS + 1
197199
: getVisualStep(aggregateRawStep);

services/vault/src/components/simple/DepositSignContent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ export function DepositSignContent({
112112
</button>
113113
</div>
114114
);
115+
// Soft deposit-flow warnings from `useDepositFlow`: recoverable issues such
116+
// as local persistence failures or per-vault WOTS/payout steps that were
117+
// skipped/failed while the rest of the split deposit kept moving.
115118
const warningCallouts = lastWarnings.map((warning) => (
116119
<Callout key={warning} variant="warning">
117120
{warning}

services/vault/src/hooks/deposit/depositFlowSteps/batchReadiness.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Hex } from "viem";
99

1010
import { POLLING_INTERVAL_MS } from "@/config/polling";
1111
import { logger } from "@/infrastructure";
12+
import { abortableSleep } from "@/utils/async";
1213
import { createVpClient } from "@/utils/rpc";
1314

1415
export type BatchReadinessStatus = "ready" | "waiting" | "terminal";
@@ -33,25 +34,11 @@ export interface WaitForBatchReadinessParams {
3334
pollIntervalMs?: number;
3435
}
3536

36-
function sleep(ms: number, signal?: AbortSignal): Promise<void> {
37-
if (ms <= 0) return Promise.resolve();
38-
return new Promise((resolve, reject) => {
39-
const timeout = setTimeout(() => {
40-
signal?.removeEventListener("abort", onAbort);
41-
resolve();
42-
}, ms);
43-
const onAbort = () => {
44-
clearTimeout(timeout);
45-
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
46-
};
47-
if (signal) {
48-
if (signal.aborted) {
49-
onAbort();
50-
return;
51-
}
52-
signal.addEventListener("abort", onAbort, { once: true });
53-
}
54-
});
37+
const MIN_POLL_INTERVAL_MS = 1;
38+
39+
function getMaxPollAttempts(timeoutMs: number, pollIntervalMs: number): number {
40+
if (timeoutMs <= 0) return 1;
41+
return Math.ceil(timeoutMs / pollIntervalMs) + 1;
5542
}
5643

5744
export async function waitForBatchReadiness({
@@ -70,9 +57,20 @@ export async function waitForBatchReadiness({
7057
const readyVaultIds = new Set<Hex>();
7158
const terminalVaultIds = new Set<Hex>();
7259
const deadline = Date.now() + timeoutMs;
60+
const effectivePollIntervalMs = Math.max(
61+
MIN_POLL_INTERVAL_MS,
62+
pollIntervalMs,
63+
);
64+
const maxPollAttempts = getMaxPollAttempts(
65+
timeoutMs,
66+
effectivePollIntervalMs,
67+
);
7368
const rpcClient = createVpClient(providerAddress);
7469

75-
while (readyVaultIds.size + terminalVaultIds.size < vaults.length) {
70+
// Bound the poller by timeout-derived attempts: one immediate poll, then at
71+
// most one poll per interval until the deadline. This keeps the helper from
72+
// spinning forever if a VP keeps returning only waiting/missing statuses.
73+
for (let attempt = 0; attempt < maxPollAttempts; attempt += 1) {
7674
signal?.throwIfAborted();
7775

7876
const pendingVaults = vaults.filter(
@@ -129,7 +127,10 @@ export async function waitForBatchReadiness({
129127

130128
const remainingMs = deadline - Date.now();
131129
if (remainingMs <= 0) break;
132-
await sleep(Math.min(pollIntervalMs, remainingMs), signal);
130+
await abortableSleep(
131+
Math.min(effectivePollIntervalMs, remainingMs),
132+
signal,
133+
);
133134
}
134135

135136
return { readyVaultIds, terminalVaultIds };

services/vault/src/utils/async.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export function abortableSleep(
2+
ms: number,
3+
signal?: AbortSignal,
4+
): Promise<void> {
5+
if (ms <= 0) return Promise.resolve();
6+
7+
return new Promise((resolve, reject) => {
8+
const timeout = setTimeout(() => {
9+
signal?.removeEventListener("abort", onAbort);
10+
resolve();
11+
}, ms);
12+
13+
const onAbort = () => {
14+
clearTimeout(timeout);
15+
reject(signal?.reason ?? new DOMException("Aborted", "AbortError"));
16+
};
17+
18+
if (signal) {
19+
if (signal.aborted) {
20+
onAbort();
21+
return;
22+
}
23+
signal.addEventListener("abort", onAbort, { once: true });
24+
}
25+
});
26+
}

0 commit comments

Comments
 (0)