diff --git a/packages/desktop/src/renderer/components/CreateUsername/CreateUsername.test.tsx b/packages/desktop/src/renderer/components/CreateUsername/CreateUsername.test.tsx index 61c479484f..e5b406d690 100644 --- a/packages/desktop/src/renderer/components/CreateUsername/CreateUsername.test.tsx +++ b/packages/desktop/src/renderer/components/CreateUsername/CreateUsername.test.tsx @@ -218,7 +218,7 @@ describe('Username taken', () => { class="MuiTypography-root MuiTypography-caption css-1d4bzk2-MuiTypography-root" style="margin-top: 8px;" > - Your username will be public, but you can choose any name you like. No spaces or special characters. Lowercase letters and numbers only. + You can choose any username you like. No spaces or special characters.
= ( setUserName(parsedName) setParsedNameDiffers(name !== parsedName) if (registeredUsers && !isNewUser) { - const allUsersArr = Object.values(registeredUsers).map(user => user.username) - if (allUsersArr.includes(name)) { + const allUsersSet = new Set(Object.values(registeredUsers).map(user => user.username)) + if (allUsersSet.has(name)) { setError('userName', { message: `${name} is already taken` }) } } @@ -301,8 +301,7 @@ export const CreateUsernameComponent: React.FC = ( {!isNewUser && ( - Your username will be public, but you can choose any name you like. No spaces or special characters. - Lowercase letters and numbers only. + You can choose any username you like. No spaces or special characters. )}
diff --git a/packages/mobile/src/components/Registration/UsernameRegistration.component.tsx b/packages/mobile/src/components/Registration/UsernameRegistration.component.tsx index 44d3a1b5bb..7c0301ae07 100644 --- a/packages/mobile/src/components/Registration/UsernameRegistration.component.tsx +++ b/packages/mobile/src/components/Registration/UsernameRegistration.component.tsx @@ -48,8 +48,8 @@ export const UsernameRegistration: FC = ({ setUserName(parsedName) setParsedNameDiffers(name !== parsedName) if (registeredUsers && !isNewUser) { - const allUsersArr = Object.values(registeredUsers).map(user => user.username) - if (allUsersArr.includes(name)) { + const allUsersSet = new Set(Object.values(registeredUsers).map(user => user.username)) + if (allUsersSet.has(name)) { setInputError(`Username @${name} is already taken`) } } diff --git a/packages/state-manager/src/sagas/identity/identity.selectors.ts b/packages/state-manager/src/sagas/identity/identity.selectors.ts index 43e6d44da4..9004adb288 100644 --- a/packages/state-manager/src/sagas/identity/identity.selectors.ts +++ b/packages/state-manager/src/sagas/identity/identity.selectors.ts @@ -26,6 +26,10 @@ export const communityMembership = createSelector(currentIdentity, identity => { return Boolean(identity?.userCsr) }) +export const hasCertificate = createSelector(currentIdentity, identity => { + return Boolean(identity?.userCertificate) +}) + export const joinedCommunities = createSelector(selectCommunities, selectEntities, (communities, identities) => { return communities.filter(community => { return identities[community.id]?.userCertificate @@ -45,9 +49,8 @@ export const usernameTaken = createSelector(currentIdentity, certificatesMapping const username = identity?.nickname if (!username) return false - const allUsernames: string[] = Object.values(certs).map(u => u.username) - - if (allUsernames.includes(username)) { + const allUsersSet = new Set(Object.values(certs).map(user => user.username)) + if (allUsersSet.has(username)) { return true } @@ -63,4 +66,5 @@ export const identitySelectors = { joinTimestamp, csr, usernameTaken, + hasCertificate, } diff --git a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts index da2c954b8b..f536ec15be 100644 --- a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts +++ b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts @@ -87,7 +87,7 @@ describe('registerUsernameSaga', () => { .run() }) - it.only('username taken - use current CSR and new nickname', async () => { + it('username taken - use current CSR and new nickname', async () => { setupCrypto() const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket diff --git a/packages/state-manager/src/sagas/identity/updateCertificate/updateCertificate.saga.ts b/packages/state-manager/src/sagas/identity/updateCertificate/updateCertificate.saga.ts index ca304e8e6a..a03438bd5d 100644 --- a/packages/state-manager/src/sagas/identity/updateCertificate/updateCertificate.saga.ts +++ b/packages/state-manager/src/sagas/identity/updateCertificate/updateCertificate.saga.ts @@ -2,12 +2,12 @@ import { SendCertificatesResponse } from '@quiet/types' import { PayloadAction } from '@reduxjs/toolkit' import { select, call, put } from 'typed-redux-saga' import { identitySelectors } from '../identity.selectors' -import { CertFieldsTypes, getCertFieldValue, getReqFieldValue, loadCSR, parseCertificate } from '@quiet/identity' +import { loadCSR, pubKeyMatch } from '@quiet/identity' import { identityActions } from '../identity.slice' import { communitiesSelectors } from '../../communities/communities.selectors' export function* updateCertificateSaga(action: PayloadAction): Generator { - const certificate = yield* select(identitySelectors.communityMembership) + const certificate = yield* select(identitySelectors.hasCertificate) const communityId = yield* select(communitiesSelectors.currentCommunityId) if (certificate) return @@ -17,12 +17,9 @@ export function* updateCertificateSaga(action: PayloadAction { - const parsedCert = parseCertificate(cert) - const certPubKey = getCertFieldValue(parsedCert, CertFieldsTypes.dmPublicKey) - if (certPubKey === pubKey) return cert + if (pubKeyMatch(cert, parsedCsr)) return cert }) if (cert) {