Skip to content

Commit

Permalink
Fix payout estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Dec 29, 2024
1 parent 8a53088 commit 10c9033
Show file tree
Hide file tree
Showing 95 changed files with 486 additions and 480 deletions.
4 changes: 2 additions & 2 deletions src/common/_deprecated/useIsHuman.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";

import { getIsHuman } from "@/common/contracts/core/sybil";
import { is_human } from "@/common/contracts/core/sybil";

export const useIsHuman = (accountId?: string) => {
const [isHumanVerified, setNadaBotVerified] = useState(false);
Expand All @@ -10,7 +10,7 @@ export const useIsHuman = (accountId?: string) => {
useEffect(() => {
const fetchHumanStatus = async () => {
try {
const isHuman = await getIsHuman({ account_id: accountId || "" });
const isHuman = await is_human({ account_id: accountId || "" });
setNadaBotVerified(isHuman);
setLoading(false);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/contracts/core/sybil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const getHumanScore = (args: GetHumanScoreInput) =>
* Get if address is human
* @returns
*/
export const getIsHuman = (args: GetHumanScoreInput): Promise<boolean> =>
export const is_human = (args: GetHumanScoreInput): Promise<boolean> =>
contractApi.view<typeof args, boolean>("is_human", {
args,
});
Expand Down
28 changes: 26 additions & 2 deletions src/common/contracts/core/voting/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useSWR from "swr";

import { UNKNOWN_ACCOUNT_ID_PLACEHOLDER } from "@/common/constants";
import type { ByPotId } from "@/common/api/indexer";
import { ByAccountId, type ConditionalExecution } from "@/common/types";

import { AccountId, ElectionId } from "./interfaces";
Expand Down Expand Up @@ -66,7 +66,7 @@ export const useElectionVoteCount = ({ electionId, enabled = true }: BasicElecti
!enabled ? undefined : votingClient.get_election_vote_count({ election_id }),
);

export const useVoterVotes = ({
export const useVotingRoundVoterVotes = ({
electionId,
accountId,
enabled = true,
Expand Down Expand Up @@ -94,3 +94,27 @@ export const useUniqueVoters = ({ electionId, enabled = true }: BasicElectionQue
useSWR(["get_unique_voters", electionId], ([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_unique_voters({ election_id }),
);

export const usePotElections = ({ potId }: ByPotId) => {
const { data: elections, isLoading } = useElections();

return {
isLoading,

elections: elections?.filter(
({ election_type }) =>
typeof election_type === "object" && "Pot" in election_type && election_type.Pot === potId,
),
};
};

export const useActivePotElections = ({ potId }: ByPotId) => {
const { data: activeElections } = useActiveElections();

return {
activeElections: activeElections?.filter(
([_electionId, { election_type }]) =>
typeof election_type === "object" && "Pot" in election_type && election_type.Pot === potId,
),
};
};
4 changes: 4 additions & 0 deletions src/common/lib/numeric.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Big, BigSource } from "big.js";
import { number, preprocess } from "zod";

export type NumericComparatorKey = keyof Big.Big & ("lt" | "lte" | "gt" | "gte");

export const NUMERIC_COMPARATOR_KEYS: NumericComparatorKey[] = ["lt", "lte", "gt", "gte"];

export const isBigSource = (value: unknown | BigSource) => {
try {
/** Attempt to create a new Big instance */
Expand Down
1 change: 1 addition & 0 deletions src/entities/dao/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./utils/validation";
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Policy = {
bounty_forgiveness_period: string;
};

export function doesUserHaveDaoFunctionCallProposalPermissions(accountId: string, policy: Policy) {
function doesUserHaveDaoFunctionCallProposalPermissions(accountId: string, policy: Policy) {
const userRoles = policy.roles.filter((role: any) => {
if (role.kind === "Everyone") return true;
return role.kind.Group && role.kind.Group.includes(accountId);
Expand All @@ -46,7 +46,7 @@ export function doesUserHaveDaoFunctionCallProposalPermissions(accountId: string
return allowed;
}

export const checkIfDaoAddress = (address: string): boolean => {
const checkIfDaoAddress = (address: string): boolean => {
return address.endsWith(
process.env.NEXT_PUBLIC_NETWORK ? "sputnik-dao.near" : "sputnik-dao.testnet", // TODO: not sure about this one
);
Expand Down
26 changes: 0 additions & 26 deletions src/entities/pot/hooks/elections.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useMemo } from "react";

import { ByPotId } from "@/common/api/indexer";
import { votingHooks } from "@/common/contracts/core/voting";

import { usePotElections } from "./elections";

export const usePotExtensionFlags = ({ potId }: ByPotId) => {
const { isLoading: isPotExtensionConfigLoading, elections } = usePotElections({ potId });
export const usePotFeatureFlags = ({ potId }: ByPotId) => {
const { isLoading: isPotExtensionConfigLoading, elections } = votingHooks.usePotElections({
potId,
});

return useMemo(
() => ({ isPotExtensionConfigLoading, hasVoting: (elections?.length ?? 0) > 0 }),
Expand Down
4 changes: 2 additions & 2 deletions src/entities/pot/hooks/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Temporal } from "temporal-polyfill";
import { ByPotId, indexer } from "@/common/api/indexer";
import daysUntil from "@/common/lib/daysUntil";

import { usePotExtensionFlags } from "./extensions";
import { usePotFeatureFlags } from "./feature-flags";

export const usePotTags = ({ potId }: ByPotId) => {
const { data: pot } = indexer.usePot({ potId });
const { hasVoting } = usePotExtensionFlags({ potId });
const { hasVoting } = usePotFeatureFlags({ potId });

return useMemo(() => {
if (pot) {
Expand Down
3 changes: 1 addition & 2 deletions src/entities/pot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export * from "./components/PotTimeline";
export * from "./components/PotDonationStats";
export * from "./constants";
export { type PotInputs, potSchema } from "./models/schemas";
export * from "./hooks/elections";
export * from "./hooks/extensions";
export * from "./hooks/feature-flags";
export * from "./hooks/lifecycle";
export * from "./hooks/permissions";
export * from "./hooks/useOrderedDonations";
Expand Down
26 changes: 0 additions & 26 deletions src/entities/profile/components/SmartContract.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/entities/profile/constants.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/entities/profile/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/entities/profile/utils/convertURLtoGithubURL.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/entities/profile/utils/getProfileGithubRepositories.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/entities/profile/utils/getProfileTeamMembersData.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/entities/profile/utils/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ import type { AccountId } from "@/common/types";
import { useAccountSocialProfile } from "@/entities/_shared/account";
import routesPath from "@/pathnames";

import getProfileTeamMembersData from "../utils/getProfileTeamMembersData";
const getProfileTeamMembersData = (profileData?: NEARSocialUserProfile) => {
if (!profileData) return [];

const team = profileData.plTeam
? JSON.parse(profileData.plTeam)
: profileData.team
? Object.entries(profileData.team)
.filter(([_, v]) => v !== null)
.map(([k, _]) => k)
: [];

return team;
};

const NoTeam = () => <p className="m-0 flex w-full flex-col">No team members to display</p>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { useToast } from "@/common/ui/hooks";
import { cn } from "@/common/ui/utils";
import { useSession } from "@/entities/_shared/session";

import { VotingCandidateOption } from "./VotingCandidateOption";
import { VotingRoundCandidateListItem } from "./CandidateListItem";

export type VotingCandidateListProps = ByElectionId & {
export type VotingRoundCandidateListProps = ByElectionId & {
data: Candidate[];
onBulkVoteSuccess: () => void;
};

//? TODO: Use VirtualScroll for better performance
export const VotingCandidateList: React.FC<VotingCandidateListProps> = ({
export const VotingRoundCandidateList: React.FC<VotingRoundCandidateListProps> = ({
electionId,
data,
onBulkVoteSuccess,
Expand Down Expand Up @@ -107,7 +107,7 @@ export const VotingCandidateList: React.FC<VotingCandidateListProps> = ({
<ScrollArea style={{ height: (windowHeight ?? 820) - 320 }}>
<div className="flex flex-col gap-2 pb-8 pt-2">
{data.map((candidate) => (
<VotingCandidateOption
<VotingRoundCandidateListItem
key={candidate.account_id}
data={candidate}
isSelected={selectedEntries.has(candidate.account_id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ import { cn } from "@/common/ui/utils";
import { AccountListItem } from "@/entities/_shared/account";
import { useSession } from "@/entities/_shared/session";

import { useVotingCandidateEntry } from "../hooks/candidates";
import { useVotingRoundCandidateEntry } from "../hooks/candidates";

export type VotingCandidateOptionProps = ByElectionId & {
export type VotingRoundCandidateListItemProps = ByElectionId & {
data: Candidate;
isSelected?: boolean;
onSelect?: (accountId: string, isSelected: boolean) => void;
};

export const VotingCandidateOption: React.FC<VotingCandidateOptionProps> = ({
export const VotingRoundCandidateListItem: React.FC<VotingRoundCandidateListItemProps> = ({
electionId,
data: { account_id: accountId, votes_received: votesCount },
isSelected = false,
onSelect,
}) => {
const user = useSession();

const { isLoading, canReceiveVotes, hasUserVotes, handleVoteCast } = useVotingCandidateEntry({
electionId,
accountId,
});
const { isLoading, canReceiveVotes, hasUserVotes, handleVoteCast } = useVotingRoundCandidateEntry(
{
electionId,
accountId,
},
);

const unableToVoteError = useMemo(() => {
if (user.isSignedIn) {
Expand Down
Loading

0 comments on commit 10c9033

Please sign in to comment.