Skip to content

Commit

Permalink
show undeployed safes in the owned safes list (#3278)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmealy authored Feb 16, 2024
1 parent ebfe991 commit b330624
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/welcome/MyAccounts/useAllSafes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useAllOwnedSafes from './useAllOwnedSafes'
import useChains from '@/hooks/useChains'
import useChainId from '@/hooks/useChainId'
import useWallet from '@/hooks/wallets/useWallet'
import { selectUndeployedSafes } from '@/store/slices'

export type SafeItems = Array<{
chainId: string
Expand Down Expand Up @@ -35,6 +36,7 @@ const useAllSafes = (): SafeItems => {
const allAdded = useAddedSafes()
const { configs } = useChains()
const currentChainId = useChainId()
const undeployedSafes = useAppSelector(selectUndeployedSafes)

return useMemo<SafeItems>(() => {
const chains = uniq([currentChainId].concat(Object.keys(allAdded)).concat(Object.keys(allOwned)))
Expand All @@ -43,17 +45,22 @@ const useAllSafes = (): SafeItems => {
if (!configs.some((item) => item.chainId === chainId)) return []
const addedOnChain = Object.keys(allAdded[chainId] || {})
const ownedOnChain = allOwned[chainId]
const undeployedOnChain = Object.keys(undeployedSafes[chainId] || {})
const uniqueAddresses = uniq(addedOnChain.concat(ownedOnChain)).filter(Boolean)

return uniqueAddresses.map((address) => ({
address,
chainId,
isWatchlist: !(ownedOnChain || []).includes(address),
threshold: allAdded[chainId]?.[address]?.threshold,
owners: allAdded[chainId]?.[address]?.owners.length,
}))
return uniqueAddresses.map((address) => {
const isUndeployed = undeployedOnChain.includes(address)
const isOwned = (ownedOnChain || []).includes(address)
return {
address,
chainId,
isWatchlist: !isOwned && !isUndeployed,
threshold: allAdded[chainId]?.[address]?.threshold,
owners: allAdded[chainId]?.[address]?.owners.length,
}
})
})
}, [configs, allAdded, allOwned, currentChainId])
}, [configs, allAdded, allOwned, currentChainId, undeployedSafes])
}

export default useAllSafes

0 comments on commit b330624

Please sign in to comment.