Skip to content

Commit 0e812d4

Browse files
Merge pull request #113 from Chia-Network/disconnect-button-fixes
fix: make disconnect button more reliable
2 parents c6e7b5d + dd60419 commit 0e812d4

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/renderer/api/cadt/v1/system/system.api.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,21 @@ const systemApi = cadtApi.injectEndpoints({
5252
method: 'GET',
5353
}),
5454
transformResponse(baseQueryReturnValue: BaseQueryResult<Config>): Config | undefined {
55+
// Check if response is empty, null, or HTML content (which would indicate a 404 served as index.html)
5556
if (_.isEmpty(baseQueryReturnValue) || _.isNil(baseQueryReturnValue)) {
5657
return undefined;
5758
}
58-
return baseQueryReturnValue;
59+
60+
if (typeof baseQueryReturnValue === 'string' && baseQueryReturnValue.includes('<!doctype html>')) {
61+
return undefined;
62+
}
63+
64+
// Ensure it's a valid config object with expected structure
65+
if (typeof baseQueryReturnValue === 'object' && baseQueryReturnValue !== null) {
66+
return baseQueryReturnValue as Config;
67+
}
68+
69+
return undefined;
5970
},
6071
}),
6172
getThemeColors: builder.query<any, void>({
@@ -64,10 +75,19 @@ const systemApi = cadtApi.injectEndpoints({
6475
method: 'GET',
6576
}),
6677
transformResponse(baseQueryReturnValue: BaseQueryResult<any>): any {
67-
if (_.isEmpty(baseQueryReturnValue) || _.isNil(baseQueryReturnValue)) {
78+
// Check if response is empty, null, or HTML content (which would indicate a 404 served as index.html)
79+
if (
80+
_.isEmpty(baseQueryReturnValue) ||
81+
_.isNil(baseQueryReturnValue) ||
82+
(typeof baseQueryReturnValue === 'string' && baseQueryReturnValue.includes('<!doctype html>'))
83+
) {
6884
return undefined;
6985
}
70-
return baseQueryReturnValue;
86+
// Ensure it's a valid object
87+
if (typeof baseQueryReturnValue === 'object' && baseQueryReturnValue !== null) {
88+
return baseQueryReturnValue;
89+
}
90+
return undefined;
7191
},
7292
}),
7393
}),

src/renderer/components/blocks/buttons/ConnectButton.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useDispatch, useSelector } from 'react-redux';
88
import { RootState } from '@/store';
99
import { resetApiHost } from '@/store/slices/app';
1010
import { reloadApplication } from '@/utils/unified-ui-utils';
11+
import { cadtApi } from '@/api/cadt/v1';
1112

1213
const ConnectButton: React.FC = () => {
1314
const location = useLocation();
@@ -33,6 +34,13 @@ const ConnectButton: React.FC = () => {
3334

3435
const handleDisconnect = () => {
3536
dispatch(resetApiHost());
37+
// Clear persisted storage to prevent auto-reconnection
38+
localStorage.removeItem('persist:app');
39+
sessionStorage.removeItem('persist:app');
40+
41+
// Clear RTK Query cache to force fresh health check
42+
dispatch(cadtApi.util.resetApiState());
43+
3644
setTimeout(() => reloadApplication(), 0);
3745
};
3846

src/renderer/store/slices/app/app.initialstate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface AppState {
99

1010
const initialState: AppState = {
1111
locale: null,
12-
apiHost: 'http://localhost:31310',
12+
apiHost: '', // Empty string means no default API host
1313
apiKey: null,
1414
configFileLoaded: false,
1515
isDarkTheme: false,

0 commit comments

Comments
 (0)