-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
consolidated following and membership DAOs list
- Loading branch information
Showing
19 changed files
with
270 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,8 @@ | ||
import { useCallback } from 'react' | ||
import { useSetRecoilState } from 'recoil' | ||
|
||
import { commandModalVisibleAtom } from '@dao-dao/state/recoil' | ||
import { ProfileDaos as StatelessProfileDaos } from '@dao-dao/stateless' | ||
|
||
import { useFeed } from '../../feed' | ||
import { useLoadingFollowingDaoCardInfos, useProfile } from '../../hooks' | ||
import { DaoCard } from '../dao/DaoCard' | ||
import { LinkWrapper } from '../LinkWrapper' | ||
import { WalletDaos } from '../wallet' | ||
import { ProfileAddChains } from './ProfileAddChains' | ||
|
||
export const ProfileDaos = () => { | ||
const setCommandModalVisible = useSetRecoilState(commandModalVisibleAtom) | ||
|
||
const followingDaosLoading = useLoadingFollowingDaoCardInfos() | ||
const feed = useFeed() | ||
|
||
const { chains } = useProfile({ | ||
onlySupported: true, | ||
}) | ||
|
||
const openSearch = useCallback( | ||
() => setCommandModalVisible(true), | ||
[setCommandModalVisible] | ||
) | ||
import { ProfileFeed } from './ProfileFeed' | ||
|
||
return ( | ||
<StatelessProfileDaos | ||
ProfileAddChains={ProfileAddChains} | ||
WalletDaos={WalletDaos} | ||
chains={chains} | ||
feedProps={{ | ||
state: feed, | ||
LinkWrapper, | ||
}} | ||
followingDaosProps={{ | ||
DaoCard, | ||
openSearch, | ||
followingDaos: followingDaosLoading, | ||
}} | ||
/> | ||
) | ||
} | ||
export const ProfileDaos = () => ( | ||
<StatelessProfileDaos ProfileFeed={ProfileFeed} WalletDaos={WalletDaos} /> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ProfileFeed as StatelessProfileFeed } from '@dao-dao/stateless' | ||
|
||
import { useFeed } from '../../feed' | ||
import { LinkWrapper } from '../LinkWrapper' | ||
|
||
export const ProfileFeed = () => { | ||
const feed = useFeed() | ||
|
||
return <StatelessProfileFeed LinkWrapper={LinkWrapper} state={feed} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,115 @@ | ||
import { waitForAny } from 'recoil' | ||
import { useCallback } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { constSelector, useSetRecoilState, waitForAny } from 'recoil' | ||
|
||
import { commandModalVisibleAtom } from '@dao-dao/state/recoil' | ||
import { | ||
WalletDaos as StatelessWalletDaos, | ||
useCachedLoadingWithError, | ||
useChain, | ||
} from '@dao-dao/stateless' | ||
import { StatefulWalletDaosProps } from '@dao-dao/types' | ||
import { transformLoadingDataWithError } from '@dao-dao/utils' | ||
import { LazyDaoCardProps, StatefulWalletDaosProps } from '@dao-dao/types' | ||
import { getSupportedChains } from '@dao-dao/utils' | ||
|
||
import { walletDaosSelector } from '../../recoil' | ||
import { useProfile } from '../../hooks/useProfile' | ||
import { | ||
lazyWalletDaosSelector, | ||
lazyWalletFollowingDaosSelector, | ||
} from '../../recoil' | ||
import { LazyDaoCard } from '../dao' | ||
import { ProfileAddChains } from '../profile/ProfileAddChains' | ||
|
||
export const WalletDaos = ({ address }: StatefulWalletDaosProps) => { | ||
const { t } = useTranslation() | ||
|
||
const { chain_id: chainId } = useChain() | ||
const { connected, chains } = useProfile({ | ||
address, | ||
onlySupported: true, | ||
}) | ||
|
||
const missingChains = | ||
!chains.loading && chains.data.length < getSupportedChains().length | ||
|
||
export const WalletDaos = ({ | ||
chainWallets, | ||
...props | ||
}: StatefulWalletDaosProps) => { | ||
const walletDaos = useCachedLoadingWithError( | ||
chainWallets.loading || chainWallets.errored | ||
chains.loading | ||
? undefined | ||
: // If no chains and an address is passed, just use the current chain. | ||
chains.data.length === 0 && address | ||
? waitForAny([ | ||
waitForAny([ | ||
lazyWalletDaosSelector({ | ||
chainId, | ||
address, | ||
}), | ||
// Can't load following DAOs if there are no chains and thus no | ||
// public key to load from. | ||
constSelector([]), | ||
]), | ||
]) | ||
: waitForAny( | ||
chainWallets.data.map((chainWallet) => | ||
walletDaosSelector(chainWallet) | ||
chains.data.map(({ chainId, address, publicKey }) => | ||
waitForAny([ | ||
lazyWalletDaosSelector({ | ||
chainId, | ||
address, | ||
}), | ||
// If wallet connected, load following. | ||
connected | ||
? lazyWalletFollowingDaosSelector({ | ||
chainId, | ||
publicKey, | ||
}) | ||
: constSelector([]), | ||
]) | ||
) | ||
), | ||
(data) => | ||
data | ||
.flatMap((loadable) => loadable.valueMaybe() || []) | ||
.flatMap((loadable): LazyDaoCardProps[] => { | ||
if (loadable.state !== 'hasValue') { | ||
return [] | ||
} | ||
|
||
const [memberOf, following] = loadable.contents | ||
|
||
return [ | ||
...(memberOf.valueMaybe()?.map((props) => ({ | ||
...props, | ||
isMember: true, | ||
})) || []), | ||
...(following.valueMaybe()?.map((props) => ({ | ||
...props, | ||
isFollowed: true, | ||
})) || []), | ||
] | ||
}) | ||
.sort((a, b) => a.name.localeCompare(b.name)) | ||
) | ||
|
||
const setCommandModalVisible = useSetRecoilState(commandModalVisibleAtom) | ||
const openSearch = useCallback( | ||
() => setCommandModalVisible(true), | ||
[setCommandModalVisible] | ||
) | ||
|
||
return ( | ||
<StatelessWalletDaos | ||
{...props} | ||
LazyDaoCard={LazyDaoCard} | ||
chainIds={transformLoadingDataWithError(chainWallets, (data) => | ||
data.map(({ chainId }) => chainId) | ||
<div className="flex flex-col gap-4"> | ||
<StatelessWalletDaos | ||
LazyDaoCard={LazyDaoCard} | ||
daos={walletDaos} | ||
includesFollowing={!address} | ||
openSearch={address ? undefined : openSearch} | ||
/> | ||
|
||
{missingChains && connected && ( | ||
<ProfileAddChains | ||
className="self-end" | ||
onlySupported | ||
prompt={t('button.addChains')} | ||
promptTooltip={t('info.supportedChainDaosNotShowingUpPrompt')} | ||
/> | ||
)} | ||
daos={chainWallets.errored ? chainWallets : walletDaos} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.