Skip to content

Commit

Permalink
make useEffect cleaner with functional programming
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed Dec 28, 2021
1 parent a98d796 commit 5204edd
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/screens/profile_details/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export const useProfileDetails = () => {
},
});

const shouldShowProfile = () => {
const dtagConnections = state.desmosProfile.connections;
const dtagConnectionsNetwork = dtagConnections.map((x) => { return x.identifier; });
const chainPrefix = chainConfig.prefix.account;
const containNetwork = dtagConnectionsNetwork.some((x) => x.startsWith(chainPrefix));
if (containNetwork) {
return true;
}
};

useEffect(() => {
const regex = /^@/;
const profileDtag = router.query.dtag as string;
Expand All @@ -52,12 +62,9 @@ export const useProfileDetails = () => {

useEffect(() => {
if (state.desmosProfile) {
const dtagConnections = state.desmosProfile.connections;
const dtagConnectionsNetwork = dtagConnections.map((x) => { return x.identifier; });
const chainPrefix = chainConfig.prefix.account;
const containNetwork = dtagConnectionsNetwork.some((x) => x.startsWith(chainPrefix));
const showProfile = shouldShowProfile();

if (containNetwork) {
if (showProfile) {
const dtagInput = router.query.dtag as string;
if ((`@${state.desmosProfile.dtag}` !== dtagInput) && (`@${state.desmosProfile.dtag.toUpperCase()}` === dtagInput.toUpperCase())) {
router.push({ pathname: `/@${state.desmosProfile.dtag}` }, `/@${state.desmosProfile.dtag}`, { shallow: true });
Expand Down

0 comments on commit 5204edd

Please sign in to comment.