From fc6656179601497a56c443cd5daacc0da3c2f9e0 Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Tue, 20 Jul 2021 09:35:45 +0200 Subject: [PATCH] Show community errors (#135) --- .../DApp/src/components/card/ProposeModal.tsx | 53 +++++++++++++------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/DApp/src/components/card/ProposeModal.tsx b/packages/DApp/src/components/card/ProposeModal.tsx index 3e021be..4329a0d 100644 --- a/packages/DApp/src/components/card/ProposeModal.tsx +++ b/packages/DApp/src/components/card/ProposeModal.tsx @@ -6,14 +6,13 @@ import { Input } from '../Input' import { VotePropose } from '../votes/VotePropose' import { Warning } from '../votes/VoteWarning' import { ConfirmBtn } from './VoteConfirmModal' -import { useContractFunction } from '@usedapp/core' +import { useContractCall, useContractFunction } from '@usedapp/core' import { useContracts } from '../../hooks/useContracts' import { CommunityDetail } from '../../models/community' import { CommunitySkeleton } from '../skeleton/CommunitySkeleton' import { useCommunityDetails } from '../../hooks/useCommunityDetails' import { ColumnFlexDiv } from '../../constants/styles' import { BigNumber } from 'ethers' -import { timespan } from '../../helpers/timespan' interface PublicKeyInputProps { publicKey: string @@ -50,15 +49,25 @@ export function ProposeModal({ }: ProposeModalProps) { const [proposingAmount, setProposingAmount] = useState(0) const [publicKey, setPublicKey] = useState('') + const [communityInDirectory, setCommunityInDirectory] = useState(false) + const [communityUnderVote, setCommunityUnderVote] = useState(false) const loading = useCommunityDetails(publicKey, setCommunityFound) - const { votingContract } = useContracts() + const { votingContract, directoryContract } = useContracts() const { send, state } = useContractFunction(votingContract, 'initializeVotingRoom') - const lastVote = - communityFound && communityFound.votingHistory - ? communityFound.votingHistory[communityFound.votingHistory.length - 1] - : undefined - const lastVoteDate = lastVote ? lastVote.date : undefined + const [isCommunityInDirectory] = useContractCall({ + abi: directoryContract.interface, + address: directoryContract.address, + method: 'isCommunityInDirectory', + args: [publicKey], + }) ?? [undefined] + + const [isCommunityUnderVote] = useContractCall({ + abi: votingContract.interface, + address: votingContract.address, + method: 'communityVotingId', + args: [publicKey], + }) ?? [undefined] useEffect(() => { if (state.status === 'Mining') { @@ -66,12 +75,28 @@ export function ProposeModal({ } }, [state]) + useEffect(() => { + if (isCommunityInDirectory) { + setCommunityInDirectory(true) + } else { + setCommunityInDirectory(false) + } + }, [isCommunityInDirectory]) + + useEffect(() => { + if (isCommunityUnderVote && isCommunityUnderVote.toNumber() > 0) { + setCommunityUnderVote(true) + } else { + setCommunityUnderVote(false) + } + }, [isCommunityUnderVote?.toNumber()]) + return ( {communityFound ? : loading && publicKey && } - {communityFound && !communityFound.validForAddition && ( + {communityFound && ( {communityFound.numberOfMembers < 42 && ( )} - {communityFound.directoryInfo && ( + {communityInDirectory && ( )} - {communityFound.currentVoting && ( - - )} - {lastVoteDate && timespan(lastVoteDate) < 30 && ( + {communityUnderVote && (