diff --git a/packages/state/recoil/selectors/wallet.ts b/packages/state/recoil/selectors/wallet.ts index 2a35384bd..19dd680f2 100644 --- a/packages/state/recoil/selectors/wallet.ts +++ b/packages/state/recoil/selectors/wallet.ts @@ -362,14 +362,14 @@ export const walletTokenCardInfosSelector = selectorFamily< token.denomOrAddress === getNativeTokenForChainId(chainId).denomOrAddress && // Check if anything staked. - Number( + HugeDecimal.from( get( nativeDelegatedBalanceSelector({ address: walletAddress, chainId, }) ).amount - ) > 0 + ).isPositive() const owner = allAccounts[accountIndex] diff --git a/packages/stateful/actions/core/actions/ConfigureRebalancer/Component.tsx b/packages/stateful/actions/core/actions/ConfigureRebalancer/Component.tsx index cc0ab6f49..fa24ed748 100644 --- a/packages/stateful/actions/core/actions/ConfigureRebalancer/Component.tsx +++ b/packages/stateful/actions/core/actions/ConfigureRebalancer/Component.tsx @@ -646,7 +646,7 @@ export const ConfigureRebalancerComponent: ActionComponent< nativeBalances.data.find( ({ token }) => token.denomOrAddress === denom ) ?? {} - const balance = Number(_balance) || 0 + const balance = HugeDecimal.from(_balance || 0) const price = prices.data.find( ({ token: { denomOrAddress: priceDenom } }) => priceDenom === denom @@ -658,9 +658,9 @@ export const ConfigureRebalancerComponent: ActionComponent< return { symbol: token.symbol, - initialAmount: HugeDecimal.from( - balance - ).toHumanReadableNumber(token.decimals), + initialAmount: balance.toHumanReadableNumber( + token.decimals + ), targetProportion: percent / 100, // Add an extra price to account for the initial balance. prices: new Array(rebalanceTimestamps.length + 1) diff --git a/packages/stateful/proposal-module-adapter/adapters/DaoProposalMultiple/components/ProposalVotes/index.tsx b/packages/stateful/proposal-module-adapter/adapters/DaoProposalMultiple/components/ProposalVotes/index.tsx index f33030687..3a0279bef 100644 --- a/packages/stateful/proposal-module-adapter/adapters/DaoProposalMultiple/components/ProposalVotes/index.tsx +++ b/packages/stateful/proposal-module-adapter/adapters/DaoProposalMultiple/components/ProposalVotes/index.tsx @@ -2,6 +2,7 @@ import uniqBy from 'lodash.uniqby' import { useEffect, useState } from 'react' import { useRecoilCallback } from 'recoil' +import { HugeDecimal } from '@dao-dao/math' import { DaoProposalMultipleSelectors } from '@dao-dao/state' import { ProposalVote, @@ -33,8 +34,8 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { const voteOptions = useLoadingVoteOptions() const totalPower = loadingProposal.loading - ? 0 - : Number(loadingProposal.data.total_power) + ? HugeDecimal.zero + : HugeDecimal.from(loadingProposal.data.total_power) const [loading, setLoading] = useState(true) const [noMoreVotes, setNoMoreVotes] = useState(false) @@ -79,8 +80,12 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { ({ vote, voter, power, rationale, votedAt }): ProposalVote => ({ voterAddress: voter, vote, - votingPowerPercent: - totalPower === 0 ? 0 : (Number(power) / totalPower) * 100, + votingPowerPercent: totalPower.isZero() + ? 0 + : HugeDecimal.from(power) + .div(totalPower) + .times(100) + .toNumber(), rationale, votedAt: votedAt ? new Date(votedAt) : undefined, }) @@ -150,8 +155,9 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { ({ vote, voter, power, rationale, votedAt }): ProposalVote => ({ voterAddress: voter, vote, - votingPowerPercent: - totalPower === 0 ? 0 : (Number(power) / totalPower) * 100, + votingPowerPercent: totalPower.isZero() + ? 0 + : HugeDecimal.from(power).div(totalPower).times(100).toNumber(), rationale, votedAt: votedAt ? new Date(votedAt) : undefined, }) diff --git a/packages/stateful/proposal-module-adapter/adapters/DaoProposalSingle/components/ProposalVotes/index.tsx b/packages/stateful/proposal-module-adapter/adapters/DaoProposalSingle/components/ProposalVotes/index.tsx index 52a063309..14ffa572d 100644 --- a/packages/stateful/proposal-module-adapter/adapters/DaoProposalSingle/components/ProposalVotes/index.tsx +++ b/packages/stateful/proposal-module-adapter/adapters/DaoProposalSingle/components/ProposalVotes/index.tsx @@ -2,6 +2,7 @@ import uniqBy from 'lodash.uniqby' import { useEffect, useState } from 'react' import { useRecoilCallback } from 'recoil' +import { HugeDecimal } from '@dao-dao/math' import { DaoProposalSingleCommonSelectors } from '@dao-dao/state' import { ProposalVote, @@ -28,8 +29,8 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { const loadingProposal = useLoadingProposal() const totalPower = loadingProposal.loading - ? 0 - : Number(loadingProposal.data.total_power) + ? HugeDecimal.zero + : HugeDecimal.from(loadingProposal.data.total_power) const [loading, setLoading] = useState(true) const [noMoreVotes, setNoMoreVotes] = useState(false) @@ -74,8 +75,12 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { ({ vote, voter, power, rationale, votedAt }): ProposalVote => ({ voterAddress: voter, vote, - votingPowerPercent: - totalPower === 0 ? 0 : (Number(power) / totalPower) * 100, + votingPowerPercent: totalPower.isZero() + ? 0 + : HugeDecimal.from(power) + .div(totalPower) + .times(100) + .toNumber(), rationale, votedAt: votedAt ? new Date(votedAt) : undefined, }) @@ -145,8 +150,9 @@ export const ProposalVotes = (props: BaseProposalVotesProps) => { ({ vote, voter, power, rationale, votedAt }): ProposalVote => ({ voterAddress: voter, vote, - votingPowerPercent: - totalPower === 0 ? 0 : (Number(power) / totalPower) * 100, + votingPowerPercent: totalPower.isZero() + ? 0 + : HugeDecimal.from(power).div(totalPower).times(100).toNumber(), rationale, votedAt: votedAt ? new Date(votedAt) : undefined, })