diff --git a/packages/stateful/hooks/useMembership.ts b/packages/stateful/hooks/useMembership.ts index 0dc424d35..301ccaeab 100644 --- a/packages/stateful/hooks/useMembership.ts +++ b/packages/stateful/hooks/useMembership.ts @@ -1,3 +1,4 @@ +import { HugeDecimal } from '@dao-dao/math' import { DaoSource, LoadingDataWithError } from '@dao-dao/types' import { useQueryLoadingDataWithError } from './query/useQueryLoadingDataWithError' @@ -35,12 +36,12 @@ interface UseMembershipResponse { * The current wallet voting weight in the DAO. Will be undefined until it * successfully loads. */ - walletVotingWeight: number | undefined + walletVotingWeight: HugeDecimal | undefined /** * The current wallet voting weight in the DAO. Will be undefined until it * successfully loads. */ - totalVotingWeight: number | undefined + totalVotingWeight: HugeDecimal | undefined } export const useMembership = ({ @@ -76,19 +77,17 @@ export const useMembership = ({ useOnSecretNetworkPermitUpdate() const walletVotingWeight = - !_walletVotingWeight.loading && - !_walletVotingWeight.errored && - !isNaN(Number(_walletVotingWeight.data.power)) - ? Number(_walletVotingWeight.data.power) + !_walletVotingWeight.loading && !_walletVotingWeight.errored + ? HugeDecimal.from(_walletVotingWeight.data.power) : undefined const totalVotingWeight = - !_totalVotingWeight.loading && - !_totalVotingWeight.errored && - !isNaN(Number(_totalVotingWeight.data.power)) - ? Number(_totalVotingWeight.data.power) + !_totalVotingWeight.loading && !_totalVotingWeight.errored + ? HugeDecimal.from(_totalVotingWeight.data.power) : undefined const isMember = - walletVotingWeight !== undefined ? walletVotingWeight > 0 : undefined + walletVotingWeight !== undefined + ? walletVotingWeight.isPositive() + : undefined return { loading: @@ -101,9 +100,7 @@ export const useMembership = ({ : { loading: false, errored: false, - data: - !isNaN(Number(_walletVotingWeight.data.power)) && - Number(_walletVotingWeight.data.power) > 0, + data: isMember ?? false, }, isMember, walletVotingWeight, diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw20Staked/hooks/useMainDaoInfoCards.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw20Staked/hooks/useMainDaoInfoCards.tsx index 084070575..53ab4b515 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw20Staked/hooks/useMainDaoInfoCards.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw20Staked/hooks/useMainDaoInfoCards.tsx @@ -1,7 +1,6 @@ import { useQueryClient } from '@tanstack/react-query' import { useTranslation } from 'react-i18next' -import { HugeDecimal } from '@dao-dao/math' import { indexerQueries } from '@dao-dao/state' import { TokenAmountDisplay, useVotingModule } from '@dao-dao/stateless' import { DaoInfoCard } from '@dao-dao/types' @@ -11,16 +10,21 @@ import { isSecretNetwork, } from '@dao-dao/utils' -import { useMembership, useQueryLoadingDataWithError } from '../../../../hooks' +import { useQueryLoadingDataWithError } from '../../../../hooks' import { useGovernanceTokenInfo } from './useGovernanceTokenInfo' import { useStakingInfo } from './useStakingInfo' export const useMainDaoInfoCards = (): DaoInfoCard[] => { const { t } = useTranslation() const votingModule = useVotingModule() - const { totalVotingWeight } = useMembership() - const { unstakingDuration } = useStakingInfo() + const { loadingTotalStakedValue, unstakingDuration } = useStakingInfo({ + fetchTotalStakedValue: true, + }) + + if (loadingTotalStakedValue === undefined) { + throw new Error(t('error.loadingData')) + } const { governanceToken: { decimals, symbol }, @@ -71,16 +75,21 @@ export const useMainDaoInfoCards = (): DaoInfoCard[] => { tooltip: t('info.totalStakedTooltip', { tokenSymbol: symbol, }), - loading: totalVotingWeight === undefined, - value: - totalVotingWeight === undefined - ? undefined - : formatPercentOf100( - HugeDecimal.from(totalVotingWeight) - .div(HugeDecimal.fromHumanReadable(supply, decimals)) - .times(100) - .toNumber() - ), + value: ( + + ), }, { label: t('title.unstakingPeriod'), diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/MembersTab.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/MembersTab.tsx index 74a8ee7af..6b32733fa 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/MembersTab.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/MembersTab.tsx @@ -1,5 +1,6 @@ import { useTranslation } from 'react-i18next' +import { HugeDecimal } from '@dao-dao/math' import { MembersTab as StatelessMembersTab, useDaoNavHelpers, @@ -49,7 +50,10 @@ export const MembersTab = () => { ? { loading: true } : { loading: false, - data: (weight / totalVotingWeight) * 100, + data: HugeDecimal.from(weight) + .div(totalVotingWeight) + .times(100) + .toNumber(), }, })) || [], } diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/ProfileCardMemberInfo/index.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/ProfileCardMemberInfo/index.tsx index 3ec0852b2..0f7fe2f9d 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/ProfileCardMemberInfo/index.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw4/components/ProfileCardMemberInfo/index.tsx @@ -21,7 +21,10 @@ export const ProfileCardMemberInfo = ({ ? { loading: true } : { loading: false, - data: (walletVotingWeight / totalVotingWeight) * 100, + data: walletVotingWeight + .div(totalVotingWeight) + .times(100) + .toNumber(), } } /> diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useMainDaoInfoCards.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useMainDaoInfoCards.tsx index b8f08060b..b5b83dac7 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useMainDaoInfoCards.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingCw721Staked/hooks/useMainDaoInfoCards.tsx @@ -68,11 +68,24 @@ export const useMainDaoInfoCards = (): DaoInfoCard[] => { tooltip: t('info.totalStakedTooltip', { tokenSymbol: symbol, }), - value: loadingTotalStakedValue.loading - ? '...' - : formatPercentOf100( - loadingTotalStakedValue.data.div(totalSupply).times(100).toNumber() - ), + value: ( + + ), }, { label: t('title.unstakingPeriod'), diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingOnftStaked/hooks/useMainDaoInfoCards.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingOnftStaked/hooks/useMainDaoInfoCards.tsx index 65e00afb6..61d06e0c8 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingOnftStaked/hooks/useMainDaoInfoCards.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingOnftStaked/hooks/useMainDaoInfoCards.tsx @@ -62,11 +62,24 @@ export const useMainDaoInfoCards = (): DaoInfoCard[] => { tooltip: t('info.totalStakedTooltip', { tokenSymbol: symbol, }), - value: loadingTotalStakedValue.loading - ? '...' - : formatPercentOf100( - loadingTotalStakedValue.data.div(totalSupply).times(100).toNumber() - ), + value: ( + + ), }, { label: t('title.unstakingPeriod'), diff --git a/packages/stateful/voting-module-adapter/adapters/DaoVotingTokenStaked/hooks/useMainDaoInfoCards.tsx b/packages/stateful/voting-module-adapter/adapters/DaoVotingTokenStaked/hooks/useMainDaoInfoCards.tsx index 4e3d22b57..d1fbf3c6d 100644 --- a/packages/stateful/voting-module-adapter/adapters/DaoVotingTokenStaked/hooks/useMainDaoInfoCards.tsx +++ b/packages/stateful/voting-module-adapter/adapters/DaoVotingTokenStaked/hooks/useMainDaoInfoCards.tsx @@ -1,12 +1,12 @@ import { useQueryClient } from '@tanstack/react-query' import { useTranslation } from 'react-i18next' -import { HugeDecimal } from '@dao-dao/math' import { indexerQueries } from '@dao-dao/state' import { TokenAmountDisplay, useVotingModule } from '@dao-dao/stateless' import { DaoInfoCard } from '@dao-dao/types' import { convertDurationToHumanReadableString, + formatPercentOf100, isSecretNetwork, } from '@dao-dao/utils' @@ -80,12 +80,16 @@ export const useMainDaoInfoCards = (): DaoInfoCard[] => { }), value: ( ),