Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unlock Profile(Verify) #1926

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/modules/rewards/hooks/useLockedStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { useGetRewardActivityStatus, useGetUserRewardsDetails } from 'queries';

// helpers
import { walletToCAIP10 } from 'helpers/w2w';
import { isUserNotFound } from '../utils/resolveError';

// types
import { AxiosError } from 'axios';
import { useRewardsContext } from 'contexts/RewardsContext';

const useLockedStatus = () => {
Expand All @@ -24,9 +24,6 @@ const useLockedStatus = () => {
userId: userDetails?.userId as string,
});

// error responses
const errorMessage = 'Failed to retrieve user';

useEffect(() => {
if (!hasMounted) {
if (isWalletConnected && userDetails?.userId) {
Expand All @@ -37,7 +34,7 @@ const useLockedStatus = () => {
}

if (status === 'error' && isWalletConnected) {
if (error instanceof AxiosError && error?.response?.data?.error === errorMessage) {
if (isUserNotFound(error)) {
setIsLocked(true);
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/modules/rewards/hooks/useRewardsAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { walletToCAIP10 } from 'helpers/w2w';
import { useAccount } from 'hooks';
import { generateVerificationProof } from '../utils/generateVerificationProof';
import { useRewardsTabs } from './useRewardsTabs';
import { isUserNotFound } from '../utils/resolveError';

// hooks
import { useGetUserRewardsDetails } from 'queries/hooks/rewards';

// types
import { AxiosError } from 'axios';
import { UserStoreType } from 'types';
import { useRewardsContext } from 'contexts/RewardsContext';
import { checkUnlockProfileErrors } from 'components/chat/unlockProfile/UnlockProfile.utils';
Expand All @@ -38,9 +38,6 @@ const useRewardsAuth = () => {
caip10WalletAddress: caip10WalletAddress,
});

// error responses
const errorMessage = 'Failed to retrieve user';

// rewards activity connect function
const connectWallet = () => {
setHandleVerify(false);
Expand Down Expand Up @@ -98,7 +95,7 @@ const useRewardsAuth = () => {

// dashboard connect wallet flow
if (status === 'error' && activeTab == 'dashboard' && !isVerifyClicked) {
if (error instanceof AxiosError && error?.response?.data?.error === errorMessage) {
if (isUserNotFound(error)) {
const errorExistsInUnlockProfile = checkUnlockProfileErrors(userPushSDKInstance);
if (errorExistsInUnlockProfile || !isWalletConnected) return;
unlockProfile();
Expand All @@ -112,7 +109,7 @@ const useRewardsAuth = () => {

// rewards activity first user
if (isVerifyClicked && status === 'error') {
if (error instanceof AxiosError && error?.response?.data?.error === errorMessage) {
if (isUserNotFound(error)) {
unlockProfile();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/modules/rewards/utils/resolveError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// types
import { AxiosError } from 'axios';

export const isUserNotFound = (error: Error) => {
if (error instanceof AxiosError && error?.response?.status === 404) {
return true;
}
return false;
};
Loading