Skip to content

Commit

Permalink
Change voting power for voting section
Browse files Browse the repository at this point in the history
Signed-off-by: Manank Patni <[email protected]>
  • Loading branch information
Man-Jain committed Sep 19, 2023
1 parent 19f70fd commit 9a9799f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/modules/lite/explorer/pages/ProposalDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => {
const community = useCommunity(id)
const poll = useSinglePoll(proposalId, id, community)
const choices = usePollChoices(poll, refresh)
const { data: voteWeight } = useTokenVoteWeight(dao?.data.token.contract)
const { data: voteWeight } = useTokenVoteWeight(dao?.data.token.contract, poll?.referenceBlock)
const [selectedVotes, setSelectedVotes] = useState<Choice[]>([])

useEffect(() => {
Expand Down
5 changes: 1 addition & 4 deletions src/services/bakingBad/delegations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Network } from "services/beacon"
import { networkNameMap } from ".."
import { DelegationDTO, TokenDelegationDTO } from "./types"
import BigNumber from "bignumber.js"
import { getCurrentBlock } from "services/utils/utils"
import { EnvKey, getEnv } from "services/config"

export const getLatestDelegation = async (daoAddress: string, network: Network) => {
Expand Down Expand Up @@ -41,9 +40,7 @@ export const getTokenDelegation = async (tokenAddress: string, account: string,
return delegatedTo
}

export const getTokenVoteWeight = async (tokenAddress: string, account: string, network: Network) => {
const level = await getCurrentBlock(network)

export const getTokenVoteWeight = async (tokenAddress: string, account: string, network: Network, level: string) => {
const url = `${getEnv(
EnvKey.REACT_APP_LITE_API_URL
)}/network/${network}/token/${tokenAddress}/token-id/0/voting-power?userAddress=${account}&level=${level}`
Expand Down
10 changes: 6 additions & 4 deletions src/services/contracts/token/hooks/useTokenVoteWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import BigNumber from "bignumber.js"
import { useQuery } from "react-query"
import { getTokenVoteWeight } from "services/bakingBad/delegations"
import { useTezos } from "services/beacon/hooks/useTezos"
import { getCurrentBlock } from "services/utils/utils"

export const useTokenVoteWeight = (tokenAddress: string | undefined) => {
export const useTokenVoteWeight = (tokenAddress: string | undefined, level?: string) => {
const { network, account } = useTezos()

const { data, ...rest } = useQuery<BigNumber | undefined, Error>(
["userTokenVoteWeight", tokenAddress],
["userTokenVoteWeight", tokenAddress, level],
async () => {
if (tokenAddress) {
return await getTokenVoteWeight(tokenAddress, account, network)
const blockLevel = level ? level : await getCurrentBlock(network)
if (tokenAddress && blockLevel) {
return await getTokenVoteWeight(tokenAddress, account, network, blockLevel)
}
},
{
Expand Down

0 comments on commit 9a9799f

Please sign in to comment.