diff --git a/packages/common/src/hooks/chats/useSetInboxPermissions.ts b/packages/common/src/hooks/chats/useSetInboxPermissions.ts index 2d14f3a9410..4ef7642aa1a 100644 --- a/packages/common/src/hooks/chats/useSetInboxPermissions.ts +++ b/packages/common/src/hooks/chats/useSetInboxPermissions.ts @@ -1,8 +1,8 @@ import { useCallback } from 'react' -import type { AudiusSdk } from '@audius/sdk' import { useDispatch, useSelector } from 'react-redux' +import { useAudiusQueryContext } from '~/audius-query' import { useAppContext } from '~/context/appContext' import { Name } from '~/models/Analytics' import { accountSelectors } from '~/store/account' @@ -17,13 +17,8 @@ const { fetchPermissions } = chatActions const { getChatPermissionsStatus, getUserChatPermissions } = chatSelectors const { getUserId } = accountSelectors -type useSetInboxPermissionsProps = { - audiusSdk: () => Promise -} - -export const useSetInboxPermissions = ({ - audiusSdk -}: useSetInboxPermissionsProps) => { +export const useSetInboxPermissions = () => { + const { audiusSdk, reportToSentry } = useAudiusQueryContext() const dispatch = useDispatch() const permissions = useSelector(getUserChatPermissions) const { @@ -53,7 +48,10 @@ export const useSetInboxPermissions = ({ }) ) } catch (e) { - console.error('Error saving chat permissions:', e) + reportToSentry({ + name: 'Chats', + error: e as Error + }) track( make({ eventName: Name.CHANGE_INBOX_SETTINGS_FAILURE, @@ -62,7 +60,7 @@ export const useSetInboxPermissions = ({ ) } }, - [audiusSdk, track, make, doFetchPermissions] + [audiusSdk, doFetchPermissions, track, make, reportToSentry] ) return { diff --git a/packages/common/src/store/pages/chat/sagas.ts b/packages/common/src/store/pages/chat/sagas.ts index 6cd719d347b..ae89484d185 100644 --- a/packages/common/src/store/pages/chat/sagas.ts +++ b/packages/common/src/store/pages/chat/sagas.ts @@ -16,7 +16,6 @@ import { import { ulid } from 'ulid' import { Name } from '~/models/Analytics' -import { ErrorLevel } from '~/models/ErrorReporting' import { ID } from '~/models/Identifiers' import { Status } from '~/models/Status' import { getAccountUser, getUserId } from '~/store/account/selectors' @@ -121,11 +120,10 @@ function* doFetchUnreadMessagesCount() { fetchUnreadMessagesCountSucceeded({ unreadMessagesCount: response.data }) ) } catch (e) { - console.error('fetchUnreadMessagesCountFailed', e) yield* put(fetchUnreadMessagesCountFailed()) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -169,11 +167,10 @@ function* doFetchLatestChats() { }) ) } catch (e) { - console.error('fetchLatestChatsFailed', e) yield* put(fetchMoreChatsFailed()) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -197,11 +194,10 @@ function* doFetchMoreChats() { yield* fetchUsersForChats(response.data) yield* put(fetchMoreChatsSucceeded(response)) } catch (e) { - console.error('fetchMoreChatsFailed', e) yield* put(fetchMoreChatsFailed()) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -262,11 +258,10 @@ function* doFetchLatestMessages( }) ) } catch (e) { - console.error('fetchLatestChatMessagesFailed', e) yield* put(fetchMoreMessagesFailed({ chatId })) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId @@ -324,11 +319,10 @@ function* doFetchMoreMessages(action: ReturnType) { }) ) } catch (e) { - console.error('fetchMoreChatMessagesFailed', e) yield* put(fetchMoreMessagesFailed({ chatId })) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId @@ -372,11 +366,10 @@ function* doSetMessageReaction(action: ReturnType) { }) ) } catch (e) { - console.error('setMessageReactionFailed', e) yield* put(setMessageReactionFailed(action.payload)) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId, @@ -434,7 +427,6 @@ function* doCreateChat(action: ReturnType) { yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS })) } } catch (e) { - console.error('createChatFailed', e) yield* put( toast({ type: 'error', @@ -443,7 +435,7 @@ function* doCreateChat(action: ReturnType) { ) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { userIds @@ -502,7 +494,6 @@ function* doCreateChatBlast(action: ReturnType) { yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS })) } } catch (e) { - console.error('createChatBlastFailed', e) yield* put( toast({ type: 'error', @@ -511,7 +502,7 @@ function* doCreateChatBlast(action: ReturnType) { ) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { audience, @@ -547,11 +538,10 @@ function* doMarkChatAsRead(action: ReturnType) { yield* put(markChatAsReadFailed({ chatId })) } } catch (e) { - console.error('markChatAsReadFailed', e) yield* put(markChatAsReadFailed({ chatId })) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId @@ -608,7 +598,6 @@ function* doSendMessage(action: ReturnType) { } yield* call(track, make({ eventName: Name.SEND_MESSAGE_SUCCESS })) } catch (e) { - console.error('sendMessageFailed', e) yield* put(sendMessageFailed({ chatId, messageId: messageIdToUse })) // Fetch the chat to see if permissions need rechecking @@ -629,7 +618,7 @@ function* doSendMessage(action: ReturnType) { } const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId, @@ -671,10 +660,9 @@ function* doFetchBlockees() { }) ) } catch (e) { - console.error('fetchBlockeesFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -693,10 +681,9 @@ function* doFetchBlockers() { }) ) } catch (e) { - console.error('fetchBlockersFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -717,10 +704,9 @@ function* doBlockUser(action: ReturnType) { make({ eventName: Name.BLOCK_USER_SUCCESS, blockedUserId: userId }) ) } catch (e) { - console.error('blockUserFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) yield* call( @@ -739,10 +725,9 @@ function* doUnblockUser(action: ReturnType) { }) yield* put(fetchBlockees()) } catch (e) { - console.error('unblockUserFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -771,10 +756,9 @@ function* doFetchPermissions(action: ReturnType) { }) ) } catch (e) { - console.error('fetchPermissionsFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error }) } @@ -800,10 +784,9 @@ function* doFetchLinkUnfurlMetadata( fetchLinkUnfurlSucceeded({ chatId, messageId, unfurlMetadata: data[0] }) ) } catch (e) { - console.error('fetchUnfurlFailed', e) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId, @@ -831,10 +814,9 @@ function* doDeleteChat(action: ReturnType) { yield* put(deleteChatSucceeded({ chatId })) yield* call(track, make({ eventName: Name.DELETE_CHAT_SUCCESS })) } catch (e) { - console.error('deleteChat failed', e, { chatId }) const reportToSentry = yield* getContext('reportToSentry') reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error: e as Error, additionalInfo: { chatId @@ -849,7 +831,7 @@ function* doLogError({ payload: { error } }: ReturnType) { const reportToSentry = yield* getContext('reportToSentry') const { code, url } = error reportToSentry({ - level: ErrorLevel.Error, + name: 'Chats', error, additionalInfo: { code, diff --git a/packages/mobile/src/screens/settings-screen/InboxSettingsScreenNew.tsx b/packages/mobile/src/screens/settings-screen/InboxSettingsScreenNew.tsx index f4e3a3cd616..21f7c952fe4 100644 --- a/packages/mobile/src/screens/settings-screen/InboxSettingsScreenNew.tsx +++ b/packages/mobile/src/screens/settings-screen/InboxSettingsScreenNew.tsx @@ -8,7 +8,6 @@ import { Formik } from 'formik' import { Button, Flex, IconMessage } from '@audius/harmony-native' import { HeaderShadow, ScreenContent } from 'app/components/core' -import { audiusSdk } from 'app/services/sdk/audius-sdk' import { FormScreen } from '../form-screen' @@ -21,9 +20,7 @@ const messages = { export const InboxSettingsScreenNew = () => { const { permissions, doFetchPermissions, savePermissions } = - useSetInboxPermissions({ - audiusSdk - }) + useSetInboxPermissions() const initialValues = useMemo(() => { return transformPermitListToMap( diff --git a/packages/web/src/components/inbox-settings-modal/InboxSettingsModalNew.tsx b/packages/web/src/components/inbox-settings-modal/InboxSettingsModalNew.tsx index c8943f98dd4..8186576537b 100644 --- a/packages/web/src/components/inbox-settings-modal/InboxSettingsModalNew.tsx +++ b/packages/web/src/components/inbox-settings-modal/InboxSettingsModalNew.tsx @@ -22,7 +22,6 @@ import { ChatPermission } from '@audius/sdk' import { Formik, useField, useFormikContext } from 'formik' import { useModalState } from 'common/hooks/useModalState' -import { audiusSdk } from 'services/audius-sdk' const messages = { title: 'Inbox Settings', @@ -84,9 +83,7 @@ export const InboxSettingsModalNew = () => { doFetchPermissions, permissionsStatus, savePermissions - } = useSetInboxPermissions({ - audiusSdk - }) + } = useSetInboxPermissions() const handleSave = useCallback( (values: InboxSettingsFormValues) => {