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
19 changes: 9 additions & 10 deletions apps/frontend/src/components/ui/NodePicker/NodePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './NodePicker.scss';
import { Dropdown, Spinner, OverlayTrigger, Tooltip } from 'react-bootstrap';
import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { useInjectReducer } from '../../../hooks/use-injectreducer';
import nodesReducer from '../../../store/nodesSlice';
import { setIsSwitching, setIsDiscovering, setActiveProfileId } from '../../../store/nodesSlice';
Expand All @@ -18,7 +17,6 @@ import logger from '../../../services/logger.service';

const NodePicker = () => {
useInjectReducer('nodes', nodesReducer);
const { pathname } = useLocation();

const profiles = useSelector(selectNodeProfiles);
const activeProfile = useSelector(selectActiveProfile);
Expand Down Expand Up @@ -58,16 +56,17 @@ const NodePicker = () => {
appStore.dispatch(setIsSwitching(false));
}

// Non-critical background refresh — transactions, offers, plugin detection.
// Non-critical background refresh after profile switch. Eagerly refetches
// ALL section data (factories, CLN dashboard, bookkeeper) regardless of
// current pathname so the next page the user navigates to has fresh data
// for the new profile. Previously only the section matching the current
// pathname was refetched, which left e.g. the factories list empty when
// a user switched profile on /bookkeeper and then navigated to /factories.
// Fire-and-forget so a slow query on any node never blocks the UI.
const bgRefresh = pathname.includes('/bookkeeper')
? BookkeeperService.fetchBKPRData()
: pathname.includes('/factories')
? FactoriesService.fetchFactoriesData()
: CLNService.fetchCLNData();

Promise.all([
bgRefresh,
CLNService.fetchCLNData(),
BookkeeperService.fetchBKPRData(),
FactoriesService.fetchFactoriesData(),
NodesService.fetchAndDispatchNodes(),
NodesService.detectFactoryPlugin(),
]).catch(err => logger.error('Background post-switch refresh failed:', err));
Expand Down
9 changes: 8 additions & 1 deletion apps/frontend/src/routes/routerReduxSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { APP_WAIT_TIME } from '../utilities/constants';
import { useDispatch, useSelector } from 'react-redux';
import { BookkeeperService, CLNService, FactoriesService, NodesService, RootService } from '../services/http.service';
import { selectAuthStatus, selectNodeInfo } from '../store/rootSelectors';
import { selectActiveProfileId } from '../store/nodesSelectors';
import { appStore } from '../store/appStore';
import logger from '../services/logger.service';

Expand All @@ -17,6 +18,7 @@ export function RootRouterReduxSync() {
const { pathname } = useLocation();
const authStatus = useSelector(selectAuthStatus);
const nodeInfo = useSelector(selectNodeInfo);
const activeProfileId = useSelector(selectActiveProfileId);

// Fetch node profiles, run background discovery, detect factory plugin
useEffect(() => {
Expand Down Expand Up @@ -115,7 +117,12 @@ export function RootRouterReduxSync() {
if (pathname !== targetPath) {
navigate(targetPath, { replace: true });
}
}, [authStatus, pathname, navigate]);
// activeProfileId is in the deps so that switching the wallet's active
// node via NodePicker re-fires the current route's data fetch against
// the new node, even when pathname doesn't change. Without this, navigating
// /bookkeeper -> switch profile -> /factories left the factories list
// empty because the route-effect closure captured the pre-switch state.
}, [authStatus, pathname, navigate, activeProfileId]);

// Clear store on route unmounting
useEffect(() => {
Expand Down
Loading