Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ownerData selector #2127

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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.certificate, CertFieldsTypes.nickName)
}

if (!nickname) {
Expand Down
33 changes: 19 additions & 14 deletions packages/state-manager/src/sagas/users/users.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,31 @@ 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
})

let certificates: { pubkey: string, certificate: Certificate }[] = []

certificates =
Array.from(Object.entries(certs))
.sort((a, b) => {
const aTimestamp = getTimestamp(a[1])
const bTimestamp = getTimestamp(b[1])
return aTimestamp - bTimestamp
}).map(cert => {
return {
pubkey: cert[0],
certificate: cert[1]
}
})
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.certificate, CertFieldsTypes.nickName)
const onionAddress = getCertFieldValue(ownerCert.certificate, CertFieldsTypes.commonName)
const peerId = getCertFieldValue(ownerCert.certificate, CertFieldsTypes.peerId)
const dmPublicKey = getCertFieldValue(ownerCert.certificate, CertFieldsTypes.dmPublicKey)
const pubKey = ownerCert.pubkey

return {
username,
Expand Down
Loading