Skip to content

Commit

Permalink
fix: correct store data injecting #1847
Browse files Browse the repository at this point in the history
  • Loading branch information
siepra committed Nov 14, 2023
1 parent b00fb79 commit 905f0af
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/desktop/src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions packages/desktop/src/renderer/sagas/index.saga.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand All @@ -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({
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReturnType<typeof communities.actions.handleInvitationCodes>['payload']>
export function* customProtocolSaga(
action: PayloadAction<ReturnType<typeof communities.actions.customProtocol>['payload']>
): Generator {
while (true) {
const connected = yield* select(socketSelectors.isConnected)
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/rtl-tests/customProtocol.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))

Expand Down
8 changes: 4 additions & 4 deletions packages/desktop/src/rtl-tests/deep.linking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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",
]
`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ export const communitiesSlice = createSlice({
},
})
},
handleInvitationCodes: (state, action: PayloadAction<InvitationPair[]>) => {
state.invitationCodes = action.payload
},
customProtocol: (state, _action: PayloadAction<InvitationPair[]>) => state,
setInvitationCodes: (state, action: PayloadAction<InvitationPair[]>) => {
state.invitationCodes = action.payload
},
Expand Down

0 comments on commit 905f0af

Please sign in to comment.