diff --git a/src/modules/explorer/pages/DAOList/index.tsx b/src/modules/explorer/pages/DAOList/index.tsx index 3eecc5f3..f710cf4e 100644 --- a/src/modules/explorer/pages/DAOList/index.tsx +++ b/src/modules/explorer/pages/DAOList/index.tsx @@ -139,7 +139,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 be0b7582..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 ( 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/pages/ProposalDetails/index.tsx b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx index 60fbb9e9..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(() => { 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" }