Skip to content

Commit

Permalink
[DDW-881] Memoize part of the useMenuUpdater hook implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonmaslowski committed Feb 8, 2022
1 parent 370d9d1 commit 54ff345
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions source/renderer/app/containers/MenuUpdater/useMenuUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { useEffect } from 'react';
import { memoize } from 'lodash/fp';
import { useEffect, useMemo } from 'react';
import { matchPath } from 'react-router-dom';
import { WalletSettingsStateEnum } from '../../../../common/ipc/api';
import { ROUTES } from '../../routes-config';
import type { UseMenuUpdaterArgs } from './types';

const walletRoutes = Object.values(ROUTES.WALLETS);

const shouldWalletSettingsOptionBeVisible = memoize((pathname: string) =>
walletRoutes.some(
(path) =>
matchPath(pathname, {
path,
})?.isExact
)
);

const useMenuUpdater = ({
stores: { app, profile, router, staking, uiDialogs },
rebuildApplicationMenu,
}: UseMenuUpdaterArgs) => {
useEffect(() => {
let walletSettingsState = WalletSettingsStateEnum.hidden;
const walletSettingsOptionVisible = walletRoutes.some(
(path) =>
matchPath(router.location?.pathname, {
path,
})?.isExact
);

if (walletSettingsOptionVisible) {
if (shouldWalletSettingsOptionBeVisible(router.location?.pathname)) {
const itIsTheWalletSettingsPage = matchPath(router.location?.pathname, {
path: ROUTES.WALLETS.SETTINGS,
})?.isExact;
Expand Down

0 comments on commit 54ff345

Please sign in to comment.