Skip to content

Commit

Permalink
591/base/profile logic (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
yayay927 authored Jan 6, 2022
1 parent 6a08c1a commit c02246c
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
- Add tombstoned status ([\#600](https://github.com/forbole/big-dipper-2.0-cosmos/issues/600))
- Add manual versioning in ui ([\#605](https://github.com/forbole/big-dipper-2.0-cosmos/issues/605))
- Optimized tx list for chains with heavy traffic ([\#602](https://github.com/forbole/big-dipper-2.0-cosmos/issues/602))
- Setup case insensitive search in dtags ([\#592](https://github.com/forbole/big-dipper-2.0-cosmos/issues/592))
- Fix profiles logic ([\#591](https://github.com/forbole/big-dipper-2.0-cosmos/issues/591))
- Add AvatarNameListMsg for handling msgs with multiple users ([\#619](https://github.com/forbole/big-dipper-2.0-cosmos/issues/619))


# base-v1.8.4 - 2021-12-08
## Bug fixes
- Fix `feegrant` and `authz` messages ([\#588](https://github.com/forbole/big-dipper-2.0-cosmos/issues/588))
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/use_desmos_profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useDesmosProfile = (options: Options) => {
try {
setLoading(true);
if (input.startsWith('@')) {
data = await fetchDtag(input.substr(1));
data = await fetchDtag(input.substring(1));
}

if (input.startsWith('desmos')) {
Expand Down
114 changes: 114 additions & 0 deletions src/screens/profile_details/hooks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import {
renderHook,
act,
cleanup,
} from '@testing-library/react-hooks';
import { useProfileDetails } from './hooks';

const mockRouter = {
query: {
dtag: '@happieSa',
},
replace: jest.fn(() => '/'),
push: jest.fn(),
};

jest.mock('next/router', () => ({
useRouter: () => mockRouter,
}));

jest.mock('@hooks', () => ({
useDesmosProfile: (options) => {
return ({
fetchDesmosProfile: jest.fn((dtag) => {
let results;
if (dtag === '@happieSa') {
results = {
address: 'desmos18tug2x5uwkgnh7qgadezvdntpwgjc88c98zuck',
bio: 'hungry all the time',
dtag: 'HappieSa',
nickname: 'theHappySamoyed',
chainLinks: [],
applicationLinks: [],
creationTime: '2021-10-06T00:10:45.761731',
coverPic: 'https://ipfs.desmos.network/ipfs/Qmf48cpgi2zNiH24Vo1xtVsePUJx9665gtiRduVCvV5fFg',
profilePic: 'https://ipfs.desmos.network/ipfs/QmTvkdGrtBHHihjVajqqA2HAoHangeKR1oYbQWzasnPi7B',
};
}
if (dtag === '@forbole') {
results = {
address: 'desmos1pm6pmpsdw8kd5g6jneyq8rl3qw6tukcp7g57w3',
bio: 'Forbole [ˈfɔːbəl] is a well-established blockchain validator and developer since 2017.',
dtag: 'forbole',
nickname: 'Forbole',
chainLinks: [],
applicationLinks: [],
creationTime: '2021-10-06T00:10:45.761731',
coverPic: 'https://ipfs.desmos.network/ipfs/Qmf48cpgi2zNiH24Vo1xtVsePUJx9665gtiRduVCvV5fFg',
profilePic: 'https://ipfs.desmos.network/ipfs/QmTvkdGrtBHHihjVajqqA2HAoHangeKR1oYbQWzasnPi7B',
};
}

return options.onComplete({
profile: [
results,
],
});
}),
formatDesmosProfile: jest.fn((data) => {
let results;
if (data.profile[0].dtag === 'HappieSa') {
results = {
dtag: 'HappieSa',
nickname: 'theHappySamoyed',
imageUrl: 'https://ipfs.desmos.network/ipfs/Qmf48cpgi2zNiH24Vo1xtVsePUJx9665gtiRduVCvV5fFg',
coverUrl: 'https://ipfs.desmos.network/ipfs/QmTvkdGrtBHHihjVajqqA2HAoHangeKR1oYbQWzasnPi7B',
bio: 'hungry all the time',
connections: [{
network: 'native',
identifier: 'desmos1kmw9et4e99ascgdw0mmkt63mggjuu0xuqjx30w',
}],
};
}

if (data.profile[0].dtag === 'forbole') {
results = {
dtag: 'forbole',
nickname: 'Forbole',
imageUrl: 'https://ipfs.desmos.network/ipfs/Qmf48cpgi2zNiH24Vo1xtVsePUJx9665gtiRduVCvV5fFg',
coverUrl: 'https://ipfs.desmos.network/ipfs/QmTvkdGrtBHHihjVajqqA2HAoHangeKR1oYbQWzasnPi7B',
bio: 'Forbole [ˈfɔːbəl] is a well-established blockchain validator and developer since 2017.',
connections: [{
network: 'native',
identifier: 'desmos1pm6pmpsdw8kd5g6jneyq8rl3qw6tukcp7g57w3',
}],
};
}
return results;
}),
});
},
}));

describe('hook: useProfileDetails', () => {
it('correctly toggles profile open', async () => {
const {
result, rerender,
} = renderHook(() => useProfileDetails());

expect(result.current.state.desmosProfile.bio).toBe('hungry all the time');
expect(mockRouter.push).toHaveBeenCalledWith({ pathname: '/@HappieSa' }, '/@HappieSa', { shallow: true });
act(() => {
mockRouter.query.dtag = '@forbole';
rerender();
});
// does not call on forbole
expect(mockRouter.push).toHaveBeenCalledTimes(1);
expect(result.current.state.desmosProfile.dtag).toBe('forbole');
});
});

afterEach(() => {
cleanup();
jest.clearAllMocks();
});
25 changes: 22 additions & 3 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,14 +62,23 @@ export const useProfileDetails = () => {

useEffect(() => {
if (state.desmosProfile) {
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 });
const showProfile = shouldShowProfile();

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 });
}
} else {
handleSetState({
exists: false,
});
}
}
}, [state.desmosProfile]);

return {
state,
shouldShowProfile,
};
};

0 comments on commit c02246c

Please sign in to comment.