MCPcopy Create free account
hub / github.com/dailydotdev/apps / useTransactionError

Function useTransactionError

packages/shared/src/hooks/useTransactionError.ts:12–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10import { useToastNotification } from './useToastNotification';
11
12export const useTransactionError = () => {
13 const { displayToast } = useToastNotification();
14 const { user, updateUser } = useAuthContext();
15
16 return async (data: ApiErrorResult) => {
17 if (
18 data.response.errors?.[0]?.extensions?.code ===
19 ApiError.BalanceTransactionError
20 ) {
21 const errorExtensions = data.response
22 .errors[0] as ApiResponseError<ApiUserTransactionErrorExtension>;
23
24 if (
25 errorExtensions.extensions.status ===
26 UserTransactionStatus.InsufficientFunds &&
27 errorExtensions.extensions.balance &&
28 user
29 ) {
30 await updateUser({
31 ...user,
32 balance: errorExtensions.extensions.balance,
33 });
34 }
35 }
36
37 displayToast(data?.response?.errors?.[0]?.message || labels.error.generic);
38 };
39};

Callers 3

CommentScreenFunction · 0.90
useCampaignMutationFunction · 0.90
useStreakFreezeFunction · 0.90

Calls 3

useToastNotificationFunction · 0.90
useAuthContextFunction · 0.90
displayToastFunction · 0.85

Tested by

no test coverage detected