utils#VotingMachineProposalState TypeScript Examples

The following examples show how to use utils#VotingMachineProposalState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StatusSearch.tsx    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
StatusSearch = ({ value, onFilter }) => {
  return (
    <ProposalsFilter
      name="stateFilter"
      id="stateSelector"
      value={value}
      onChange={e => onFilter(e.target.value)}
    >
      <option value="Any Status">Any Status</option>
      {enumKeys(VotingMachineProposalState).map(
        i =>
          i !== 'None' && (
            <option key={i} value={VotingMachineProposalState[i]}>
              {i}
            </option>
          )
      )}
    </ProposalsFilter>
  );
}
Example #2
Source File: useFilteredProposals.ts    From dxvote with GNU Affero General Public License v3.0 6 votes vote down vote up
matchStatus = (proposal: ProposalsExtended, status: string) => {
  if (status === 'Any Status' || !status) {
    return proposal;
  }
  // status is rejected
  if (status === '7') {
    return proposal.stateInScheme === WalletSchemeProposalState.Rejected;
  }
  // status is passed
  if (status === '8') {
    return (
      proposal.stateInScheme === WalletSchemeProposalState.Submitted &&
      proposal.stateInVotingMachine === VotingMachineProposalState.Executed
    );
  }
  return proposal.stateInVotingMachine === parseInt(status);
}
Example #3
Source File: index.tsx    From dxvote with GNU Affero General Public License v3.0 5 votes vote down vote up
Details = () => {
  const {
    context: { daoStore },
  } = useContext();

  const proposalId = useLocation().pathname.split('/')[3];
  const proposal = daoStore.getProposal(proposalId);

  const scheme = daoStore.getScheme(proposal.scheme);

  const boostedVoteRequiredPercentage =
    scheme.boostedVoteRequiredPercentage / 100;

  const { boostTime, finishTime } = daoStore.getProposalStatus(proposalId);

  return (
    <SpaceAroundRow>
      <ProposalDescription>
        <Detail>
          <strong>Proposer</strong>
          <small>
            <BlockchainLink type="user" text={proposal.proposer} toCopy />
          </small>
        </Detail>
        <Detail>
          <strong>Scheme</strong> <small>{scheme.name}</small>
        </Detail>
        <Detail>
          <strong>Voting Parameters</strong>{' '}
          <small>{proposal.paramsHash.substring(0, 10)}...</small>
        </Detail>
        <Detail>
          <strong>State in Voting Machine </strong>
          <small>
            {VotingMachineProposalState[proposal.stateInVotingMachine]}
          </small>
        </Detail>
        <Detail>
          <strong>State in Scheme </strong>
          <small>{WalletSchemeProposalState[proposal.stateInScheme]}</small>
        </Detail>
        <Detail>
          <strong>Submitted Date</strong>
          <small>
            {moment
              .unix(proposal.submittedTime.toNumber())
              .format('MMMM Do YYYY, HH:mm:ss')}
          </small>
        </Detail>
        <Detail>
          <strong>Boost Date</strong>
          <small>
            {boostTime.toNumber() > 0
              ? moment
                  .unix(boostTime.toNumber())
                  .format('MMMM Do YYYY, HH:mm:ss')
              : '-'}
          </small>
        </Detail>
        <Detail>
          <strong>Finish Date</strong>
          <small>
            {moment
              .unix(finishTime.toNumber())
              .format('MMMM Do YYYY, HH:mm:ss')}
          </small>
        </Detail>

        {boostedVoteRequiredPercentage > 0 && (
          <Detail>
            <strong> Required Boosted Vote: </strong>
            <small>{boostedVoteRequiredPercentage}%</small>
          </Detail>
        )}
      </ProposalDescription>
    </SpaceAroundRow>
  );
}
Example #4
Source File: useFilterCriteria.ts    From dxvote with GNU Affero General Public License v3.0 4 votes vote down vote up
useFilterCriteria = (): useFilterCriteriaReturns => {
  const {
    context: { daoStore },
  } = useContext();

  const { getRep } = useRep(ZERO_ADDRESS);

  const [filteredProposals, setFilteredProposals] = useState<
    ProposalsExtended[]
  >([]);

  const [loading, setLoading] = useState(true);
  const timeNow = bnum(moment().unix());

  useEffect(() => {
    const allProposals = daoStore.getAllProposals();

    // Queded && positiveVotes >= 10% (Ordered from time to finish, from lower to higher)
    const stateEarliestAbove10 = allProposals
      .filter(proposal => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;

        const repAtCreation = getRep(
          proposal.creationEvent.blockNumber
        ).totalSupply;

        return (
          proposal.stateInVotingMachine === VotingMachineProposalState.Queued &&
          timeNow.lt(proposal.submittedTime.plus(queuedVotePeriodLimit)) &&
          proposal.positiveVotes
            .div(repAtCreation)
            .times(100)
            .decimalPlaces(2)
            .gte(QUEUED_PRIORITY_THRESHOLD)
        );
      })
      .sort(orderByNewestTimeToFinish);

    // Proposals Boosted. (Ordered from time to finish, from lower to higher)
    const stateBoosted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine === VotingMachineProposalState.Boosted
      )
      .sort(orderByNewestTimeToFinish);

    const stateQuiteEndingProposals = allProposals
      .filter(proposal => {
        return (
          proposal.stateInVotingMachine ===
          VotingMachineProposalState.QuietEndingPeriod
        );
      })
      .sort(orderByNewestTimeToFinish);

    const statePreBoosted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine ===
          VotingMachineProposalState.PreBoosted
      )
      .sort(orderByNewestTimeToFinish);

    // Queded && positiveVotes < 10% (Ordered from time to finish, from lower to higher)
    const stateEarliestUnder10 = allProposals
      .filter((proposal): Boolean => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;

        const repAtCreation = getRep(
          proposal.creationEvent.blockNumber
        ).totalSupply;

        return (
          proposal.stateInVotingMachine === VotingMachineProposalState.Queued &&
          timeNow.lt(proposal.submittedTime.plus(queuedVotePeriodLimit)) &&
          proposal.positiveVotes
            .div(repAtCreation)
            .times(100)
            .decimalPlaces(2)
            .lt(QUEUED_PRIORITY_THRESHOLD)
        );
      })
      .sort(orderByNewestTimeToFinish);

    //Proposals in Executed status. (Ordered in time passed since finish, from higher to lower)
    const stateExecuted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine === VotingMachineProposalState.Executed
      )
      .sort(orderByOldestTimeToFinish);

    //Proposals finished status. (Expired in queue, rejected or passed)
    const stateFinished = allProposals
      .filter((proposal): Boolean => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;
        return (
          (proposal.stateInVotingMachine ===
            VotingMachineProposalState.Queued &&
            timeNow.gt(proposal.submittedTime.plus(queuedVotePeriodLimit))) ||
          proposal.stateInVotingMachine ===
            VotingMachineProposalState.ExpiredInQueue ||
          proposal.stateInVotingMachine ===
            VotingMachineProposalState.Rejected ||
          proposal.stateInVotingMachine === VotingMachineProposalState.Passed
        );
      })
      .sort(orderByOldestTimeToFinish);

    setFilteredProposals([
      ...stateBoosted,
      ...statePreBoosted,
      ...stateQuiteEndingProposals,
      ...stateEarliestAbove10,
      ...stateEarliestUnder10,
      ...stateExecuted,
      ...stateFinished,
    ]);

    setLoading(false);
  }, []);

  return {
    proposals: filteredProposals,
    loading,
  };
}