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: change hour format to 24h for non english #1417

Merged
Merged
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
119 changes: 62 additions & 57 deletions packages/legacy/core/App/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ import { BifoldLogger } from '../services/logger'
import { Role } from '../types/chat'
import { BifoldError } from '../types/error'
import { Screens, Stacks } from '../types/navigators'
import { CredentialDataForProof, ProofCredentialAttributes, ProofCredentialItems, ProofCredentialPredicates } from '../types/proof-items'
import {
CredentialDataForProof,
ProofCredentialAttributes,
ProofCredentialItems,
ProofCredentialPredicates,
} from '../types/proof-items'
import { ChildFn } from '../types/tour'

import { BifoldAgent } from './agent'
Expand Down Expand Up @@ -133,7 +138,7 @@ export function formatTime(
const sameDay = time.getDate() === now.getDate() && time.getMonth() === now.getMonth() && sameYear
const isPortuguese = i18n.resolvedLanguage === 'pt-BR'
const isNonEnglish = i18n.resolvedLanguage === 'fr' || isPortuguese
const hoursFormat = isPortuguese ? 'HH:mm' : 'h:mm a'
const hoursFormat = isNonEnglish ? 'HH:mm' : 'h:mm a'
// for the shortened approach eg. in chat bubbles
if (chatFormat) {
if (lessThanAMinuteAgo) {
Expand Down Expand Up @@ -174,8 +179,8 @@ export function formatTime(
? momentTime.format(formatString)
: // if non-english, don't include comma between year and month
isNonEnglish
? `${momentTime.format(formatString)} ${momentTime.format('YYYY')}`
: `${momentTime.format(formatString)}, ${momentTime.format('YYYY')}`
? `${momentTime.format(formatString)} ${momentTime.format('YYYY')}`
: `${momentTime.format(formatString)}, ${momentTime.format('YYYY')}`
if (includeHour) {
formattedTime = `${formattedTime}, ${momentTime.format(hoursFormat)}`
}
Expand Down Expand Up @@ -347,7 +352,7 @@ export const schemaIdFromRestrictions = (queries?: AnonCredsProofRequestRestrict
// the '2' here is the enum of the transaction type which, for schemas, is always 2
const schemaId = rstrWithSchemaId
? rstrWithSchemaId.schema_id ||
`${rstrWithSchemaId.issuer_did}:2:${rstrWithSchemaId.schema_name}:${rstrWithSchemaId.schema_version}`
`${rstrWithSchemaId.issuer_did}:2:${rstrWithSchemaId.schema_name}:${rstrWithSchemaId.schema_version}`
: ''
return schemaId
}
Expand Down Expand Up @@ -405,33 +410,33 @@ const evaluateOperation = (attribute: number, pValue: number, pType: AnonCredsPr
*/
export const evaluatePredicates =
(fields: Fields, credId?: string) =>
(proofCredentialItems: ProofCredentialItems): Predicate[] => {
const predicates = proofCredentialItems.predicates
if (!predicates || predicates.length == 0) {
return []
}
(proofCredentialItems: ProofCredentialItems): Predicate[] => {
const predicates = proofCredentialItems.predicates
if (!predicates || predicates.length == 0) {
return []
}

if ((credId && credId != proofCredentialItems.credId) || !proofCredentialItems.credId) {
return []
}
if ((credId && credId != proofCredentialItems.credId) || !proofCredentialItems.credId) {
return []
}

const credentialAttributes = getCredentialInfo(proofCredentialItems.credId, fields).map((ci) => ci.attributes)
const credentialAttributes = getCredentialInfo(proofCredentialItems.credId, fields).map((ci) => ci.attributes)

return predicates.map((predicate: Predicate) => {
const { pType: pType, pValue: pValue, name: field } = predicate
let satisfied = false
return predicates.map((predicate: Predicate) => {
const { pType: pType, pValue: pValue, name: field } = predicate
let satisfied = false

if (field) {
const attribute = (credentialAttributes.find((attr) => attr[field] != undefined) ?? {})[field]
if (field) {
const attribute = (credentialAttributes.find((attr) => attr[field] != undefined) ?? {})[field]

if (attribute && pValue) {
satisfied = evaluateOperation(Number(attribute), Number(pValue), pType as AnonCredsPredicateType)
}
if (attribute && pValue) {
satisfied = evaluateOperation(Number(attribute), Number(pValue), pType as AnonCredsPredicateType)
}
}

return { ...predicate, satisfied }
})
}
return { ...predicate, satisfied }
})
}

// scans through requested attributes and records
// Builds and returns label: value attributes
Expand Down Expand Up @@ -754,25 +759,25 @@ export const retrieveCredentialsForProof = async (
// We should ignore the key, if the value is undefined. For now this is a workaround.
...(hasIndy
? {
indy: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: true,
},
}
indy: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: true,
},
}
: {}),
...(hasAnonCreds
? {
anoncreds: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: true,
},
}
anoncreds: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: true,
},
}
: {}),
...(hasPresentationExchange ? { presentationExchange: {} } : {}),
},
Expand All @@ -786,25 +791,25 @@ export const retrieveCredentialsForProof = async (
// We should ignore the key, if the value is undefined. For now this is a workaround.
...(hasIndy
? {
indy: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: false,
},
}
indy: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: false,
},
}
: {}),
...(hasAnonCreds
? {
anoncreds: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: false,
},
}
anoncreds: {
// Setting `filterByNonRevocationRequirements` to `false` returns all
// credentials even if they are revokable (and revoked). We need this to
// be able to show why a proof cannot be satisfied. Otherwise we can only
// show failure.
filterByNonRevocationRequirements: false,
},
}
: {}),
...(hasPresentationExchange ? { presentationExchange: {} } : {}),
},
Expand Down