diff --git a/src/modules/explorer/pages/User/components/DelegationBanner.tsx b/src/modules/explorer/pages/User/components/DelegationBanner.tsx index a7948286..cbf18de7 100644 --- a/src/modules/explorer/pages/User/components/DelegationBanner.tsx +++ b/src/modules/explorer/pages/User/components/DelegationBanner.tsx @@ -6,7 +6,7 @@ import { Edit } from "@material-ui/icons" import { DelegationDialog } from "./DelegationModal" import { useDelegationStatus } from "services/contracts/token/hooks/useDelegationStatus" import { useTezos } from "services/beacon/hooks/useTezos" -import { useDelegationVoteWeight } from "services/contracts/token/hooks/useDelegationVoteWeight" +import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight" import BigNumber from "bignumber.js" import { parseUnits } from "services/contracts/utils" import { ProfileAvatar } from "modules/explorer/components/styled/ProfileAvatar" @@ -65,7 +65,7 @@ export const Delegation: React.FC<{ daoId: string }> = ({ daoId }) => { const { data: delegatedTo, isLoading, refetch } = useDelegationStatus(dao?.data.token.contract) const [delegationStatus, setDelegationStatus] = useState(DelegationsType.NOT_DELEGATING) const [openModal, setOpenModal] = useState(false) - const { data: voteWeight } = useDelegationVoteWeight(dao?.data.token.contract) + const { data: voteWeight } = useTokenVoteWeight(dao?.data.token.contract) const [loadingRes, setLoadingRes] = useState(true) const [shouldRefetch, setShouldRefetch] = useState(true) diff --git a/src/modules/explorer/pages/User/index.tsx b/src/modules/explorer/pages/User/index.tsx index ec243953..444686cd 100644 --- a/src/modules/explorer/pages/User/index.tsx +++ b/src/modules/explorer/pages/User/index.tsx @@ -19,6 +19,7 @@ import { UserProfileName } from "../../components/UserProfileName" import { DropButton } from "../Proposals" import { usePolls } from "modules/lite/explorer/hooks/usePolls" import { Delegation } from "./components/DelegationBanner" +import { useTokenDelegationSupported } from "services/contracts/token/hooks/useTokenDelegationSupported" const ContentBlockItem = styled(Grid)({ padding: "35px 52px", @@ -103,6 +104,7 @@ export const User: React.FC = () => { const daoId = useDAOID() const { data, cycleInfo } = useDAO(daoId) const { data: proposals } = useProposals(daoId) + const history = useHistory() const { data: executedProposals } = useProposals(daoId, ProposalStatus.EXECUTED) const { data: droppedProposals } = useProposals(daoId, ProposalStatus.DROPPED) @@ -110,6 +112,8 @@ export const User: React.FC = () => { const polls = usePolls(data?.liteDAOData?._id) const pollsPosted = polls?.filter(p => p.author === account) + const { data: isTokenDelegationSupported } = useTokenDelegationSupported(data?.data.token.contract) + useEffect(() => { if (!account) { history.push(`../${daoId}`) @@ -207,7 +211,8 @@ export const User: React.FC = () => { - + {isTokenDelegationSupported ? : null} + {proposalsCreated && cycleInfo && ( ({ paddingBottom: 19, @@ -94,10 +93,8 @@ export const Choices: React.FC = ({ choices, submitForm, isLoading, votingS const { data } = useDAO(daoId) const liteDAOId = data?.liteDAOData?._id ? data?.liteDAOData?._id : id const tokenAddress = useToken(liteDAOId) - const { data: userBalance } = useUserTokenBalance(tokenAddress) - console.log("userBalance: ", userBalance) - const canCreateProposal = userBalance && new BigNumber(userBalance).gt(0) ? true : false - console.log("canCreateProposal: ", canCreateProposal) + const { data: userTokenVoteWeight } = useTokenVoteWeight(tokenAddress) + const canCreateProposal = userTokenVoteWeight && userTokenVoteWeight.gt(0) ? true : false return ( diff --git a/src/modules/lite/explorer/components/ProposalTableRow.tsx b/src/modules/lite/explorer/components/ProposalTableRow.tsx index d982cf8e..e7b14a63 100644 --- a/src/modules/lite/explorer/components/ProposalTableRow.tsx +++ b/src/modules/lite/explorer/components/ProposalTableRow.tsx @@ -1,13 +1,11 @@ -import React, { createContext, useContext, useEffect, useState } from "react" +import React from "react" import { styled, Grid, Typography, useTheme, useMediaQuery, LinearProgress } from "@material-ui/core" import { RowContainer } from "./tables/RowContainer" import { ProposalStatus, TableStatusBadge } from "./ProposalTableRowStatusBadge" import { useHistory } from "react-router" import { Blockie } from "modules/common/Blockie" import { toShortAddress } from "services/contracts/utils" -import { Choice } from "models/Choice" import { Poll } from "models/Polls" -import { ChoiceDetails } from "./ChoiceDetails" import { usePollChoices } from "../hooks/usePollChoices" export interface ProposalTableRowData { @@ -83,17 +81,6 @@ export const ProposalTableRow: React.FC<{ poll: Poll; daoId?: string }> = ({ pol {poll.description} - - {choices && choices.length > 0 - ? choices.map((choice: Choice, index: number) => ( - - )) - : null} ) } diff --git a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx index 1e91affc..9da222db 100644 --- a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx +++ b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx @@ -16,9 +16,8 @@ import { useSinglePoll } from "../../hooks/usePoll" import { ProposalStatus } from "../../components/ProposalTableRowStatusBadge" import { BackButton } from "modules/lite/components/BackButton" import { voteOnLiteProposal } from "services/services/lite/lite-services" -import { useDelegationStatus } from "services/contracts/token/hooks/useDelegationStatus" import { useDAO } from "services/services/dao/hooks/useDAO" -import { useDelegationVoteWeight } from "services/contracts/token/hooks/useDelegationVoteWeight" +import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight" import BigNumber from "bignumber.js" const PageContainer = styled("div")({ @@ -63,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 } = useDelegationVoteWeight(dao?.data.token.contract) + const { data: voteWeight } = useTokenVoteWeight(dao?.data.token.contract) const [selectedVotes, setSelectedVotes] = useState([]) useEffect(() => { diff --git a/src/services/bakingBad/delegations/index.ts b/src/services/bakingBad/delegations/index.ts index cb80d47e..c810b642 100644 --- a/src/services/bakingBad/delegations/index.ts +++ b/src/services/bakingBad/delegations/index.ts @@ -41,7 +41,7 @@ export const getTokenDelegation = async (tokenAddress: string, account: string, return delegatedTo } -export const getTokenDelegationVoteWeight = async (tokenAddress: string, account: string, network: Network) => { +export const getTokenVoteWeight = async (tokenAddress: string, account: string, network: Network) => { const level = await getCurrentBlock(network) const url = `${getEnv( diff --git a/src/services/bakingBad/tokenBalances/index.ts b/src/services/bakingBad/tokenBalances/index.ts index 297af55c..d595754f 100644 --- a/src/services/bakingBad/tokenBalances/index.ts +++ b/src/services/bakingBad/tokenBalances/index.ts @@ -218,6 +218,19 @@ export const getUserTokenBalance = async (accountAddress: string, network: Netwo return userTokenBalance } +export const isTokenDelegationSupported = async (tezos: TezosToolkit, address: string) => { + const token = await tezos.wallet.at(address) + + const contractViews = Object.keys(token.contractViews) + const votingPowerView = contractViews.find(view => view === "voting_power") + + if (votingPowerView) { + return true + } + + return false +} + export const getVotingPowerAtReferenceBlock = async ( accountAddress: string, network: Network = "mainnet", diff --git a/src/services/contracts/token/hooks/useTokenDelegationSupported.ts b/src/services/contracts/token/hooks/useTokenDelegationSupported.ts new file mode 100644 index 00000000..be26151c --- /dev/null +++ b/src/services/contracts/token/hooks/useTokenDelegationSupported.ts @@ -0,0 +1,26 @@ +import { useQuery } from "react-query" +import { isTokenDelegationSupported } from "services/bakingBad/tokenBalances" +import { useTezos } from "services/beacon/hooks/useTezos" + +export const useTokenDelegationSupported = (tokenAddress: string | undefined) => { + const { tezos } = useTezos() + + const { data, ...rest } = useQuery( + ["delegationSupported", tokenAddress], + async () => { + let tokenDelegationSupported = false + if (tokenAddress) { + tokenDelegationSupported = await isTokenDelegationSupported(tezos, tokenAddress) + } + return tokenDelegationSupported + }, + { + enabled: !!tokenAddress + } + ) + + return { + data, + ...rest + } +} diff --git a/src/services/contracts/token/hooks/useDelegationVoteWeight.ts b/src/services/contracts/token/hooks/useTokenVoteWeight.ts similarity index 58% rename from src/services/contracts/token/hooks/useDelegationVoteWeight.ts rename to src/services/contracts/token/hooks/useTokenVoteWeight.ts index 6765e580..8538581e 100644 --- a/src/services/contracts/token/hooks/useDelegationVoteWeight.ts +++ b/src/services/contracts/token/hooks/useTokenVoteWeight.ts @@ -1,16 +1,16 @@ import BigNumber from "bignumber.js" import { useQuery } from "react-query" -import { getTokenDelegationVoteWeight } from "services/bakingBad/delegations" +import { getTokenVoteWeight } from "services/bakingBad/delegations" import { useTezos } from "services/beacon/hooks/useTezos" -export const useDelegationVoteWeight = (tokenAddress: string | undefined) => { +export const useTokenVoteWeight = (tokenAddress: string | undefined) => { const { network, account } = useTezos() const { data, ...rest } = useQuery( - ["delegationVoteWeight", tokenAddress], + ["userTokenVoteWeight", tokenAddress], async () => { if (tokenAddress) { - return await getTokenDelegationVoteWeight(tokenAddress, account, network) + return await getTokenVoteWeight(tokenAddress, account, network) } }, { diff --git a/src/services/contracts/token/hooks/useUserTokenBalance.ts b/src/services/contracts/token/hooks/useUserTokenBalance.ts index 4a32af84..0bf5337e 100644 --- a/src/services/contracts/token/hooks/useUserTokenBalance.ts +++ b/src/services/contracts/token/hooks/useUserTokenBalance.ts @@ -1,6 +1,4 @@ -import BigNumber from "bignumber.js" import { useQuery } from "react-query" -import { getTokenDelegationVoteWeight } from "services/bakingBad/delegations" import { getUserTokenBalance } from "services/bakingBad/tokenBalances" import { useTezos } from "services/beacon/hooks/useTezos"