Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
node-version: "22.x"

- name: Install dependencies
run: npm ci
run: npm install

- name: Run ESLint
run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
node-version: "22.x"

- name: Install dependencies
run: npm ci
run: npm install

- name: Compile locale files
run: npm run lingui:compile
Expand Down
27 changes: 4 additions & 23 deletions src/components/AvatarRecord/index.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Buffer } from 'buffer'

import { useMemo } from 'react'

import { generateAvatarInitials } from 'pear-apps-utils-avatar-initials'
import { CheckIcon, StarIcon } from 'pearpass-lib-ui-react-native-components'
import { colors } from 'pearpass-lib-ui-theme-provider/native'
import { getDefaultFavicon } from 'pearpass-lib-vault'
import { useFavicon } from 'pearpass-lib-vault'

import {
AvatarImage,
Expand All @@ -14,7 +12,6 @@ import {
ItemImageContainer
} from './styles'
import { RECORD_COLOR_BY_TYPE } from '../../constants/recordColorByType'
import { extractDomainName } from '../../utils/extractDomainName'

global.Buffer = global.Buffer || Buffer

Expand All @@ -34,23 +31,7 @@ export const AvatarRecord = ({
isSelected,
websiteDomain
}) => {
const avatarSrc = useMemo(() => {
if (!websiteDomain) {
return null
}

const website = extractDomainName(websiteDomain)

const avatarBuffer = getDefaultFavicon(website) || null

if (!avatarBuffer) {
return null
}

const base64 = Buffer.from(avatarBuffer).toString('base64')

return base64 ? `data:image/png;base64,${base64}` : null
}, [websiteDomain])
const { faviconSrc } = useFavicon({ url: websiteDomain })

if (isSelected) {
return (
Expand All @@ -62,10 +43,10 @@ export const AvatarRecord = ({

return (
<ItemImageContainer isSelected={isSelected} size={size}>
{avatarSrc ? (
{faviconSrc ? (
<AvatarImage
testID="avatar-image"
source={{ uri: avatarSrc }}
source={{ uri: faviconSrc }}
size={size}
/>
) : (
Expand Down
16 changes: 15 additions & 1 deletion src/components/AvatarRecord/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ jest.mock('pearpass-lib-ui-react-native-components', () => ({
}))

jest.mock('pearpass-lib-vault', () => ({
getDefaultFavicon: jest.fn()
getDefaultFavicon: jest.fn(),
useFavicon: jest.fn(({ url }) => {
const { getDefaultFavicon } = require('pearpass-lib-vault')
const { extractDomainName } = require('../../utils/extractDomainName')

if (!url) return { faviconSrc: null }

const domain = extractDomainName(url)
const buffer = getDefaultFavicon(domain)

if (!buffer) return { faviconSrc: null }

const base64 = buffer.toString('base64')
return { faviconSrc: `data:image/png;base64,${base64}` }
})
}))

jest.mock('../../utils/extractDomainName', () => ({
Expand Down