Skip to content

Commit

Permalink
Synchronize fallback wallet images.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 5, 2023
1 parent ae59c24 commit 2831a23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 11 additions & 3 deletions packages/stateful/hooks/useEntity.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useCachedLoading, useChain } from '@dao-dao/stateless'
import { Entity, EntityType, LoadingData } from '@dao-dao/types'
import { getFallbackImage } from '@dao-dao/utils'
import {
getFallbackImage,
isValidWalletAddress,
toBech32Hash,
} from '@dao-dao/utils'

import { entitySelector } from '../recoil'

// Supports wallets from any chain and DAOs from the current chain or DAOs from
// another chain with a polytone account on the current chain.
export const useEntity = (address: string): LoadingData<Entity> => {
const { chain_id: chainId } = useChain()
const { chain_id: chainId, bech32_prefix: bech32Prefix } = useChain()

return useCachedLoading(
entitySelector({
Expand All @@ -20,7 +24,11 @@ export const useEntity = (address: string): LoadingData<Entity> => {
chainId,
address,
name: null,
imageUrl: getFallbackImage(address),
imageUrl: getFallbackImage(
isValidWalletAddress(address, bech32Prefix)
? toBech32Hash(address)
: address
),
}
)
}
9 changes: 7 additions & 2 deletions packages/stateful/recoil/selectors/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getImageUrlForChainId,
isValidContractAddress,
isValidWalletAddress,
toBech32Hash,
} from '@dao-dao/utils'

import { daoInfoFromPolytoneProxySelector, daoInfoSelector } from './dao'
Expand Down Expand Up @@ -43,6 +44,8 @@ export const entitySelector = selectorFamily<
return entity
}

const isWallet = isValidWalletAddress(address, bech32Prefix)

const [
daoInfoLoadable,
daoInfoFromPolytoneProxyLoadable,
Expand All @@ -65,7 +68,7 @@ export const entitySelector = selectorFamily<
})
: constSelector(undefined),
// try to load profile assuming the address is a wallet address.
address && isValidWalletAddress(address, bech32Prefix)
address && isWallet
? walletProfileDataSelector({
address,
chainId,
Expand Down Expand Up @@ -127,7 +130,9 @@ export const entitySelector = selectorFamily<
: undefined) ||
// Use actual address for fallback image, even if polytone account, so
// the fallback image stays consistent.
getFallbackImage(actualAddress),
getFallbackImage(
isWallet ? toBech32Hash(actualAddress) : actualAddress
),
}

return entity
Expand Down
2 changes: 1 addition & 1 deletion packages/stateful/recoil/selectors/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const makeDefaultWalletProfileData = (
loading,
address,
profile: { ...EMPTY_WALLET_PROFILE },
backupImageUrl: getFallbackImage(),
backupImageUrl: getFallbackImage(toBech32Hash(address) || address),
})

// This selector returns the profile for a wallet with some helpful metadata,
Expand Down

0 comments on commit 2831a23

Please sign in to comment.