diff --git a/src/modules/explorer/components/ProposalActionsDialog.tsx b/src/modules/explorer/components/ProposalActionsDialog.tsx index 8a995d18..a02eda86 100644 --- a/src/modules/explorer/components/ProposalActionsDialog.tsx +++ b/src/modules/explorer/components/ProposalActionsDialog.tsx @@ -128,7 +128,6 @@ export const ProposalActionsDialog: React.FC = ({ open, handleClose }) => const liteDAOId = data?.liteDAOData?._id const shouldDisable = useIsProposalButtonDisabled(daoId) const { network, account } = useTezos() - const isMember = useIsMember(network, data?.liteDAOData?.tokenAddress || "", account) const handleOpenCustomProposalModal = (key: ProposalAction) => { setProposalAction(key) @@ -171,10 +170,8 @@ export const ProposalActionsDialog: React.FC = ({ open, handleClose }) => - elem.id === "off-chain" && isMember + elem.id === "off-chain" ? handleLiteProposal() - : elem.id === "off-chain" && !isMember - ? null : !shouldDisable ? elem.isLambda ? handleOpenCustomProposalModal(elem.id) @@ -182,25 +179,11 @@ export const ProposalActionsDialog: React.FC = ({ open, handleClose }) => : null } > - + {elem.name} {elem.description}{" "} diff --git a/src/modules/explorer/pages/DAOList/index.tsx b/src/modules/explorer/pages/DAOList/index.tsx index cd9434c5..dc22baab 100644 --- a/src/modules/explorer/pages/DAOList/index.tsx +++ b/src/modules/explorer/pages/DAOList/index.tsx @@ -113,7 +113,7 @@ export const DAOList: React.FC = () => { }, allowPublicAccess: dao.dao_type.name === "lite" ? dao.allowPublicAccess : true })) - .sort((a, b) => b.votingAddresses.length - a.votingAddresses.length) + .sort((a, b) => b.votingAddressesCount - a.votingAddressesCount) if (searchText) { return formattedDAOs.filter( diff --git a/src/modules/lite/explorer/components/Choices.tsx b/src/modules/lite/explorer/components/Choices.tsx index 8a073525..4e1d12ce 100644 --- a/src/modules/lite/explorer/components/Choices.tsx +++ b/src/modules/lite/explorer/components/Choices.tsx @@ -18,8 +18,8 @@ import { FieldArray, Field } from "formik" import { TextField as FormikTextField } from "formik-material-ui" import { useDAOID } from "modules/explorer/pages/DAO/router" import { useDAO } from "services/services/dao/hooks/useDAO" -import { useToken } from "../hooks/useToken" import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight" +import { useCommunity } from "../hooks/useCommunity" const ChoicesContainer = styled(Grid)(({ theme }) => ({ paddingBottom: 19, @@ -91,9 +91,9 @@ export const Choices: React.FC = ({ choices, submitForm, isLoading, votingS const daoId = useDAOID() const { data } = useDAO(daoId) - const liteDAOId = data?.liteDAOData?._id ? data?.liteDAOData?._id : id - const tokenAddress = useToken(liteDAOId) - const { data: userTokenVoteWeight } = useTokenVoteWeight(tokenAddress) + const community = useCommunity(id) + + const { data: userTokenVoteWeight } = useTokenVoteWeight(data?.data?.token?.contract || community?.tokenAddress) const canCreateProposal = userTokenVoteWeight && userTokenVoteWeight.gt(0) ? true : false return ( @@ -193,7 +193,7 @@ export const Choices: React.FC = ({ choices, submitForm, isLoading, votingS {!isLoading ? ( - Create Proposal + {canCreateProposal ? "Create Proposal" : "No Voting Weight"} ) : ( diff --git a/src/modules/lite/explorer/components/DaoCardDetail.tsx b/src/modules/lite/explorer/components/DaoCardDetail.tsx index 19b8b7dc..37f9a6f8 100644 --- a/src/modules/lite/explorer/components/DaoCardDetail.tsx +++ b/src/modules/lite/explorer/components/DaoCardDetail.tsx @@ -4,9 +4,9 @@ import React, { useCallback, useContext, useEffect, useState } from "react" import { useHistory } from "react-router" import { useTezos } from "services/beacon/hooks/useTezos" import { DashboardContext } from "../context/ActionSheets/explorer" -import { useHoldersTotalCount } from "../hooks/useHolderTotalCount" import { updateCount } from "services/services/lite/lite-services" import { useIsMember } from "../hooks/useIsMember" +import { useHoldersTotalCount } from "../hooks/useHolderTotalCount" const StyledAvatar = styled(Avatar)({ height: 159, @@ -58,34 +58,31 @@ export const DaoCardDetail: React.FC = ({ community, setIsUp const { network, account } = useTezos() const theme = useTheme() const { isConnected } = useContext(DashboardContext) - const count = useHoldersTotalCount(network, community?.tokenAddress || "") const isMember = useIsMember(network, community?.tokenAddress || "", account) + const count = useHoldersTotalCount( + network, + community?.tokenAddress || "", + community?.tokenID ? Number(community?.tokenID) : 0 + ) - const updateCommunityCount = useCallback( - async (count: number) => { - if (community) { - try { - const resp = await updateCount(community._id, count) - const respData = await resp.json() + const updateCommunityCount = useCallback(async () => { + if (community) { + try { + const resp = await updateCount(community._id) + const respData = await resp.json() - if (!resp.ok) { - console.log(respData.message) - } - } catch (error) { - console.log("Error: ", error) + if (!resp.ok) { + console.log(respData.message) } + } catch (error) { + console.log("Error: ", error) } - }, - [community] - ) + } + }, [community]) useEffect(() => { - updateCommunityCount(count) - }, [count, updateCommunityCount]) - - const shouldBeDisabled = () => { - return community?.requiredTokenOwnership && isMember ? false : true - } + updateCommunityCount() + }, [updateCommunityCount]) return ( @@ -110,7 +107,6 @@ export const DaoCardDetail: React.FC = ({ community, setIsUp {isConnected ? ( { +export const useHoldersTotalCount = (network: Network, tokenAddress: string, tokenID: number) => { const [count, setCount] = useState(0) const openNotification = useNotification() @@ -12,36 +13,15 @@ export const useHoldersTotalCount = (network: Network, tokenAddress: string) => async function fetchTotalCount() { try { if (tokenAddress !== "") { - const url = `https://api.${networkNameMap[network]}.tzkt.io/v1/tokens/balances/?token.contract=${tokenAddress}` - await fetch(url).then(async response => { - if (!response.ok) { - openNotification({ - message: "An error has occurred", - autoHideDuration: 2000, - variant: "error" - }) - return - } - - const record: any[] = await response.json() - - const nonZeroBalance = record.filter((item: any) => item.balance !== "0") - if (!record) { - return - } - - setCount(nonZeroBalance.length) - return - }) + const holdersCount = await getTokenHoldersCount(network, tokenAddress, tokenID) + setCount(holdersCount) } - return } catch (error) { openNotification({ message: "An error has occurred", autoHideDuration: 2000, variant: "error" }) - return } } fetchTotalCount() diff --git a/src/modules/lite/explorer/hooks/usePolls.tsx b/src/modules/lite/explorer/hooks/usePolls.tsx index ee5ecc49..2b9efcab 100644 --- a/src/modules/lite/explorer/hooks/usePolls.tsx +++ b/src/modules/lite/explorer/hooks/usePolls.tsx @@ -30,12 +30,12 @@ export const usePolls = (id: any) => { return } - // @TODO Add functinolity if needed for card in proposal list - // communityPolls.map(community => { - // community.timeFormatted = isProposalActive(Number(community.endTime)) - // community.isActive = !community.timeFormatted.includes("ago") ? ProposalStatus.ACTIVE : ProposalStatus.CLOSED - // }) + communityPolls.map(community => { + community.timeFormatted = isProposalActive(Number(community.endTime)) + community.isActive = !community.timeFormatted.includes("ago") ? ProposalStatus.ACTIVE : ProposalStatus.CLOSED + }) + // @TODO Add functinolity if needed for card in proposal list // communityPolls.forEach(async poll => { // if (poll) { // await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/choices/${poll._id}/votes`).then(async response => { diff --git a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx index af96a785..19a37100 100644 --- a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx +++ b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx @@ -62,7 +62,10 @@ 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, poll?.referenceBlock) + const { data: voteWeight } = useTokenVoteWeight( + dao?.data.token.contract || community?.tokenAddress, + poll?.referenceBlock + ) const [selectedVotes, setSelectedVotes] = useState([]) useEffect(() => { @@ -165,7 +168,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => { color="secondary" onClick={() => saveVote()} > - Cast your vote + {voteWeight?.gt(new BigNumber(0)) ? "Cast your vote" : "No Voting Weight"} ) : null} diff --git a/src/services/services/lite/lite-services.ts b/src/services/services/lite/lite-services.ts index 07f0105d..852452d6 100644 --- a/src/services/services/lite/lite-services.ts +++ b/src/services/services/lite/lite-services.ts @@ -131,21 +131,6 @@ export const saveLiteCommunity = async (signature: string, publicKey: string | u return resp } -export const joinLiteCommunity = async (signature: string, publicKey: string | undefined, payloadBytes: string) => { - const resp = await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/daos/join`, { - method: "POST", - body: JSON.stringify({ - signature, - publicKey, - payloadBytes - }), - headers: { - "Content-Type": "application/json" - } - }) - return resp -} - export const saveLiteProposal = async (signature: string, publicKey: string | undefined, payloadBytes: string) => { const resp = await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/poll/add`, { method: "POST", @@ -193,12 +178,9 @@ export const fetchLiteData = async (daoContract: string, network: Network) => { } } -export const updateCount = async (id: string, count: number) => { +export const updateCount = async (id: string) => { const resp = await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/daos/count/${id}`, { method: "POST", - body: JSON.stringify({ - count - }), headers: { "Content-Type": "application/json" }