Skip to content

Commit

Permalink
Fix/joining by QR code and not showing username taken screen for user…
Browse files Browse the repository at this point in the history
… who has unique name (#1962)

* fix:fixed mobile bugs - joining by QR code and not showing username taken screen for user who has unique name

* test:fix splash screen test

* test:fix component styles

* test:fix snapshots

* fix:remove params.code from splash screen

* fix:problem with path and race condition in state manager

* fix:state manager tests

* fix:update certificate saga
  • Loading branch information
Kacper-RF authored Oct 13, 2023
1 parent ef94963 commit f85230d
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 32 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[unreleased]

* Shorter dots-placeholder for invite link

* Fixed mobile bugs - joining by QR code and not showing username taken screen for user who has unique name

[Unreleased]
* Shorter dots-placeholder for invite link

* Revert adjusting bootstrap scripts for developing on Windows

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ describe('DuplicatedUsername component', () => {
style={
{
"height": 12,
"marginLeft": 4,
"marginRight": 4,
"merginLeft": 4,
"width": 13,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const classes = StyleSheet.create({
width: 13,
height: 12,
marginRight: 4,
merginLeft: 4,
marginLeft: 4,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describe('UserLabel component', () => {
style={
{
"height": 12,
"marginLeft": 4,
"marginRight": 4,
"merginLeft": 4,
"width": 13,
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/mobile/src/route.params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { ScreenNames } from './const/ScreenNames.enum'

// eslint-disable-next-line
export type RootStackParamList = {
[ScreenNames.SplashScreen]: {
code?: string
}
[ScreenNames.SplashScreen]: undefined
[ScreenNames.JoinCommunityScreen]: {
code?: string
}
Expand Down
8 changes: 6 additions & 2 deletions packages/mobile/src/screens/Splash/Splash.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ export const SplashScreen: FC<SplashScreenProps> = ({ route }) => {
const ready = useSelector(initSelectors.ready)

useEffect(() => {
const code = route.params?.code
let code = route.path

// Screen hasn't been open through a link
if (!code) return

if (code.charAt(0) === '?') {
code = code.slice(1, code.length)
}

if (ready) {
dispatch(initActions.deepLink(code))
}
}, [ready, route.params?.code])
}, [ready, route.path])

return <Splash />
}
6 changes: 2 additions & 4 deletions packages/mobile/src/tests/splash.screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ describe('Splash screen', () => {
const invitationCode =
'QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE=y7yczmugl2tekami7sbdz5pfaemvx7bahwthrdvcbzw5vex2crsr26qd'

const route: { key: string; name: ScreenNames.SplashScreen; params: { code?: string } } = {
const route: { key: string; name: ScreenNames.SplashScreen; path: string } = {
key: '',
name: ScreenNames.SplashScreen,
params: {
code: invitationCode,
},
path: invitationCode,
}

renderComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ describe('communitiesSelectors', () => {
certificates: [identity.userCertificate || ''],
})
)

store.dispatch(
usersActions.setAllCerts({
certificates: [identity.userCertificate || ''],
})
)
const ownerNickname = communitiesSelectors.ownerNickname(store.getState())
expect(ownerNickname).toEqual(identity.nickname)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import { identitySelectors } from '../identity.selectors'
import { loadCSR, pubKeyMatch } from '@quiet/identity'
import { identityActions } from '../identity.slice'
import { communitiesSelectors } from '../../communities/communities.selectors'
import { usersActions } from '../../users/users.slice'

export function* updateCertificateSaga(action: PayloadAction<SendCertificatesResponse>): Generator {
const certificate = yield* select(identitySelectors.hasCertificate)
const communityId = yield* select(communitiesSelectors.currentCommunityId)

if (certificate) return

const csr = yield* select(identitySelectors.csr)

if (!csr?.userCsr) return
if (!certificate && csr?.userCsr) {
const parsedCsr = yield* call(loadCSR, csr?.userCsr)

const parsedCsr = yield* call(loadCSR, csr?.userCsr)
const cert = action.payload.certificates.find(cert => {
if (pubKeyMatch(cert, parsedCsr)) return cert
})

const cert = action.payload.certificates.find(cert => {
if (pubKeyMatch(cert, parsedCsr)) return cert
})

if (cert) {
yield* put(
identityActions.storeUserCertificate({
userCertificate: cert,
communityId,
})
)
if (cert) {
yield* put(
identityActions.storeUserCertificate({
userCertificate: cert,
communityId,
})
)
}
}

yield* put(usersActions.setAllCerts(action.payload))
}
6 changes: 6 additions & 0 deletions packages/state-manager/src/sagas/users/users.slice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe('users reducer', () => {
})
)

store.dispatch(
usersActions.setAllCerts({
certificates: [userCertString],
})
)

const certificates = usersSelectors.certificates(store.getState())

expect(certificates[userPubKey]).toEqual(parsedCert)
Expand Down
4 changes: 3 additions & 1 deletion packages/state-manager/src/sagas/users/users.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const usersSlice = createSlice({
storeUserCertificate: (state, action: PayloadAction<{ certificate: string }>) => {
certificatesAdapter.addOne(state.certificates, parseCertificate(action.payload.certificate))
},
responseSendCertificates: (state, action: PayloadAction<SendCertificatesResponse>) => {
responseSendCertificates: (state, action: PayloadAction<SendCertificatesResponse>) => {},

setAllCerts: (state, action: PayloadAction<SendCertificatesResponse>) => {
certificatesAdapter.setAll(
state.certificates,
Object.values(action.payload.certificates).map(item => {
Expand Down

0 comments on commit f85230d

Please sign in to comment.