diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/components/StakingModal.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/components/StakingModal.tsx index a5f1b3b36..809d3e7c9 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/components/StakingModal.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/components/StakingModal.tsx @@ -198,15 +198,16 @@ const InnerStakingModal = ({ const onDeselectAll = () => setCurrentTokenIds([]) - const nfts = - (mode === StakingMode.Stake - ? loadingWalletUnstakedNfts - : mode === StakingMode.Unstake - ? loadingWalletStakedNfts - : undefined) ?? - ({ loading: false, errored: true } as LoadingDataWithError< - LazyNftCardInfo[] - >) + const nfts: LoadingDataWithError = (mode === + StakingMode.Stake + ? loadingWalletUnstakedNfts + : mode === StakingMode.Unstake + ? loadingWalletStakedNfts + : undefined) ?? { + loading: false, + errored: true, + error: new Error('Unexpected failure to load NFTs'), + } const onSelectAll = () => setCurrentTokenIds( diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useStakingInfo.ts b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useStakingInfo.ts index 93f79ff6f..be0a5bab3 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useStakingInfo.ts +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useStakingInfo.ts @@ -12,7 +12,6 @@ import { DaoVotingCw721StakedSelectors, blockHeightSelector, contractVersionSelector, - nftCardInfoSelector, refreshClaimsIdAtom, refreshWalletBalancesIdAtom, } from '@dao-dao/state' @@ -22,8 +21,9 @@ import { useCachedLoadingWithError, useDao, } from '@dao-dao/stateless' +import { LazyNftCardInfo } from '@dao-dao/types' import { NftClaim } from '@dao-dao/types/contracts/DaoVotingCw721Staked' -import { claimAvailable } from '@dao-dao/utils' +import { claimAvailable, getNftKey } from '@dao-dao/utils' import { useWallet } from '../../../../hooks/useWallet' import { UseStakingInfoOptions, UseStakingInfoResponse } from '../types' @@ -130,7 +130,7 @@ export const useStakingInfo = ({ ) // Wallet staked value - const loadingWalletStakedNftsLoadable = useCachedLoading( + const loadingWalletStakedNfts = useCachedLoadingWithError( fetchWalletStakedValue && walletAddress ? DaoVotingCw721StakedSelectors.stakedNftsSelector({ chainId: dao.chainId, @@ -138,48 +138,34 @@ export const useStakingInfo = ({ params: [{ address: walletAddress }], }) : undefined, - undefined - ) - - const loadingWalletStakedNfts = useCachedLoadingWithError( - !loadingWalletStakedNftsLoadable.loading && - loadingWalletStakedNftsLoadable.data - ? waitForAll( - loadingWalletStakedNftsLoadable.data?.map((tokenId) => - nftCardInfoSelector({ - chainId: dao.chainId, - collection: governanceTokenAddress, - tokenId, - }) - ) - ) - : undefined + (data) => + data.map( + (tokenId): LazyNftCardInfo => ({ + key: getNftKey(dao.chainId, governanceTokenAddress, tokenId), + chainId: dao.chainId, + collectionAddress: governanceTokenAddress, + tokenId, + }) + ) ) - const loadingWalletUnstakedNftsLoadable = useCachedLoadingWithError( + const loadingWalletUnstakedNfts = useCachedLoadingWithError( fetchWalletUnstakedNfts && walletAddress && governanceTokenAddress ? CommonNftSelectors.unpaginatedAllTokensForOwnerSelector({ chainId: dao.chainId, contractAddress: governanceTokenAddress, owner: walletAddress, }) - : undefined - ) - - const loadingWalletUnstakedNfts = useCachedLoadingWithError( - !loadingWalletUnstakedNftsLoadable.loading && - !loadingWalletUnstakedNftsLoadable.errored && - loadingWalletUnstakedNftsLoadable.data - ? waitForAll( - loadingWalletUnstakedNftsLoadable.data?.map((tokenId) => - nftCardInfoSelector({ - chainId: dao.chainId, - collection: governanceTokenAddress, - tokenId, - }) - ) - ) - : undefined + : undefined, + (data) => + data.map( + (tokenId): LazyNftCardInfo => ({ + key: getNftKey(dao.chainId, governanceTokenAddress, tokenId), + chainId: dao.chainId, + collectionAddress: governanceTokenAddress, + tokenId, + }) + ) ) return { @@ -208,13 +194,13 @@ export const useStakingInfo = ({ data: HugeDecimal.from(loadingTotalStakedValue.data.power), }, // Wallet staked value - loadingWalletStakedValue: loadingWalletStakedNftsLoadable.loading + loadingWalletStakedValue: loadingWalletStakedNfts.loading ? { loading: true } - : !loadingWalletStakedNftsLoadable.data + : loadingWalletStakedNfts.errored ? undefined : { loading: false, - data: HugeDecimal.from(loadingWalletStakedNftsLoadable.data.length), + data: HugeDecimal.from(loadingWalletStakedNfts.data.length), }, loadingWalletStakedNfts, loadingWalletUnstakedNfts, diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/types.ts b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/types.ts index 4b6d38032..25356f916 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/types.ts +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/types.ts @@ -3,9 +3,9 @@ import { ContractVersion, Duration, GenericToken, + LazyNftCardInfo, LoadingData, LoadingDataWithError, - NftCardInfo, } from '@dao-dao/types' import { NftClaim } from '@dao-dao/types/contracts/DaoVotingCw721Staked' @@ -33,8 +33,8 @@ export interface UseStakingInfoResponse { loadingTotalStakedValue?: LoadingData // Wallet staked value loadingWalletStakedValue?: LoadingData - loadingWalletStakedNfts?: LoadingDataWithError - loadingWalletUnstakedNfts?: LoadingDataWithError + loadingWalletStakedNfts?: LoadingDataWithError + loadingWalletUnstakedNfts?: LoadingDataWithError } export interface UseGovernanceCollectionInfoOptions {