Skip to content

Commit

Permalink
Synchronize fallback images. (#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Oct 5, 2023
1 parent ae59c24 commit 171ece8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 2 additions & 3 deletions packages/stateful/recoil/selectors/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
STARGAZE_NAMES_CONTRACT,
getChainForChainId,
getFallbackImage,
toBech32Hash,
transformBech32Address,
} from '@dao-dao/utils'

Expand Down Expand Up @@ -100,7 +99,7 @@ export const makeDefaultWalletProfileData = (
loading,
address,
profile: { ...EMPTY_WALLET_PROFILE },
backupImageUrl: getFallbackImage(),
backupImageUrl: getFallbackImage(address),
})

// This selector returns the profile for a wallet with some helpful metadata,
Expand Down Expand Up @@ -135,7 +134,7 @@ export const walletProfileDataSelector = selectorFamily<
profile.nft = pfpkProfile.nft
}

const backupImageUrl = getFallbackImage(toBech32Hash(address))
const backupImageUrl = getFallbackImage(address)

// Set `imageUrl` to PFPK image, defaulting to fallback image.
profile.imageUrl = pfpkProfile?.nft?.imageUrl || backupImageUrl
Expand Down
3 changes: 1 addition & 2 deletions packages/stateless/components/EntityDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
concatAddressStartEnd,
getFallbackImage,
toAccessibleImageUrl,
toBech32Hash,
} from '@dao-dao/utils'

import { useChainContext, useDaoNavHelpers, useDetectTruncate } from '../hooks'
Expand Down Expand Up @@ -102,7 +101,7 @@ export const EntityDisplay = ({
style={{
backgroundImage: `url(${
loadingEntity.loading
? getFallbackImage(toBech32Hash(address))
? getFallbackImage(address)
: toAccessibleImageUrl(loadingEntity.data.imageUrl)
})`,
width: imageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { VoteDisplay } from '@dao-dao/stateful/proposal-module-adapter/adapters/
import { CHAIN_ID } from '@dao-dao/storybook'
import { EntityType } from '@dao-dao/types'
import { Vote } from '@dao-dao/types/contracts/DaoProposalSingle.common'
import { getFallbackImage, toBech32Hash } from '@dao-dao/utils'
import { getFallbackImage } from '@dao-dao/utils'

import { EntityDisplay } from '../EntityDisplay'
import { ProposalVotes, ProposalVotesProps } from './ProposalVotes'
Expand Down Expand Up @@ -45,7 +45,7 @@ export const makeProps = (): ProposalVotesProps<Vote> => ({
chainId: CHAIN_ID,
address: props.address,
name: null,
imageUrl: getFallbackImage(toBech32Hash(props.address)),
imageUrl: getFallbackImage(props.address),
},
}}
{...props}
Expand Down
5 changes: 5 additions & 0 deletions packages/utils/getFallbackImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ChainId } from '@dao-dao/types'

import { getImageUrlForChainId } from './chain'
import { NEUTRON_GOVERNANCE_DAO } from './constants'
import { toBech32Hash } from './conversion'

// fallback images in the public/placeholders directory.
export const getFallbackImage = (identifier = '') => {
Expand All @@ -13,6 +14,10 @@ export const getFallbackImage = (identifier = '') => {
return getImageUrlForChainId(ChainId.NeutronMainnet)
}

// If identitifer is an address, get its bech32 data, so it's consistent
// across chains.
identifier = toBech32Hash(identifier) || identifier

const hashed = identifier.split('').reduce((p, n) => n.charCodeAt(0) + p, 0)
const index = (hashed % 5) + 1
return `/placeholders/${index}.svg`
Expand Down

0 comments on commit 171ece8

Please sign in to comment.