Skip to content

Commit cf74f94

Browse files
authored
[HUMAN App] fix: remove unnecessary query invalidation (#3484)
1 parent ed55849 commit cf74f94

File tree

17 files changed

+46
-137
lines changed

17 files changed

+46
-137
lines changed

packages/apps/human-app/frontend/src/api/hooks/use-access-token-refresh.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { useNavigate } from 'react-router-dom';
33
import { useAuth } from '@/modules/auth/hooks/use-auth';
44
import { browserAuthProvider } from '@/shared/contexts/browser-auth-provider';
@@ -8,7 +8,6 @@ import { routerPaths } from '@/router/router-paths';
88
import { authService } from '../authorized-http-api-client';
99

1010
export function useAccessTokenRefresh() {
11-
const queryClient = useQueryClient();
1211
const navigate = useNavigate();
1312
const { signOut: web2SignOut, user: web2User } = useAuth();
1413

@@ -41,12 +40,6 @@ export function useAccessTokenRefresh() {
4140
});
4241
}
4342
},
44-
onSuccess: async () => {
45-
await queryClient.invalidateQueries();
46-
},
47-
onError: async () => {
48-
await queryClient.invalidateQueries();
49-
},
5043
scope: {
5144
id: 'refresh-access-token',
5245
},
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { useNavigate } from 'react-router-dom';
33
import { routerPaths } from '@/router/router-paths';
44
import { env } from '@/shared/env';
@@ -13,18 +13,13 @@ function signInMutationFn(data: SignInDto) {
1313
}
1414

1515
export function useSignInMutation() {
16-
const queryClient = useQueryClient();
1716
const navigate = useNavigate();
1817

1918
return useMutation({
2019
mutationFn: signInMutationFn,
21-
onSuccess: async () => {
20+
onSuccess: () => {
2221
navigate(routerPaths.worker.profile);
2322
window.location.reload();
24-
await queryClient.invalidateQueries();
25-
},
26-
onError: async () => {
27-
await queryClient.invalidateQueries();
2823
},
2924
});
3025
}

packages/apps/human-app/frontend/src/modules/signup/operator/hooks/use-add-stake.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { useNavigate } from 'react-router-dom';
33
import { ethers } from 'ethers';
44
import { stakingStake } from '@/modules/smart-contracts/Staking/staking-stake';
@@ -62,7 +62,6 @@ export function useAddStake() {
6262
} = useConnectedWallet();
6363
const { data: HMTDecimals } = useHMTokenDecimals();
6464

65-
const queryClient = useQueryClient();
6665
const navigate = useNavigate();
6766

6867
return useMutation({
@@ -75,12 +74,8 @@ export function useAddStake() {
7574
chainId,
7675
decimals: HMTDecimals,
7776
}),
78-
onSuccess: async () => {
77+
onSuccess: () => {
7978
navigate(routerPaths.operator.addKeys);
80-
await queryClient.invalidateQueries();
81-
},
82-
onError: async () => {
83-
await queryClient.invalidateQueries();
8479
},
8580
mutationKey: ['addStake', address],
8681
});

packages/apps/human-app/frontend/src/modules/signup/operator/hooks/use-edit-existing-keys.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
useMutation,
3-
useMutationState,
4-
useQueryClient,
5-
} from '@tanstack/react-query';
1+
import { useMutation, useMutationState } from '@tanstack/react-query';
62
import last from 'lodash/last';
73
import { useNavigate } from 'react-router-dom';
84
import type { JsonRpcSigner } from 'ethers';
@@ -50,7 +46,7 @@ export function useEditExistingKeysMutation() {
5046
chainId,
5147
web3ProviderMutation: { data: web3Data },
5248
} = useConnectedWallet();
53-
const queryClient = useQueryClient();
49+
5450
const navigate = useNavigate();
5551

5652
return useMutation({
@@ -60,12 +56,8 @@ export function useEditExistingKeysMutation() {
6056
chainId,
6157
signer: web3Data?.signer,
6258
}),
63-
onSuccess: async () => {
59+
onSuccess: () => {
6460
navigate(routerPaths.operator.editExistingKeysSuccess);
65-
await queryClient.invalidateQueries();
66-
},
67-
onError: async () => {
68-
await queryClient.invalidateQueries();
6961
},
7062
mutationKey: ['editKeys', address],
7163
});
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { useNavigate } from 'react-router-dom';
33
import { routerPaths } from '@/router/router-paths';
44
import * as signupService from '@/modules/signup/services/signup.service';
55
import { type SignUpDto } from '../schema';
66

77
export function useSignUpMutation() {
8-
const queryClient = useQueryClient();
98
const navigate = useNavigate();
109

1110
return useMutation({
1211
mutationFn: async (data: Omit<SignUpDto, 'confirmPassword'>) => {
1312
return signupService.workerSignUp(data);
1413
},
15-
onSuccess: async (_, { email }) => {
14+
onSuccess: (_, { email }) => {
1615
navigate(routerPaths.worker.verifyEmail, {
1716
state: { routerState: { email } },
1817
});
19-
await queryClient.invalidateQueries();
20-
},
21-
onError: async () => {
22-
await queryClient.invalidateQueries();
2318
},
2419
});
2520
}

packages/apps/human-app/frontend/src/modules/worker/email-verification/hooks/resend-email-verification.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { t } from 'i18next';
33
import { useAuth } from '@/modules/auth/hooks/use-auth';
44
import { type ResendEmailVerificationDto } from '../schemas';
@@ -20,18 +20,11 @@ async function resendEmailVerificationMutationFn(
2020
const resendEmailVerificationKey = 'resendEmailVerification';
2121

2222
export function useResendEmailVerificationWorkerMutation() {
23-
const queryClient = useQueryClient();
2423
const { user } = useAuth();
2524

2625
return useMutation({
2726
mutationFn: (dto: ResendEmailVerificationDto) =>
2827
resendEmailVerificationMutationFn(dto, Boolean(user)),
29-
onSuccess: async () => {
30-
await queryClient.invalidateQueries();
31-
},
32-
onError: async () => {
33-
await queryClient.invalidateQueries();
34-
},
3528
mutationKey: [resendEmailVerificationKey],
3629
});
3730
}

packages/apps/human-app/frontend/src/modules/worker/hcaptcha-labeling/hooks/enable-hcaptcha-labeling.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { useNavigate } from 'react-router-dom';
33
import { routerPaths } from '@/router/router-paths';
44
import { useAccessTokenRefresh } from '@/api/hooks/use-access-token-refresh';
55
import * as hCaptchaLabelingService from '../services/hcaptcha-labeling.service';
66

77
export function useEnableHCaptchaLabelingMutation() {
8-
const queryClient = useQueryClient();
98
const navigate = useNavigate();
109
const { refreshAccessTokenAsync } = useAccessTokenRefresh();
1110
const mutation = useMutation({
@@ -16,12 +15,8 @@ export function useEnableHCaptchaLabelingMutation() {
1615

1716
return result;
1817
},
19-
onSuccess: async () => {
18+
onSuccess: () => {
2019
navigate(routerPaths.worker.HcaptchaLabeling);
21-
await queryClient.invalidateQueries();
22-
},
23-
onError: async () => {
24-
await queryClient.invalidateQueries();
2520
},
2621
});
2722

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import type { ResponseError } from '@/shared/types/global.type';
33
import * as hCaptchaLabelingService from '../services/hcaptcha-labeling.service';
44
import { type VerifyHCaptchaLabelingBody } from '../types';
55

6-
export function useSolveHCaptchaMutation(callbacks?: {
7-
onSuccess?: (() => void) | (() => Promise<void>);
8-
onError?:
9-
| ((error: ResponseError) => void)
10-
| ((error: ResponseError) => Promise<void>);
6+
export function useSolveHCaptchaMutation(callbacks: {
7+
onSuccess: () => void | Promise<void>;
8+
onError: (error: ResponseError) => void | Promise<void>;
119
}) {
12-
const queryClient = useQueryClient();
13-
1410
return useMutation({
1511
mutationFn: async (data: VerifyHCaptchaLabelingBody) =>
1612
hCaptchaLabelingService.verifyHCaptchaLabeling(data),
1713
onSuccess: async () => {
18-
if (callbacks?.onSuccess) {
19-
await callbacks.onSuccess();
20-
}
21-
await queryClient.invalidateQueries();
14+
await callbacks.onSuccess();
2215
},
2316
onError: async (error) => {
24-
if (callbacks?.onError) {
25-
await callbacks.onError(error);
26-
}
27-
await queryClient.invalidateQueries();
17+
await callbacks.onError(error);
2818
},
2919
});
3020
}

packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMutation, useQueryClient } from '@tanstack/react-query';
1+
import { useMutation } from '@tanstack/react-query';
22
import { t } from 'i18next';
33
import { useAuthenticatedUser } from '@/modules/auth/hooks/use-authenticated-user';
44
import { useAccessTokenRefresh } from '@/api/hooks/use-access-token-refresh';
@@ -9,12 +9,11 @@ import { PrepareSignatureType } from '@/shared/services/signature.service';
99
import * as profileService from '../profile/services/profile.service';
1010

1111
interface RegisterAddressCallbacks {
12-
onSuccess?: () => void | Promise<void>;
13-
onError?: (error: ResponseError) => void | Promise<void>;
12+
onSuccess: () => void | Promise<void>;
13+
onError: (error: ResponseError) => void | Promise<void>;
1414
}
1515

16-
function useRegisterAddressMutation(callbacks?: RegisterAddressCallbacks) {
17-
const queryClient = useQueryClient();
16+
function useRegisterAddressMutation(callbacks: RegisterAddressCallbacks) {
1817
const { user, updateUserData } = useAuthenticatedUser();
1918
const { refreshAccessTokenAsync } = useAccessTokenRefresh();
2019
const { address, chainId, signMessage } = useWalletConnect();
@@ -45,29 +44,19 @@ function useRegisterAddressMutation(callbacks?: RegisterAddressCallbacks) {
4544
});
4645
};
4746

48-
const onSuccess = async () => {
49-
if (callbacks?.onSuccess) {
50-
await callbacks.onSuccess();
51-
}
52-
await queryClient.invalidateQueries();
53-
};
54-
55-
const onError = async (error: ResponseError) => {
56-
if (callbacks?.onError) {
57-
await callbacks.onError(error);
58-
}
59-
await queryClient.invalidateQueries();
60-
};
61-
6247
return useMutation({
6348
mutationFn,
64-
onSuccess,
65-
onError,
49+
onSuccess: async () => {
50+
await callbacks.onSuccess();
51+
},
52+
onError: async (error: ResponseError) => {
53+
await callbacks.onError(error);
54+
},
6655
mutationKey: [user.wallet_address],
6756
});
6857
}
6958

70-
export function useRegisterAddress(callbacks?: RegisterAddressCallbacks) {
59+
export function useRegisterAddress(callbacks: RegisterAddressCallbacks) {
7160
const mutation = useRegisterAddressMutation(callbacks);
7261

7362
return {

packages/apps/human-app/frontend/src/modules/worker/jobs/available-jobs/hooks/use-assign-job.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { z } from 'zod';
2-
import {
3-
type MutationKey,
4-
useMutation,
5-
useQueryClient,
6-
} from '@tanstack/react-query';
2+
import { type MutationKey, useMutation } from '@tanstack/react-query';
73
import * as jobsService from '../../services/jobs.service';
84
import { type AssignJobBody } from '../../types';
95

@@ -16,16 +12,12 @@ export function useAssignJobMutation(
1612
},
1713
mutationKey?: MutationKey
1814
) {
19-
const queryClient = useQueryClient();
20-
2115
return useMutation({
2216
mutationFn: async (data: AssignJobBody) => jobsService.assignJob(data),
23-
onSuccess: async () => {
24-
await queryClient.invalidateQueries();
17+
onSuccess: () => {
2518
callbacks?.onSuccess();
2619
},
27-
onError: async (error) => {
28-
await queryClient.invalidateQueries();
20+
onError: (error) => {
2921
callbacks?.onError(error);
3022
},
3123
mutationKey,

0 commit comments

Comments
 (0)