Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions client/src/components/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,18 @@ export function SettingsPage() {
const [storefrontEnabled, setStorefrontEnabled] = useState(false);
const [savingStorefront, setSavingStorefront] = useState(false);
const [saving, setSaving] = useState(false);
const [loadingSettings, setLoadingSettings] = useState(true);
const [loadingSettings, setLoadingSettings] = useState(() => hasIdentity());
const [settingsChanged, setSettingsChanged] = useState(false);

// Blossom server state
const [blossomServer, setBlossomServerState] = useState(getBlossomServer());
const [customBlossomUrl, setCustomBlossomUrl] = useState('');
// Kept in sync after mount by the preset/submit handlers below — no effect needed.
const [customBlossomUrl, setCustomBlossomUrl] = useState(() =>
PRESET_BLOSSOM_SERVERS.some((s) => s.url === blossomServer) ? '' : blossomServer
);
const [blossomUrlError, setBlossomUrlError] = useState('');
const [mirroringEnabled, setMirroringEnabledState] = useState(getMirroringEnabled());

const isCustomServer = !PRESET_BLOSSOM_SERVERS.some((s) => s.url === blossomServer);

useEffect(() => {
if (isCustomServer) {
setCustomBlossomUrl(blossomServer);
}
}, [blossomServer, isCustomServer]);

useEffect(() => {
if (hasIdentity()) {
const pubkey = getPublicKeyHex();
Expand All @@ -77,8 +72,6 @@ export function SettingsPage() {
})
.catch(() => {})
.finally(() => setLoadingSettings(false));
} else {
setLoadingSettings(false);
}
}, []);

Expand Down Expand Up @@ -166,6 +159,7 @@ export function SettingsPage() {
}
setBlossomServer(normalized);
setBlossomServerState(normalized);
setCustomBlossomUrl(normalized);
setBlossomUrlError('');
toast.showToast('Blossom server updated', 'success');
};
Expand Down
54 changes: 28 additions & 26 deletions client/src/components/UnlockPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,24 @@ export function UnlockPage() {
() => verifyGeneratedPreviewBundle(unlock.stash?.generatedPreview, unlock.stash?.previewProof),
[unlock.stash?.generatedPreview, unlock.stash?.previewProof]
);
const generatedPreview = unlock.stash?.generatedPreview;
const previewStats = useMemo(() => {
if (!unlock.stash?.generatedPreview || unlock.stash.generatedPreview.kind !== 'text-peek') {
if (!generatedPreview || generatedPreview.kind !== 'text-peek') {
return null;
}

const metadata = unlock.stash.generatedPreview.metadata as TextPreviewMetadata;
const metadata = generatedPreview.metadata as TextPreviewMetadata;
const percent =
unlock.stash.generatedPreview.fileSize > 0
? Math.round((metadata.previewBytes / unlock.stash.generatedPreview.fileSize) * 1000) / 10
generatedPreview.fileSize > 0
? Math.round((metadata.previewBytes / generatedPreview.fileSize) * 1000) / 10
: 0;

return {
bytes: metadata.previewBytes,
lines: metadata.linesIncluded,
percent,
};
}, [unlock.stash?.generatedPreview]);
}, [generatedPreview]);
const previewProofInvalid = previewVerification.state === 'invalid';
const legacyTextPeek =
unlock.stash?.generatedPreview?.kind === 'text-peek' &&
Expand Down Expand Up @@ -212,21 +213,7 @@ export function UnlockPage() {
}
}, [id, previewProofInvalid, startTimerAndPolling]);

// Auto-create or resume invoice when Lightning tab is active and stash is loaded
useEffect(() => {
if (
tab !== 'lightning' ||
!unlock.stash ||
invoice ||
lnLoading ||
unlock.status !== 'ready' ||
!claimAttempted.current ||
previewProofInvalid
) {
return;
}

// Try to resume a persisted invoice from sessionStorage
const startOrResumeInvoice = useCallback(() => {
if (id) {
try {
const saved = sessionStorage.getItem(`stashu-invoice-${id}`);
Expand All @@ -237,26 +224,41 @@ export function UnlockPage() {
// Resume polling the existing invoice
startTimerAndPolling(parsed.invoice, parsed.quoteId, parsed.expiresAt);
return;
} else {
// Expired — clean up
sessionStorage.removeItem(`stashu-invoice-${id}`);
}
// Expired — clean up
sessionStorage.removeItem(`stashu-invoice-${id}`);
}
} catch {
// Corrupted storage — ignore
}
}

createInvoice();
}, [id, createInvoice, startTimerAndPolling]);

// Auto-create or resume invoice when Lightning tab is active and stash is loaded
useEffect(() => {
if (
tab !== 'lightning' ||
!unlock.stash ||
invoice ||
lnLoading ||
unlock.status !== 'ready' ||
!claimAttempted.current ||
previewProofInvalid
) {
return;
}

// Records the invoice the mint hands back, so the extra render here is intentional.
startOrResumeInvoice();
}, [
tab,
unlock.stash,
invoice,
lnLoading,
unlock.status,
id,
createInvoice,
startTimerAndPolling,
startOrResumeInvoice,
previewProofInvalid,
]);

Expand Down
Loading