diff --git a/packages/frontend/src/components/navigation/Navigation.js b/packages/frontend/src/components/navigation/Navigation.js index 2e0eb13df2..e0d9b7c2a1 100644 --- a/packages/frontend/src/components/navigation/Navigation.js +++ b/packages/frontend/src/components/navigation/Navigation.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useCallback } from 'react'; import styled from 'styled-components'; import DesktopContainer from './DesktopContainer'; @@ -46,22 +46,19 @@ export default ({ if (menuOpen) { document.addEventListener('keydown', handleKeyDown); document.addEventListener('click', handleClick); + } else { + document.removeEventListener('keydown', handleKeyDown); + document.removeEventListener('click', handleClick); } }, [menuOpen]); - const handleCloseMenu = () => { - setMenuOpen(false); - document.removeEventListener('keydown', handleKeyDown); - document.removeEventListener('click', handleClick); - }; - - const handleKeyDown = (e) => { + const handleKeyDown = useCallback((e) => { if (e.keyCode === 27) { - handleCloseMenu(); + setMenuOpen(false); } - }; + }, []); - const handleClick = (e) => { + const handleClick = useCallback((e) => { const desktopMenu = document.getElementById('desktop-menu'); const mobileMenu = document.getElementById('mobile-menu'); @@ -70,21 +67,21 @@ export default ({ } if (e.target.tagName === 'BUTTON' || e.target.tagName === 'A' || (!desktopMenu?.contains(e.target) && !mobileMenu?.contains(e.target))) { - handleCloseMenu(); + setMenuOpen(false); } - }; + }, []); - const toggleMenu = () => { + const toggleMenu = useCallback(() => { if (menuOpen) { - handleCloseMenu(); + setMenuOpen(false); } else { setMenuOpen(true); } - }; + }, [menuOpen]); const handleSelectAccount = (accountId) => { selectAccount(accountId); - handleCloseMenu(); + setMenuOpen(false); }; return ( diff --git a/packages/frontend/src/components/navigation/NavigationWrapper.js b/packages/frontend/src/components/navigation/NavigationWrapper.js index 1cdb0cf14b..f3005f6a7a 100644 --- a/packages/frontend/src/components/navigation/NavigationWrapper.js +++ b/packages/frontend/src/components/navigation/NavigationWrapper.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { switchAccount, getAccountBalance } from '../../redux/actions/account'; @@ -17,13 +17,15 @@ export default () => { return ( { + selectAccount={useCallback((accountId) => { dispatch(switchAccount({ accountId })); - }} + }, [])} showNavLinks={account.localStorage?.accountFound} flowLimitationMainMenu={flowLimitationMainMenu} flowLimitationSubMenu={flowLimitationSubMenu} - refreshBalance={(accountId) => dispatch(getAccountBalance(accountId))} + refreshBalance={useCallback((accountId) => { + dispatch(getAccountBalance(accountId)); + }, [])} availableAccounts={availableAccounts} account={account} /> diff --git a/packages/frontend/src/routes/WalletWrapper.js b/packages/frontend/src/routes/WalletWrapper.js index 10390a4a25..028fbf746f 100644 --- a/packages/frontend/src/routes/WalletWrapper.js +++ b/packages/frontend/src/routes/WalletWrapper.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useCallback } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { Wallet } from '../components/wallet/Wallet'; @@ -21,8 +21,8 @@ export function WalletWrapper({ setTab }) { - const accountId = useSelector((state) => selectAccountId(state)); - const balance = useSelector((state) => selectBalance(state)); + const accountId = useSelector(selectAccountId); + const balance = useSelector(selectBalance); const dispatch = useDispatch(); const linkdropAmount = useSelector(selectLinkdropAmount); const createFromImplicitSuccess = useSelector(selectCreateFromImplicitSuccess); @@ -34,21 +34,14 @@ export function WalletWrapper({ useEffect(() => { if (accountId) { - let id = Mixpanel.get_distinct_id(); - Mixpanel.identify(id); + Mixpanel.identify(Mixpanel.get_distinct_id()); Mixpanel.people.set({ relogin_date: new Date().toString() }); + + dispatch(fetchNFTs({ accountId })); + dispatch(fetchTokens({ accountId })); } }, [accountId]); - useEffect(() => { - if (!accountId) { - return; - } - - dispatch(fetchNFTs({ accountId })); - dispatch(fetchTokens({ accountId })); - }, [accountId]); - return ( { + useCallback(() => { dispatch(setLinkdropAmount('0')); Mixpanel.track('Click dismiss NEAR drop success modal'); - } + },[]) } handleSetCreateFromImplicitSuccess={() => dispatch(setCreateFromImplicitSuccess(false))} handleSetCreateCustomName={() => dispatch(setCreateCustomName(false))}