diff --git a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx index 9da222db..8087ef31 100644 --- a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx +++ b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx @@ -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([]) useEffect(() => { diff --git a/src/services/bakingBad/delegations/index.ts b/src/services/bakingBad/delegations/index.ts index c810b642..1cde4dd7 100644 --- a/src/services/bakingBad/delegations/index.ts +++ b/src/services/bakingBad/delegations/index.ts @@ -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) => { @@ -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}` diff --git a/src/services/contracts/token/hooks/useTokenVoteWeight.ts b/src/services/contracts/token/hooks/useTokenVoteWeight.ts index 840f9a6d..4329a1fa 100644 --- a/src/services/contracts/token/hooks/useTokenVoteWeight.ts +++ b/src/services/contracts/token/hooks/useTokenVoteWeight.ts @@ -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( - ["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) } }, {