Skip to content

Commit 50aed62

Browse files
committed
refactor(vault): address artifact-modal review feedback
1 parent 86018b3 commit 50aed62

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

services/vault/src/components/deposit/RecoveryArtifactsCard.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import { COPY } from "@/copy";
1616
import { useArtifactDownload } from "@/hooks/deposit/useArtifactDownload";
1717
import { hasArtifactsDownloaded } from "@/utils/artifactDownloadStorage";
1818

19-
const BYTES_PER_MB = 1024 * 1024;
20-
const BYTES_PER_GB = 1024 * 1024 * 1024;
19+
const BYTES_PER_KB = 1024;
20+
const BYTES_PER_MB = BYTES_PER_KB * 1024;
21+
const BYTES_PER_GB = BYTES_PER_MB * 1024;
2122

2223
// Brand orange (Tailwind's `secondary-main` token), inlined because
2324
// ProgressBar takes a raw CSS color rather than a class name.
@@ -65,7 +66,7 @@ function formatBytes(bytes: number): string {
6566
if (bytes >= BYTES_PER_MB) {
6667
return `${Math.round(bytes / BYTES_PER_MB)} MB`;
6768
}
68-
return `${Math.round(bytes / 1024)} KB`;
69+
return `${Math.round(bytes / BYTES_PER_KB)} KB`;
6970
}
7071

7172
interface RecoveryArtifactsCardProps {
@@ -168,7 +169,10 @@ export const RecoveryArtifactsCard = forwardRef<
168169
<>
169170
<div className="flex items-baseline justify-between gap-2">
170171
<span className="text-base leading-[1.5] tracking-[0.15px] text-accent-primary">
171-
<span>{formatBytes(receivedBytes)}</span>
172+
{/* Clamp to total so a gzip'd Content-Length or an
173+
underestimated fallback can't render "1.40 GB / 1.30 GB"
174+
— matches the percent/bar clamps below. */}
175+
<span>{formatBytes(Math.min(receivedBytes, totalBytes))}</span>
172176
<span className="text-accent-secondary">
173177
{" / "}
174178
{formatBytes(totalBytes)}

services/vault/src/copy.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,23 @@ export const COPY = {
312312
cardSizeDownloaded: "~1 GB",
313313
downloadButton: "Download Artifacts",
314314
downloadingButton: "Downloading...",
315-
cancelDownloadButton: "Cancel",
316-
downloadedLabel: "Downloaded",
317315
retryButton: "Retry",
318316
walletSignatureHint:
319317
"You may be asked to approve a signature in your wallet to authenticate.",
320318
// Caption under the progress bar while bytes are streaming.
321319
doNotCloseHint: "Do not close this window while downloading.",
322320
cannotAuthenticate:
323321
"Cannot authenticate with the vault provider. Please refresh and try again.",
322+
// Progress/status lines surfaced in the card while the download hook
323+
// works through its fetch / re-auth / wait-for-signatures states.
324+
fetchingArtifacts: "Fetching artifacts from vault provider...",
325+
reauthenticating: "Re-authenticating with vault provider...",
326+
waitingForSignatures:
327+
"Waiting for vault provider to process signatures...",
328+
// Error fallbacks shown when a thrown error carries no usable message.
329+
authenticationFailed: "Authentication failed",
330+
reauthenticationFailed: "Re-authentication failed",
331+
downloadFailed: "Download failed",
324332
},
325333
form: {
326334
computingAllocation: "Computing allocation...",

services/vault/src/hooks/deposit/useArtifactDownload.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function useArtifactDownload(options?: {
9696
setState({
9797
...INITIAL_STATE,
9898
loading: true,
99-
progress: "Fetching artifacts from vault provider...",
99+
progress: COPY.deposit.recoveryArtifacts.fetchingArtifacts,
100100
});
101101

102102
const normalizedPeginTxid = stripHexPrefix(peginTxid);
@@ -136,7 +136,7 @@ export function useArtifactDownload(options?: {
136136
setError(
137137
primeErr instanceof Error
138138
? primeErr.message
139-
: "Authentication failed",
139+
: COPY.deposit.recoveryArtifacts.authenticationFailed,
140140
);
141141
return false;
142142
}
@@ -157,7 +157,7 @@ export function useArtifactDownload(options?: {
157157

158158
setState((prev) => ({
159159
...prev,
160-
progress: "Re-authenticating with vault provider...",
160+
progress: COPY.deposit.recoveryArtifacts.reauthenticating,
161161
// Reset byte counters so the bar doesn't linger between attempts;
162162
// the next fetchAndDownloadArtifacts call seeds them from 0 again.
163163
receivedBytes: 0,
@@ -215,7 +215,7 @@ export function useArtifactDownload(options?: {
215215
if (isPreDepositorSignaturesError(err)) {
216216
setState((prev) => ({
217217
...prev,
218-
progress: "Waiting for vault provider to process signatures...",
218+
progress: COPY.deposit.recoveryArtifacts.waitingForSignatures,
219219
receivedBytes: 0,
220220
totalBytes: 0,
221221
}));
@@ -232,7 +232,7 @@ export function useArtifactDownload(options?: {
232232
if (primed && !cancelledRef.current) {
233233
setState((prev) => ({
234234
...prev,
235-
progress: "Fetching artifacts from vault provider...",
235+
progress: COPY.deposit.recoveryArtifacts.fetchingArtifacts,
236236
}));
237237
continue;
238238
}
@@ -241,14 +241,18 @@ export function useArtifactDownload(options?: {
241241
setError(
242242
primeErr instanceof Error
243243
? primeErr.message
244-
: "Re-authentication failed",
244+
: COPY.deposit.recoveryArtifacts.reauthenticationFailed,
245245
);
246246
return;
247247
}
248248
}
249249

250250
if (cancelledRef.current) return;
251-
setError(err instanceof Error ? err.message : "Download failed");
251+
setError(
252+
err instanceof Error
253+
? err.message
254+
: COPY.deposit.recoveryArtifacts.downloadFailed,
255+
);
252256
return;
253257
}
254258
}

0 commit comments

Comments
 (0)