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

Synchronize fallback images #1401

Merged
merged 1 commit into from
Oct 5, 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
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
Loading