-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix re renders of wallet view on every navigation action
- Loading branch information
Showing
6 changed files
with
119 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './useCheckMultiRpcModal'; |
38 changes: 38 additions & 0 deletions
38
app/components/hooks/useCheckMultiRpcModal/useCheckMultiRpcModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { isObject } from '@metamask/utils'; | ||
import Routes from '../../../constants/navigation/Routes'; | ||
import { setMultiRpcMigrationModalOpen } from '../../../actions/security'; | ||
import { selectShowMultiRpcModal } from '../../../selectors/preferencesController'; | ||
import { selectNetworkConfigurations } from '../../../selectors/networkController'; | ||
|
||
const useCheckMultiRpcModal = () => { | ||
const dispatch = useDispatch(); | ||
const navigation = useNavigation(); | ||
const networkConfigurations = useSelector(selectNetworkConfigurations); | ||
|
||
const showMultiRpcModal = useSelector(selectShowMultiRpcModal); | ||
|
||
const isNetworkDuplicated = Object.values(networkConfigurations).some( | ||
(networkConfiguration) => | ||
isObject(networkConfiguration) && | ||
Array.isArray(networkConfiguration.rpcEndpoints) && | ||
networkConfiguration.rpcEndpoints.length > 1, | ||
); | ||
|
||
const checkMultiRpcModal = useCallback(() => { | ||
if (showMultiRpcModal && isNetworkDuplicated) { | ||
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, { | ||
screen: Routes.MODAL.MULTI_RPC_MIGRATION_MODAL, | ||
}); | ||
dispatch(setMultiRpcMigrationModalOpen(true)); | ||
} | ||
}, [dispatch, showMultiRpcModal, navigation, isNetworkDuplicated]); | ||
|
||
useEffect(() => { | ||
checkMultiRpcModal(); | ||
}, [checkMultiRpcModal]); | ||
}; | ||
|
||
export default useCheckMultiRpcModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './useCheckNftAutoDetectionModal'; |
42 changes: 42 additions & 0 deletions
42
app/components/hooks/useCheckNftAutoDetectionModal/useCheckNftAutoDetectionModal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
|
||
import { selectUseNftDetection } from '../../../selectors/preferencesController'; | ||
import { isMainNet } from '../../../util/networks'; | ||
import Routes from '../../../constants/navigation/Routes'; | ||
import { setNftAutoDetectionModalOpen } from '../../../actions/security'; | ||
import { RootState } from '../../../reducers'; | ||
import { selectProviderConfig } from '../../../selectors/networkController'; | ||
|
||
const useCheckNftAutoDetectionModal = () => { | ||
const dispatch = useDispatch(); | ||
const navigation = useNavigation(); | ||
const useNftDetection = useSelector(selectUseNftDetection); | ||
const providerConfig = useSelector(selectProviderConfig); | ||
const isNFTAutoDetectionModalViewed = useSelector( | ||
(state: RootState) => state.security.isNFTAutoDetectionModalViewed, | ||
); | ||
|
||
const checkNftAutoDetectionModal = useCallback(() => { | ||
const isOnMainnet = isMainNet(providerConfig.chainId); | ||
if (!useNftDetection && isOnMainnet && !isNFTAutoDetectionModalViewed) { | ||
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, { | ||
screen: Routes.MODAL.NFT_AUTO_DETECTION_MODAL, | ||
}); | ||
dispatch(setNftAutoDetectionModalOpen(true)); | ||
} | ||
}, [ | ||
dispatch, | ||
isNFTAutoDetectionModalViewed, | ||
navigation, | ||
providerConfig.chainId, | ||
useNftDetection, | ||
]); | ||
|
||
useEffect(() => { | ||
checkNftAutoDetectionModal(); | ||
}, [checkNftAutoDetectionModal]); | ||
}; | ||
|
||
export default useCheckNftAutoDetectionModal; |