File tree Expand file tree Collapse file tree 3 files changed +23
-13
lines changed
confirmations/components/confirm/info/hooks
notifications/notification-components/snap Expand file tree Collapse file tree 3 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 1+ import { useCallback , useMemo } from 'react' ;
12import { useNavigate } from 'react-router-dom-v5-compat' ;
23import { parseMetaMaskUrl } from '@metamask/snaps-utils' ;
34import { getSnapRoute } from '../../helpers/utils/util' ;
45
56const useSnapNavigation = ( ) => {
67 const navigate = useNavigate ( ) ;
7- const useSnapNavigate = ( url : string ) => {
8- let path ;
9- const linkData = parseMetaMaskUrl ( url ) ;
10- if ( linkData . snapId ) {
11- path = getSnapRoute ( linkData . snapId ) ;
12- } else {
13- path = linkData . path ;
14- }
15- navigate ( path ) ;
16- } ;
17- return {
18- useSnapNavigate,
19- } ;
8+ const useSnapNavigate = useCallback (
9+ ( url : string ) => {
10+ let path ;
11+ const linkData = parseMetaMaskUrl ( url ) ;
12+ if ( linkData . snapId ) {
13+ path = getSnapRoute ( linkData . snapId ) ;
14+ } else {
15+ path = linkData . path ;
16+ }
17+ navigate ( path ) ;
18+ } ,
19+ [ navigate ] ,
20+ ) ;
21+ return useMemo (
22+ ( ) => ( {
23+ useSnapNavigate,
24+ } ) ,
25+ [ useSnapNavigate ] ,
26+ ) ;
2027} ;
2128
2229export default useSnapNavigation ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export function useNestedTransactionLabels({
1515 const { data, to } = nestedTransaction ;
1616 // It's safe to call useFourByte here because the length of nestedTransactions
1717 // remains stable throughout the component's lifecycle.
18+ // eslint-disable-next-line react-hooks/rules-of-hooks
1819 const methodData = useFourByte ( { data, to } ) ;
1920 const functionName = methodData ?. name ;
2021
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ export const SnapFooterButton = (props: { notification: SnapNotification }) => {
4444 if ( isExternal ) {
4545 setIsOpen ( true ) ;
4646 } else {
47+ // This hook is safe to include in this event handler, because its only reactive component is `useNavigate`
48+ // eslint-disable-next-line react-hooks/rules-of-hooks
4749 useSnapNavigate ( href ) ;
4850 }
4951 } ,
You can’t perform that action at this time.
0 commit comments