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
23 changes: 21 additions & 2 deletions src/contexts/wallet-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -759,23 +759,42 @@ export const WalletProvider = ({ children, testXpub }: { children: ReactNode; te
if (!hasCachedData) {
console.log(`[WalletContext] Starting progressive discovery for wallet switch ${activeXpub.substring(0, 20)}...`);

let receivedComplete = false;
const result = await getWalletDataProgressive(activeXpub, currency, (partialData: PartialWalletData) => {
if (requestId !== activeRequestId.current) {
return;
}
// Once a completion update has been applied, ignore any late or
// out-of-order partial emit so it can't revert the finished dashboard
// back to a partial (lower-balance / fewer-tx) view.
if (receivedComplete) {
return;
}
// Real-time UI updates as addresses are discovered!
console.log(`[WalletContext] Progressive update - ${partialData.discoveryProgress.addressesWithActivity} addresses, ${partialData.transactions.length} txs, ${partialData.balanceBTC} BTC`);

// Update discovery progress
setDiscoveryProgress(partialData.discoveryProgress);

// Update wallet data with partial results
// Convert PartialWalletData to WalletData by removing progressive fields
const { discoveryProgress, isComplete, ...walletData } = partialData;
setData(walletData as WalletData);
// During the discovery phase we receive progress-only updates with no
// wallet data yet. Don't clobber the loading skeleton with an empty
// snapshot - only surface data once there's something to show (or when
// discovery has completed, which also covers the empty-wallet case).
const hasContent =
isComplete ||
walletData.transactions.length > 0 ||
walletData.balanceBTC > 0 ||
walletData.usedAddressCount > 0;
if (hasContent) {
setData(walletData as WalletData);
}

// If complete, mark as no longer discovering
if (partialData.isComplete) {
receivedComplete = true;
setIsDiscovering(false);
setIsLoading(false);
}
Expand Down
Loading
Loading