diff --git a/packages/state-manager/src/sagas/communities/communities.selectors.ts b/packages/state-manager/src/sagas/communities/communities.selectors.ts index f0e7113803..97c9b60771 100644 --- a/packages/state-manager/src/sagas/communities/communities.selectors.ts +++ b/packages/state-manager/src/sagas/communities/communities.selectors.ts @@ -9,7 +9,7 @@ import { getOldestParsedCerificate } from '../users/users.selectors' // Workaround for "The inferred type of 'communitiesSelectors' cannot be named without a reference to // 'packages/identity/node_modules/pkijs/build'. This is likely not portable. A type annotation is necessary." // https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1270716220 -import type {} from 'pkijs' +import type { } from 'pkijs' const communitiesSlice: CreatedSelectors[StoreKeys.Communities] = (state: StoreState) => state[StoreKeys.Communities] @@ -83,7 +83,7 @@ export const ownerNickname = createSelector( const parsedCert = parseCertificate(certificate) nickname = getCertFieldValue(parsedCert, CertFieldsTypes.nickName) } else { - nickname = getCertFieldValue(oldestParsedCerificate, CertFieldsTypes.nickName) + nickname = getCertFieldValue(oldestParsedCerificate[1], CertFieldsTypes.nickName) } if (!nickname) { diff --git a/packages/state-manager/src/sagas/users/users.selectors.ts b/packages/state-manager/src/sagas/users/users.selectors.ts index 059c053e3b..bd1ac16cee 100644 --- a/packages/state-manager/src/sagas/users/users.selectors.ts +++ b/packages/state-manager/src/sagas/users/users.selectors.ts @@ -124,26 +124,24 @@ export const getUserByPubKey = (pubKey: string) => createSelector(allUsers, user export const getOldestParsedCerificate = createSelector(certificates, certs => { const getTimestamp = (cert: Certificate) => new Date(cert.notBefore.value).getTime() - let certificates: Certificate[] = [] - Object.keys(certs).map(pubKey => { - certificates = [...certificates, certs[pubKey]] - }) - certificates.sort((a, b) => { - const aTimestamp = getTimestamp(a) - const bTimestamp = getTimestamp(b) - return aTimestamp - bTimestamp - }) + const certificates: [string, Certificate][] = + Array.from(Object.entries(certs)) + .sort((a, b) => { + const aTimestamp = getTimestamp(a[1]) + const bTimestamp = getTimestamp(b[1]) + return aTimestamp - bTimestamp + }) return certificates[0] }) export const ownerData = createSelector(getOldestParsedCerificate, ownerCert => { if (!ownerCert) return null - const username = getCertFieldValue(ownerCert, CertFieldsTypes.nickName) - const onionAddress = getCertFieldValue(ownerCert, CertFieldsTypes.commonName) - const peerId = getCertFieldValue(ownerCert, CertFieldsTypes.peerId) - const dmPublicKey = getCertFieldValue(ownerCert, CertFieldsTypes.dmPublicKey) - const pubKey = keyFromCertificate(ownerCert) + const username = getCertFieldValue(ownerCert[1], CertFieldsTypes.nickName) + const onionAddress = getCertFieldValue(ownerCert[1], CertFieldsTypes.commonName) + const peerId = getCertFieldValue(ownerCert[1], CertFieldsTypes.peerId) + const dmPublicKey = getCertFieldValue(ownerCert[1], CertFieldsTypes.dmPublicKey) + const pubKey = ownerCert[0] return { username,