From 905f0af43f538eb3a26ac74416452ac3eab447db Mon Sep 17 00:00:00 2001 From: siepra Date: Tue, 14 Nov 2023 14:38:23 +0100 Subject: [PATCH] fix: correct store data injecting #1847 --- packages/desktop/src/renderer/index.tsx | 2 +- packages/desktop/src/renderer/sagas/index.saga.ts | 4 ++-- ...ationCode.saga.test.ts => customProtocol.saga.test.ts} | 8 ++++---- ...andleInvitationCode.saga.ts => customProtocol.saga.ts} | 8 ++++---- packages/desktop/src/rtl-tests/customProtocol.test.tsx | 2 +- packages/desktop/src/rtl-tests/deep.linking.test.tsx | 8 ++++---- .../src/sagas/communities/communities.slice.ts | 4 +--- 7 files changed, 17 insertions(+), 19 deletions(-) rename packages/desktop/src/renderer/sagas/invitation/{handleInvitationCode.saga.test.ts => customProtocol.saga.test.ts} (87%) rename packages/desktop/src/renderer/sagas/invitation/{handleInvitationCode.saga.ts => customProtocol.saga.ts} (84%) diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index a3a1ecc0b5..ba677dd746 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -22,7 +22,7 @@ ipcRenderer.on('force-save-state', async _event => { ipcRenderer.on('invitation', (_event, invitation) => { console.log('invitation', invitation, 'dispatching action') - store.dispatch(communities.actions.handleInvitationCodes(invitation.codes)) + store.dispatch(communities.actions.customProtocol(invitation.codes)) }) const container = document.getElementById('root') diff --git a/packages/desktop/src/renderer/sagas/index.saga.ts b/packages/desktop/src/renderer/sagas/index.saga.ts index e41f8b6faa..c245f00684 100644 --- a/packages/desktop/src/renderer/sagas/index.saga.ts +++ b/packages/desktop/src/renderer/sagas/index.saga.ts @@ -1,13 +1,13 @@ import { communities } from '@quiet/state-manager' import { all, takeEvery } from 'redux-saga/effects' -import { handleInvitationCodeSaga } from './invitation/handleInvitationCode.saga' +import { customProtocolSaga } from './invitation/customProtocol.saga' import { startConnectionSaga } from './socket/socket.saga' import { socketActions } from './socket/socket.slice' export default function* root(): Generator { const dataPort = new URLSearchParams(window.location.search).get('dataPort') || '' yield all([ - takeEvery(communities.actions.handleInvitationCodes.type, handleInvitationCodeSaga), + takeEvery(communities.actions.customProtocol.type, customProtocolSaga), startConnectionSaga( socketActions.startConnection({ dataPort: parseInt(dataPort), diff --git a/packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.test.ts b/packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.test.ts similarity index 87% rename from packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.test.ts rename to packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.test.ts index d95c7fd035..ef6ef4138e 100644 --- a/packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.test.ts +++ b/packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.test.ts @@ -2,7 +2,7 @@ import { communities, getFactory, Store } from '@quiet/state-manager' import { Community, CommunityOwnership, CreateNetworkPayload, InvitationPair } from '@quiet/types' import { FactoryGirl } from 'factory-girl' import { expectSaga } from 'redux-saga-test-plan' -import { handleInvitationCodeSaga } from './handleInvitationCode.saga' +import { customProtocolSaga } from './customProtocol.saga' import { SocketState } from '../socket/socket.slice' import { prepareStore } from '../../testUtils/prepareStore' import { StoreKeys } from '../../store/store.keys' @@ -39,7 +39,7 @@ describe('Handle invitation code', () => { ownership: CommunityOwnership.User, peers: validInvitationPair, } - await expectSaga(handleInvitationCodeSaga, communities.actions.handleInvitationCodes(validInvitationPair)) + await expectSaga(customProtocolSaga, communities.actions.customProtocol(validInvitationPair)) .withState(store.getState()) .put(communities.actions.createNetwork(payload)) .run() @@ -52,7 +52,7 @@ describe('Handle invitation code', () => { peers: validInvitationPair, } - await expectSaga(handleInvitationCodeSaga, communities.actions.handleInvitationCodes(validInvitationPair)) + await expectSaga(customProtocolSaga, communities.actions.customProtocol(validInvitationPair)) .withState(store.getState()) .put( modalsActions.openModal({ @@ -73,7 +73,7 @@ describe('Handle invitation code', () => { peers: [], } - await expectSaga(handleInvitationCodeSaga, communities.actions.handleInvitationCodes([])) + await expectSaga(customProtocolSaga, communities.actions.customProtocol([])) .withState(store.getState()) .put(communities.actions.clearInvitationCodes()) .put( diff --git a/packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.ts b/packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.ts similarity index 84% rename from packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.ts rename to packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.ts index a43c71a988..f6dd56b2b2 100644 --- a/packages/desktop/src/renderer/sagas/invitation/handleInvitationCode.saga.ts +++ b/packages/desktop/src/renderer/sagas/invitation/customProtocol.saga.ts @@ -6,8 +6,8 @@ import { socketSelectors } from '../socket/socket.selectors' import { ModalName } from '../modals/modals.types' import { modalsActions } from '../modals/modals.slice' -export function* handleInvitationCodeSaga( - action: PayloadAction['payload']> +export function* customProtocolSaga( + action: PayloadAction['payload']> ): Generator { while (true) { const connected = yield* select(socketSelectors.isConnected) @@ -17,8 +17,8 @@ export function* handleInvitationCodeSaga( yield* delay(500) } - const currentCommunityId = yield* select(communities.selectors.currentCommunityId) - if (currentCommunityId) { + const community = yield* select(communities.selectors.currentCommunity) + if (community) { yield* put( modalsActions.openModal({ name: ModalName.warningModal, diff --git a/packages/desktop/src/rtl-tests/customProtocol.test.tsx b/packages/desktop/src/rtl-tests/customProtocol.test.tsx index b0dbcaf697..9f1d54fc28 100644 --- a/packages/desktop/src/rtl-tests/customProtocol.test.tsx +++ b/packages/desktop/src/rtl-tests/customProtocol.test.tsx @@ -69,7 +69,7 @@ describe('Opening app through custom protocol', () => { { peerId: 'abcdef', onionAddress: 'bidrmzr3ee6qa2vvrlcnqvvvsk2gmjktcqkunba326parszr44gibwyd' }, ] - store.dispatch(communities.actions.handleInvitationCodes(invitationCodes)) + store.dispatch(communities.actions.customProtocol(invitationCodes)) store.dispatch(modalsActions.openModal({ name: ModalName.joinCommunityModal })) diff --git a/packages/desktop/src/rtl-tests/deep.linking.test.tsx b/packages/desktop/src/rtl-tests/deep.linking.test.tsx index 6565cee4ac..dc9bf874d6 100644 --- a/packages/desktop/src/rtl-tests/deep.linking.test.tsx +++ b/packages/desktop/src/rtl-tests/deep.linking.test.tsx @@ -38,13 +38,13 @@ describe('Deep linking', () => { }, ] - store.dispatch(communities.actions.handleInvitationCodes(validPair)) + store.dispatch(communities.actions.customProtocol(validPair)) await act(async () => {}) const originalNetwork = communities.selectors.currentCommunity(store.getState()) // Redo the action to provoke renewed saga runs - store.dispatch(communities.actions.handleInvitationCodes(validPair)) + store.dispatch(communities.actions.customProtocol(validPair)) await act(async () => {}) const currentNetwork = communities.selectors.currentCommunity(store.getState()) @@ -53,12 +53,12 @@ describe('Deep linking', () => { expect(actions).toMatchInlineSnapshot(` Array [ - "Communities/handleInvitationCodes", + "Communities/customProtocol", "Communities/createNetwork", "Communities/setInvitationCodes", "Communities/addNewCommunity", "Communities/setCurrentCommunity", - "Communities/handleInvitationCodes", + "Communities/customProtocol", "Modals/openModal", ] `) diff --git a/packages/state-manager/src/sagas/communities/communities.slice.ts b/packages/state-manager/src/sagas/communities/communities.slice.ts index 1b37740456..124abf1085 100644 --- a/packages/state-manager/src/sagas/communities/communities.slice.ts +++ b/packages/state-manager/src/sagas/communities/communities.slice.ts @@ -93,9 +93,7 @@ export const communitiesSlice = createSlice({ }, }) }, - handleInvitationCodes: (state, action: PayloadAction) => { - state.invitationCodes = action.payload - }, + customProtocol: (state, _action: PayloadAction) => state, setInvitationCodes: (state, action: PayloadAction) => { state.invitationCodes = action.payload },