From 4bd41c843bd68a1b234d8adf0231855070ae2689 Mon Sep 17 00:00:00 2001 From: Adam Kahtava Date: Mon, 20 Mar 2023 13:17:36 -0400 Subject: [PATCH] Resolved a saga error which was calling out to /mine when a user was not authenticated --- src/platform-apps/channels/container.test.tsx | 14 +++++++- src/platform-apps/channels/container.tsx | 32 +++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/platform-apps/channels/container.test.tsx b/src/platform-apps/channels/container.test.tsx index b1c91cef0..862d1ec38 100644 --- a/src/platform-apps/channels/container.test.tsx +++ b/src/platform-apps/channels/container.test.tsx @@ -31,6 +31,9 @@ describe('ChannelsContainer', () => { user: { data: null, }, + context: { + isAuthenticated: true, + }, ...props, }; @@ -55,7 +58,7 @@ describe('ChannelsContainer', () => { expect(fetchChannels).toHaveBeenCalledWith(domainId); }); - it('set receiveUnreadCount channels on mount', () => { + it('set receiveUnreadCount channels on mount when authenticated', () => { const domainId = '0x000000000000000000000000000000000000000A'; const fetchChannels = jest.fn(); const receiveUnreadCount = jest.fn(); @@ -65,6 +68,15 @@ describe('ChannelsContainer', () => { expect(receiveUnreadCount).toHaveBeenCalledWith(domainId); }); + it('do not set receiveUnreadCount channels on mount when anonymous', () => { + const fetchChannels = jest.fn(); + const receiveUnreadCount = jest.fn(); + + subject({ fetchChannels, receiveUnreadCount, context: { isAuthenticated: false } }); + + expect(receiveUnreadCount).not.toHaveBeenCalledWith(); + }); + it('wraps ChannelList in AppContextPanel', () => { const wrapper = subject(); diff --git a/src/platform-apps/channels/container.tsx b/src/platform-apps/channels/container.tsx index d32a6b4b4..52550d28e 100644 --- a/src/platform-apps/channels/container.tsx +++ b/src/platform-apps/channels/container.tsx @@ -17,6 +17,7 @@ import { AppLayout, AppContextPanel, AppContent } from '@zer0-os/zos-component-l import './styles.scss'; import { AuthenticationState } from '../../store/authentication/types'; import { ChatViewContainer } from '../../components/chat-view-container/chat-view-container'; +import { withContext as withAuthenticationContext } from '../../components/authentication/context'; interface PublicProperties { store: Store; @@ -33,6 +34,9 @@ export interface Properties extends PublicProperties { receiveUnreadCount: (domainId: string) => void; stopSyncChannels: () => void; user: AuthenticationState['user']; + context: { + isAuthenticated: boolean; + }; } export class Container extends React.Component { @@ -59,14 +63,30 @@ export class Container extends React.Component { } componentDidMount() { - this.props.fetchChannels(this.props.domainId); - this.props.receiveUnreadCount(this.props.domainId); + const { + context: { isAuthenticated }, + domainId, + } = this.props; + + this.props.fetchChannels(domainId); + + if (isAuthenticated) { + this.props.receiveUnreadCount(domainId); + } } componentDidUpdate(prevProps: Properties) { - if (prevProps.user.data !== this.props.user.data) { - this.props.fetchChannels(this.props.domainId); - this.props.receiveUnreadCount(this.props.domainId); + const { + context: { isAuthenticated }, + user, + domainId, + } = this.props; + + if (isAuthenticated) { + if (prevProps.user.data !== user.data) { + this.props.fetchChannels(domainId); + this.props.receiveUnreadCount(domainId); + } } } @@ -104,4 +124,4 @@ export class Container extends React.Component { } } -export const ChannelsContainer = connectContainer(Container); +export const ChannelsContainer = withAuthenticationContext<{}>(connectContainer(Container));