Skip to content

Commit

Permalink
convert some more to HugeDecimals
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 3, 2024
1 parent 8490e24 commit 6935379
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/state/recoil/selectors/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down

0 comments on commit 6935379

Please sign in to comment.