Skip to content

Commit 8abd7b3

Browse files
[DDW-881] Enhance logic for updating menus (#2838)
Co-authored-by: Michael Chappell <[email protected]>
1 parent 4afc990 commit 8abd7b3

35 files changed

+574
-523
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
### Fixes
1313

14+
- Fixed behaviour of wallet settings option of the app menu ([PR 2838](https://github.com/input-output-hk/daedalus/pull/2838))
1415
- Fixed available disk space takes a long time to show ([PR 2849](https://github.com/input-output-hk/daedalus/pull/2849))
15-
16+
1617
### Chores
1718

1819
- Migrated codebase from javascript to typescript ([PR 2843](https://github.com/input-output-hk/daedalus/pull/2843))

source/common/config/electron-store.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const STORAGE_KEYS: Record<string, StorageKey> = {
1010
APP_AUTOMATIC_UPDATE_FAILED: 'APP-AUTOMATIC-UPDATE-FAILED',
1111
APP_UPDATE_COMPLETED: 'APP-UPDATE-COMPLETED',
1212
ASSET_DATA: 'ASSET-DATA',
13-
ASSET_SETTINGS_DIALOG_WAS_OPENED: 'ASSET-SETTINGS-DIALOG-WAS-OPENED',
1413
CURRENCY_ACTIVE: 'CURRENCY-ACTIVE',
1514
CURRENCY_SELECTED: 'CURRENCY-SELECTED',
1615
DATA_LAYER_MIGRATION_ACCEPTANCE: 'DATA-LAYER-MIGRATION-ACCEPTANCE',

source/common/ipc/api.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,15 @@ export type SubmitBugReportRequestMainResponse = void;
178178
/**
179179
* Channel to rebuild the electron application menu after the language setting changes
180180
*/
181+
export enum WalletSettingsStateEnum {
182+
hidden = 'hidden',
183+
disabled = 'disabled',
184+
enabled = 'enabled',
185+
}
181186
export const REBUILD_APP_MENU_CHANNEL = 'REBUILD_APP_MENU_CHANNEL';
182187
export type RebuildAppMenuRendererRequest = {
183188
isNavigationEnabled: boolean;
189+
walletSettingsState: WalletSettingsStateEnum;
184190
};
185191
export type RebuildAppMenuMainResponse = void;
186192

@@ -312,14 +318,6 @@ export const GENERATE_WALLET_MIGRATION_REPORT_CHANNEL =
312318
export type GenerateWalletMigrationReportRendererRequest = WalletMigrationReportData;
313319
export type GenerateWalletMigrationReportMainResponse = void;
314320

315-
/**
316-
* Channel for enabling application menu navigation
317-
*/
318-
export const ENABLE_APPLICATION_MENU_NAVIGATION_CHANNEL =
319-
'ENABLE_APPLICATION_MENU_NAVIGATION_CHANNEL';
320-
export type EnableApplicationMenuNavigationRendererRequest = void;
321-
export type EnableApplicationMenuNavigationMainResponse = void;
322-
323321
/**
324322
* Channel for generating wallet migration report
325323
*/

source/main/index.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { app, dialog, BrowserWindow, screen, shell } from 'electron';
44
import type { Event } from 'electron';
55
import { client } from 'electron-connect';
66
import EventEmitter from 'events';
7+
import { WalletSettingsStateEnum } from '../common/ipc/api';
78
import { requestElectronStore } from './ipc/electronStoreConversation';
89
import { logger } from './utils/logging';
910
import {
@@ -43,7 +44,6 @@ import type {
4344
import { logUsedVersion } from './utils/logUsedVersion';
4445
import { setStateSnapshotLogChannel } from './ipc/set-log-state-snapshot';
4546
import { generateWalletMigrationReportChannel } from './ipc/generateWalletMigrationReportChannel';
46-
import { enableApplicationMenuNavigationChannel } from './ipc/enableApplicationMenuNavigationChannel';
4747
import { pauseActiveDownloads } from './ipc/downloadManagerChannel';
4848
import {
4949
restoreSavedWindowBounds,
@@ -198,28 +198,20 @@ const onAppReady = async () => {
198198
// @ts-ignore ts-migrate(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
199199
buildAppMenus(mainWindow, cardanoNode, userLocale, {
200200
isNavigationEnabled: false,
201+
walletSettingsState: WalletSettingsStateEnum.hidden,
201202
});
202-
enableApplicationMenuNavigationChannel.onReceive(
203-
() =>
204-
new Promise((resolve) => {
205-
const locale = getLocale(network);
206-
// @ts-ignore ts-migrate(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
207-
buildAppMenus(mainWindow, cardanoNode, locale, {
208-
isNavigationEnabled: true,
209-
});
210-
resolve();
211-
})
212-
);
213203
rebuildApplicationMenu.onReceive(
214-
(data) =>
204+
({ walletSettingsState, isNavigationEnabled }) =>
215205
new Promise((resolve) => {
216206
const locale = getLocale(network);
217207
// @ts-ignore ts-migrate(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
218208
buildAppMenus(mainWindow, cardanoNode, locale, {
219-
isNavigationEnabled: data.isNavigationEnabled,
209+
isNavigationEnabled,
210+
walletSettingsState,
220211
});
221212
// @ts-ignore ts-migrate(2339) FIXME: Property 'updateTitle' does not exist on type 'Bro... Remove this comment to see the full error message
222213
mainWindow.updateTitle(locale);
214+
// @ts-ignore ts-migrate(2794) FIXME: Expected 1 arguments, but got 0. Did you forget to... Remove this comment to see the full error message
223215
resolve();
224216
})
225217
);

source/main/ipc/enableApplicationMenuNavigationChannel.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

source/main/menus/osx.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { showUiPartChannel } from '../ipc/control-ui-parts';
88
import { NOTIFICATIONS } from '../../common/ipc/constants';
99
import { generateSupportRequestLink } from '../../common/utils/reporting';
1010
import { buildKnownIssueFixesSubmenu } from './submenuBuilders';
11+
import { WalletSettingsStateEnum } from '../../common/ipc/api';
1112

1213
const id = 'menu';
1314
export const osxMenu = (
@@ -17,6 +18,7 @@ export const osxMenu = (
1718
translations: {},
1819
locale: string,
1920
isNavigationEnabled: boolean,
21+
walletSettingsState: WalletSettingsStateEnum,
2022
translation: (...args: Array<any>) => any = getTranslation(translations, id)
2123
) => [
2224
{
@@ -65,7 +67,10 @@ export const osxMenu = (
6567
actions.openWalletSettingsPage();
6668
},
6769

68-
enabled: isNavigationEnabled,
70+
enabled:
71+
isNavigationEnabled &&
72+
walletSettingsState === WalletSettingsStateEnum.enabled,
73+
visible: walletSettingsState !== WalletSettingsStateEnum.hidden,
6974
},
7075
{
7176
type: 'separator',

source/main/menus/win-linux.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { NOTIFICATIONS } from '../../common/ipc/constants';
88
import { showUiPartChannel } from '../ipc/control-ui-parts';
99
import { generateSupportRequestLink } from '../../common/utils/reporting';
1010
import { buildKnownIssueFixesSubmenu } from './submenuBuilders';
11+
import { WalletSettingsStateEnum } from '../../common/ipc/api';
1112

1213
const id = 'menu';
1314
export const winLinuxMenu = (
@@ -17,6 +18,7 @@ export const winLinuxMenu = (
1718
translations: {},
1819
locale: string,
1920
isNavigationEnabled: boolean,
21+
walletSettingsState: WalletSettingsStateEnum,
2022
translation: (...args: Array<any>) => any = getTranslation(translations, id)
2123
) => [
2224
{
@@ -127,7 +129,10 @@ export const winLinuxMenu = (
127129
actions.openWalletSettingsPage();
128130
},
129131

130-
enabled: isNavigationEnabled,
132+
enabled:
133+
isNavigationEnabled &&
134+
walletSettingsState === WalletSettingsStateEnum.enabled,
135+
visible: walletSettingsState !== WalletSettingsStateEnum.hidden,
131136
},
132137
{
133138
type: 'separator',

source/main/utils/buildAppMenus.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { app, BrowserWindow, dialog, globalShortcut, Menu } from 'electron';
2+
import { WalletSettingsStateEnum } from '../../common/ipc/api';
23
import { environment } from '../environment';
34
import { winLinuxMenu } from '../menus/win-linux';
45
import { osxMenu } from '../menus/osx';
@@ -9,13 +10,15 @@ import { DIALOGS, PAGES } from '../../common/ipc/constants';
910
import { showUiPartChannel } from '../ipc/control-ui-parts';
1011
import { getTranslation } from './getTranslation';
1112

13+
interface Data {
14+
isNavigationEnabled: boolean;
15+
walletSettingsState: WalletSettingsStateEnum;
16+
}
1217
export const buildAppMenus = async (
1318
mainWindow: BrowserWindow,
1419
cardanoNode: CardanoNode | null | undefined,
1520
locale: string,
16-
data: {
17-
isNavigationEnabled: boolean;
18-
}
21+
{ isNavigationEnabled, walletSettingsState }: Data
1922
) => {
2023
const {
2124
ABOUT,
@@ -24,7 +27,6 @@ export const buildAppMenus = async (
2427
TOGGLE_RTS_FLAGS_MODE,
2528
} = DIALOGS;
2629
const { SETTINGS, WALLET_SETTINGS } = PAGES;
27-
const { isNavigationEnabled } = data;
2830
const { isMacOS, isBlankScreenFixActive } = environment;
2931

3032
const translations = require(`../locales/${locale}`);
@@ -136,7 +138,8 @@ export const buildAppMenus = async (
136138
menuActions,
137139
translations,
138140
locale,
139-
isNavigationEnabled
141+
isNavigationEnabled,
142+
walletSettingsState
140143
)
141144
);
142145
Menu.setApplicationMenu(menu);
@@ -149,7 +152,8 @@ export const buildAppMenus = async (
149152
menuActions,
150153
translations,
151154
locale,
152-
isNavigationEnabled
155+
isNavigationEnabled,
156+
walletSettingsState
153157
)
154158
);
155159
mainWindow.setMenu(menu);

source/renderer/app/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { ActionsMap } from './actions/index';
2121
import NewsFeedContainer from './containers/news/NewsFeedContainer';
2222
import ToggleRTSFlagsDialogContainer from './containers/knownIssues/ToggleRTSFlagsDialogContainer';
2323
import RTSFlagsRecommendationOverlayContainer from './containers/knownIssues/RTSFlagsRecommendationOverlayContainer';
24+
import { MenuUpdater } from './containers/MenuUpdater';
2425

2526
@observer
2627
class App extends Component<{
@@ -61,6 +62,7 @@ class App extends Component<{
6162
{/* @ts-ignore ts-migrate(2769) FIXME: No overload matches this call. */}
6263
<ThemeManager variables={themeVars} />
6364
<Provider stores={stores} actions={actions}>
65+
<MenuUpdater />
6466
<ThemeProvider
6567
theme={daedalusTheme}
6668
skins={SimpleSkins}

source/renderer/app/actions/assets-actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import Action from './lib/Action';
22
import type { AssetToken } from '../api/assets/types'; // ======= ASSETS ACTIONS =======
33

44
export default class AssetsActions {
5-
onAssetSettingsOpen: Action<{
5+
setEditedAsset: Action<{
66
asset: AssetToken;
77
}> = new Action();
88
onAssetSettingsSubmit: Action<{
99
asset: AssetToken;
1010
decimals: number;
1111
}> = new Action();
12-
onAssetSettingsCancel: Action<any> = new Action();
12+
unsetEditedAsset: Action<any> = new Action();
1313
onOpenAssetSend: Action<{
1414
uniqueId: string;
1515
}> = new Action();

0 commit comments

Comments
 (0)