Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-881] Enhance logic for updating menus #2838

Merged
merged 41 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f5026be
[DDW-881] Implement global Reaction responsible for rebuilding app me…
szymonmaslowski Jan 24, 2022
db14b17
[DDW-881] Move the side effect of watching for manu to rebuld to the …
szymonmaslowski Jan 25, 2022
5b7ef84
[DDW-881] Fix lint and codestyle issues
szymonmaslowski Jan 25, 2022
b713dce
Merge remote-tracking branch 'origin/develop' into feature/ddw-881
szymonmaslowski Jan 25, 2022
1029883
[DDW-881] Update changelog
szymonmaslowski Jan 25, 2022
cc73406
[DDW-881] Make wallet settings menu option be visible but disabled wh…
szymonmaslowski Jan 26, 2022
1b7acc0
[DDW-881] Integrate Asset Settings Dialog with the ui dialogs mobx store
szymonmaslowski Jan 27, 2022
62d86f3
[DDW-881] Minor code improvements
szymonmaslowski Jan 27, 2022
c1a3b14
[DDW-881] Plug in the WalletTokenPicker dialog to the uiDialogs mobx …
szymonmaslowski Jan 31, 2022
20e6cff
[DDW-881] Disable wallet settings menu option for About dialog, Diagn…
szymonmaslowski Jan 31, 2022
2b9d727
[DDW-881] Hide closing the Picket dialog functionality inside the con…
szymonmaslowski Feb 1, 2022
7a4aee6
[DDW-881] Fix flow issues
szymonmaslowski Feb 1, 2022
6041c3a
[DDW-881] Refactor MenuUpdater feature to use basic useEffect in plac…
szymonmaslowski Feb 1, 2022
a080f7a
[DDW-881] Make initial testcase of useMenuUpdater more generic
szymonmaslowski Feb 1, 2022
542fce8
[DDW-881] temporarily removed husky pre-commit
mchappell Feb 2, 2022
e0af21a
[DDW-881] installed ts packages, and packages required for migration
mchappell Feb 2, 2022
f2496af
[DDW-881] added ts extensions to prettierignore
mchappell Feb 2, 2022
8e599cc
[DDW-881] added tsconfig
mchappell Feb 2, 2022
8fa0b95
[DDW-881] converted all javascript files to typescript files
mchappell Feb 2, 2022
7401f53
[DDW-881] converted files returning react components to tsx extension
mchappell Feb 2, 2022
a4f42bd
[DDW-881] made global replacements in all folders
mchappell Feb 2, 2022
8b8e386
[DDW-881] converted flow style code in typescript files to typescript…
mchappell Feb 2, 2022
b4b30ac
[DDW-881] updated ts-ignore annotations in components
mchappell Feb 2, 2022
b870a37
[DDW-881] added ts-ignore annotations and re-formatted files accordin…
mchappell Feb 2, 2022
8b37fc2
[DDW-881] re-enabled husky pre-commit step
mchappell Feb 2, 2022
1e0819e
[DDW-881] lockfile fixed
mchappell Feb 2, 2022
ef5c709
[DDW-881] Use dialog related actions and store methods passed from ab…
szymonmaslowski Feb 2, 2022
b5dd487
Merge branch 'develop' into feature/ddw-881
mchappell Feb 2, 2022
ef05075
[DDW-881] removed previously deleted files conflicting with develop m…
mchappell Feb 2, 2022
840e978
[DDW-881] fixed lockfile
mchappell Feb 2, 2022
3cf0227
Merge branch 'feature/ddw-881' of https://github.com/input-output-hk/…
mchappell Feb 2, 2022
cf3bfd0
[DDW-881] updated wallet send page
mchappell Feb 2, 2022
d8f0ad5
[DDW-881] Apply again reverted changes of opening AssetSettingsDialog
szymonmaslowski Feb 3, 2022
4f4950a
[DDW-881] Fix WalletSendForm tests
szymonmaslowski Feb 3, 2022
77e90cd
[DDW-881] Fix one of useMenuUpdater tests
szymonmaslowski Feb 3, 2022
3a8ff36
[DDW-881] Fix ts issue of MenuUpdater
szymonmaslowski Feb 3, 2022
649c731
Merge remote-tracking branch 'origin/develop' into feature/ddw-881
szymonmaslowski Feb 3, 2022
370d9d1
[DDW-881] Reimplement WalletSettingsStateEnum to TS native enum
szymonmaslowski Feb 3, 2022
54ff345
[DDW-881] Memoize part of the useMenuUpdater hook implementation
szymonmaslowski Feb 8, 2022
a818d53
Revert "[DDW-881] Memoize part of the useMenuUpdater hook implementat…
szymonmaslowski Feb 8, 2022
c7bafab
Merge remote-tracking branch 'origin/develop' into feature/ddw-881
szymonmaslowski Feb 8, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- Implemented new token picker ([PR 2787](https://github.com/input-output-hk/daedalus/pull/2787))
- Improved wallet send form ([PR 2791](https://github.com/input-output-hk/daedalus/pull/2791))

### Fixes

- Fixed behaviour of wallet settings option of the app menu ([PR 2838](https://github.com/input-output-hk/daedalus/pull/2838))

### Chores

- Updated the list of team members ([PR 2805](https://github.com/input-output-hk/daedalus/pull/2805))
Expand Down
1 change: 0 additions & 1 deletion source/common/config/electron-store.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const STORAGE_KEYS: {
APP_AUTOMATIC_UPDATE_FAILED: 'APP-AUTOMATIC-UPDATE-FAILED',
APP_UPDATE_COMPLETED: 'APP-UPDATE-COMPLETED',
ASSET_DATA: 'ASSET-DATA',
ASSET_SETTINGS_DIALOG_WAS_OPENED: 'ASSET-SETTINGS-DIALOG-WAS-OPENED',
CURRENCY_ACTIVE: 'CURRENCY-ACTIVE',
CURRENCY_SELECTED: 'CURRENCY-SELECTED',
DATA_LAYER_MIGRATION_ACCEPTANCE: 'DATA-LAYER-MIGRATION-ACCEPTANCE',
Expand Down
18 changes: 10 additions & 8 deletions source/common/ipc/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,19 @@ export type SubmitBugReportRequestMainResponse = void;
/**
* Channel to rebuild the electron application menu after the language setting changes
*/
export type WalletSettingsStateValue = 'hidden' | 'disabled' | 'enabled';
export const WalletSettingsStateEnum: EnumMap<
WalletSettingsStateValue,
WalletSettingsStateValue
> = {
hidden: 'hidden',
disabled: 'disabled',
enabled: 'enabled',
};
export const REBUILD_APP_MENU_CHANNEL = 'REBUILD_APP_MENU_CHANNEL';
export type RebuildAppMenuRendererRequest = {
isNavigationEnabled: boolean,
walletSettingsState: WalletSettingsStateValue,
};
export type RebuildAppMenuMainResponse = void;

Expand Down Expand Up @@ -308,14 +318,6 @@ export const GENERATE_WALLET_MIGRATION_REPORT_CHANNEL =
export type GenerateWalletMigrationReportRendererRequest = WalletMigrationReportData;
export type GenerateWalletMigrationReportMainResponse = void;

/**
* Channel for enabling application menu navigation
*/
export const ENABLE_APPLICATION_MENU_NAVIGATION_CHANNEL =
'ENABLE_APPLICATION_MENU_NAVIGATION_CHANNEL';
export type EnableApplicationMenuNavigationRendererRequest = void;
export type EnableApplicationMenuNavigationMainResponse = void;

/**
* Channel for generating wallet migration report
*/
Expand Down
19 changes: 5 additions & 14 deletions source/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
import { app, dialog, BrowserWindow, screen, shell } from 'electron';
import { client } from 'electron-connect';
import EventEmitter from 'events';
import { WalletSettingsStateEnum } from '../common/ipc/api';
import { requestElectronStore } from './ipc/electronStoreConversation';
import { logger } from './utils/logging';
import {
Expand Down Expand Up @@ -45,7 +46,6 @@ import type {
import { logUsedVersion } from './utils/logUsedVersion';
import { setStateSnapshotLogChannel } from './ipc/set-log-state-snapshot';
import { generateWalletMigrationReportChannel } from './ipc/generateWalletMigrationReportChannel';
import { enableApplicationMenuNavigationChannel } from './ipc/enableApplicationMenuNavigationChannel';
import { pauseActiveDownloads } from './ipc/downloadManagerChannel';
import {
restoreSavedWindowBounds,
Expand Down Expand Up @@ -186,25 +186,16 @@ const onAppReady = async () => {

buildAppMenus(mainWindow, cardanoNode, userLocale, {
isNavigationEnabled: false,
walletSettingsState: WalletSettingsStateEnum.hidden,
});

enableApplicationMenuNavigationChannel.onReceive(
() =>
new Promise((resolve) => {
const locale = getLocale(network);
buildAppMenus(mainWindow, cardanoNode, locale, {
isNavigationEnabled: true,
});
resolve();
})
);

rebuildApplicationMenu.onReceive(
(data) =>
({ walletSettingsState, isNavigationEnabled }) =>
new Promise((resolve) => {
const locale = getLocale(network);
buildAppMenus(mainWindow, cardanoNode, locale, {
isNavigationEnabled: data.isNavigationEnabled,
isNavigationEnabled,
walletSettingsState,
});
mainWindow.updateTitle(locale);
resolve();
Expand Down
13 changes: 0 additions & 13 deletions source/main/ipc/enableApplicationMenuNavigationChannel.js

This file was deleted.

8 changes: 7 additions & 1 deletion source/main/menus/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { environment } from '../environment';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { generateSupportRequestLink } from '../../common/utils/reporting';
import { WalletSettingsStateEnum } from '../../common/ipc/api';
import type { WalletSettingsStateValue } from '../../common/ipc/api';
import { getRtsFlags } from '../utils/rtsFlags';

const id = 'menu';
Expand All @@ -22,6 +24,7 @@ export const osxMenu = (
translations: {},
locale: string,
isNavigationEnabled: boolean,
walletSettingsState: WalletSettingsStateValue,
translation: Function = getTranslation(translations, id)
) => [
{
Expand Down Expand Up @@ -58,7 +61,10 @@ export const osxMenu = (
click() {
actions.openWalletSettingsPage();
},
enabled: isNavigationEnabled,
enabled:
isNavigationEnabled &&
walletSettingsState === WalletSettingsStateEnum.enabled,
visible: walletSettingsState !== WalletSettingsStateEnum.hidden,
},
{ type: 'separator' },
{
Expand Down
8 changes: 7 additions & 1 deletion source/main/menus/win-linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { environment } from '../environment';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { generateSupportRequestLink } from '../../common/utils/reporting';
import { WalletSettingsStateEnum } from '../../common/ipc/api';
import type { WalletSettingsStateValue } from '../../common/ipc/api';
import { getRtsFlags } from '../utils/rtsFlags';

const id = 'menu';
Expand All @@ -22,6 +24,7 @@ export const winLinuxMenu = (
translations: {},
locale: string,
isNavigationEnabled: boolean,
walletSettingsState: WalletSettingsStateValue,
translation: Function = getTranslation(translations, id)
) => [
{
Expand Down Expand Up @@ -118,7 +121,10 @@ export const winLinuxMenu = (
click() {
actions.openWalletSettingsPage();
},
enabled: isNavigationEnabled,
enabled:
isNavigationEnabled &&
walletSettingsState === WalletSettingsStateEnum.enabled,
visible: walletSettingsState !== WalletSettingsStateEnum.hidden,
},
{
type: 'separator',
Expand Down
17 changes: 11 additions & 6 deletions source/main/utils/buildAppMenus.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import { app, BrowserWindow, dialog, globalShortcut, Menu } from 'electron';
import type { WalletSettingsStateValue } from '../../common/ipc/api';
import { environment } from '../environment';
import { winLinuxMenu } from '../menus/win-linux';
import { osxMenu } from '../menus/osx';
Expand All @@ -12,17 +13,19 @@ import { getTranslation } from './getTranslation';
import { setRtsFlagsAndRestart } from './rtsFlags';
import { RTS_FLAGS } from '../config';

type Data = {
isNavigationEnabled: boolean,
walletSettingsState: WalletSettingsStateValue,
};

export const buildAppMenus = async (
mainWindow: BrowserWindow,
cardanoNode: ?CardanoNode,
locale: string,
data: {
isNavigationEnabled: boolean,
}
{ isNavigationEnabled, walletSettingsState }: Data
) => {
const { ABOUT, DAEDALUS_DIAGNOSTICS, ITN_REWARDS_REDEMPTION } = DIALOGS;
const { SETTINGS, WALLET_SETTINGS } = PAGES;
const { isNavigationEnabled } = data;

const { isMacOS, isBlankScreenFixActive } = environment;
const translations = require(`../locales/${locale}`);
Expand Down Expand Up @@ -146,7 +149,8 @@ export const buildAppMenus = async (
menuActions,
translations,
locale,
isNavigationEnabled
isNavigationEnabled,
walletSettingsState
)
);
Menu.setApplicationMenu(menu);
Expand All @@ -158,7 +162,8 @@ export const buildAppMenus = async (
menuActions,
translations,
locale,
isNavigationEnabled
isNavigationEnabled,
walletSettingsState
)
);
mainWindow.setMenu(menu);
Expand Down
2 changes: 2 additions & 0 deletions source/renderer/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { DIALOGS } from '../../common/ipc/constants';
import type { StoresMap } from './stores/index';
import type { ActionsMap } from './actions/index';
import NewsFeedContainer from './containers/news/NewsFeedContainer';
import { MenuUpdater } from './containers/MenuUpdater';

@observer
export default class App extends Component<{
Expand Down Expand Up @@ -56,6 +57,7 @@ export default class App extends Component<{
<Fragment>
<ThemeManager variables={themeVars} />
<Provider stores={stores} actions={actions}>
<MenuUpdater />
<ThemeProvider
theme={daedalusTheme}
skins={SimpleSkins}
Expand Down
4 changes: 2 additions & 2 deletions source/renderer/app/actions/assets-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import type { AssetToken } from '../api/assets/types';
// ======= ASSETS ACTIONS =======

export default class AssetsActions {
onAssetSettingsOpen: Action<{ asset: AssetToken }> = new Action();
setEditedAsset: Action<{ asset: AssetToken }> = new Action();
onAssetSettingsSubmit: Action<{
asset: AssetToken,
decimals: number,
}> = new Action();
onAssetSettingsCancel: Action<any> = new Action();
unsetEditedAsset: Action<any> = new Action();
onOpenAssetSend: Action<{ uniqueId: string }> = new Action();
onCopyAssetParam: Action<{ param: string, fullValue: string }> = new Action();
onToggleFavorite: Action<{
Expand Down
9 changes: 0 additions & 9 deletions source/renderer/app/api/utils/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,6 @@ export default class LocalStorageApi {
`${policyId}${assetName}`
);

getAssetSettingsDialogWasOpened = (): Promise<boolean> =>
LocalStorageApi.get(keys.ASSET_SETTINGS_DIALOG_WAS_OPENED, false);

setAssetSettingsDialogWasOpened = (): Promise<void> =>
LocalStorageApi.set(keys.ASSET_SETTINGS_DIALOG_WAS_OPENED, true);

unsetAssetSettingsDialogWasOpened = (): Promise<void> =>
LocalStorageApi.unset(keys.ASSET_SETTINGS_DIALOG_WAS_OPENED);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed those three methods since they look like an overhead. We should not use persistent storage to store the information about whether the dialog is open since it is just a runtime information. Except the usage in the AssetsStore which was just checking whether the dialog was open I didn't found any other usages so they were safe to remove.

getSmashServer = (): Promise<string> =>
LocalStorageApi.get(keys.SMASH_SERVER);

Expand Down
7 changes: 1 addition & 6 deletions source/renderer/app/components/assets/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,12 @@ export default class Asset extends Component<Props, State> {
}

renderPillPopOverContainer = () => {
const {
asset,
onCopyAssetParam,
assetSettingsDialogWasOpened,
} = this.props;
const { asset, onCopyAssetParam } = this.props;
const pillContent = this.renderPillContent();
const popOverContent = (
<AssetContent
asset={asset}
onCopyAssetParam={onCopyAssetParam}
assetSettingsDialogWasOpened={assetSettingsDialogWasOpened}
className={styles.popOverContent}
highlightFingerprint
/>
Expand Down
37 changes: 16 additions & 21 deletions source/renderer/app/components/wallet/WalletSendForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import React, { Component, Fragment } from 'react';
import React, { Component, Fragment, createRef } from 'react';
import type { Node } from 'react';
import type { Field } from 'mobx-react-form';
import { observer } from 'mobx-react';
Expand Down Expand Up @@ -39,7 +39,8 @@ import type { HwDeviceStatus } from '../../domains/Wallet';
import type { AssetToken, ApiTokens } from '../../api/assets/types';
import type { ReactIntlMessage } from '../../types/i18nTypes';
import { DiscreetWalletAmount } from '../../features/discreet-mode';
import WalletTokenPicker from './tokens/wallet-token-picker/WalletTokenPicker';
import WalletTokenPickerDialogContainer from '../../containers/tokens/WalletTokenPickerDialogContainer';
import type { Api } from '../../containers/tokens/WalletTokenPickerDialogContainer';

messages.fieldIsRequired = globalMessages.fieldIsRequired;

Expand Down Expand Up @@ -99,7 +100,6 @@ type State = {
isResetButtonDisabled: boolean,
isReceiverAddressValid: boolean,
isTransactionFeeCalculated: boolean,
isTokenPickerOpen: boolean,
isCalculatingTransactionFee: boolean,
adaInputState: AdaInputState,
};
Expand All @@ -121,7 +121,6 @@ export default class WalletSendForm extends Component<Props, State> {
isResetButtonDisabled: true,
isReceiverAddressValid: false,
isTransactionFeeCalculated: false,
isTokenPickerOpen: false,
isCalculatingTransactionFee: false,
adaInputState: AdaInputStateType.None,
};
Expand Down Expand Up @@ -186,6 +185,8 @@ export default class WalletSendForm extends Component<Props, State> {
return this.availableAssets.length > 0;
}

walletTokenPickerRef = createRef<Api>();

getAssetByUniqueId = (uniqueId: string): ?AssetToken => {
const { assets: allAssets } = this.props;
return allAssets.find((asset) => asset.uniqueId === uniqueId);
Expand Down Expand Up @@ -1016,7 +1017,7 @@ export default class WalletSendForm extends Component<Props, State> {
label={intl.formatMessage(messages.addAssetButtonLabel)}
disabled={!this.hasAvailableAssets}
onClick={() => {
this.setState({ isTokenPickerOpen: true });
this.walletTokenPickerRef?.current?.open?.();
szymonmaslowski marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
</div>
Expand Down Expand Up @@ -1046,7 +1047,6 @@ export default class WalletSendForm extends Component<Props, State> {
transactionFeeError,
isResetButtonDisabled,
isTransactionFeeCalculated,
isTokenPickerOpen,
selectedAssetUniqueIds,
} = this.state;
const {
Expand Down Expand Up @@ -1170,21 +1170,16 @@ export default class WalletSendForm extends Component<Props, State> {
/>
) : null}

{isTokenPickerOpen && (
<WalletTokenPicker
assets={assets}
previouslyCheckedIds={selectedAssetUniqueIds}
tokenFavorites={tokenFavorites}
walletName={walletName}
onCancel={() => {
this.setState({ isTokenPickerOpen: false });
}}
onAdd={(checked) => {
this.setState({ isTokenPickerOpen: false });
checked.forEach(this.addAssetRow);
}}
/>
)}
<WalletTokenPickerDialogContainer
ref={this.walletTokenPickerRef}
assets={assets}
previouslyCheckedIds={selectedAssetUniqueIds}
tokenFavorites={tokenFavorites}
walletName={walletName}
onAdd={(checked) => {
checked.forEach(this.addAssetRow);
}}
/>
</div>
);
}
Expand Down
Loading