Skip to content

Commit

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

import { Registration, RegistrationStatus, listsClient } from "@/common/contracts/core";
import { Registration, RegistrationStatus, listsContractClient } from "@/common/contracts/core";

const UNREGISTERED_PROJECT = {
id: "",
Expand Down Expand Up @@ -29,7 +29,7 @@ export const useRegistration = (projectId: string) => {
try {
if (projectId) {
const registration =
(await listsClient.getRegistration({
(await listsContractClient.getRegistration({
registrant_id: projectId,
})) || UNREGISTERED_PROJECT;

Expand Down
4 changes: 2 additions & 2 deletions src/common/contracts/core/campaigns/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as campaignsClient from "./client";
import * as campaignsContractClient from "./client";

export * from "./interfaces";

export { campaignsClient };
export { campaignsContractClient };
4 changes: 2 additions & 2 deletions src/common/contracts/core/donation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as donationClient from "./client";
import * as donationContractClient from "./client";

export * from "./interfaces";

export { donationClient };
export { donationContractClient };
4 changes: 2 additions & 2 deletions src/common/contracts/core/lists/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as listsClient from "./client";
import * as listsContractClient from "./client";

export * from "./interfaces";

export { listsClient };
export { listsContractClient };
4 changes: 2 additions & 2 deletions src/common/contracts/core/pot-factory/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as potFactoryClient from "./client";
import * as potFactoryContractClient from "./client";

export * from "./interfaces";

export { potFactoryClient };
export { potFactoryContractClient };
4 changes: 2 additions & 2 deletions src/common/contracts/core/pot/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as potClient from "./client";
import * as potContractClient from "./client";

export * from "./interfaces";

export { potClient };
export { potContractClient };
29 changes: 17 additions & 12 deletions src/common/contracts/core/voting/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@ import type { ByPotId } from "@/common/api/indexer";
import { ByAccountId, type ConditionalExecution } from "@/common/types";

import { AccountId, ElectionId } from "./interfaces";
import { votingClient } from "./singleton.client";
import { votingContractClient } from "./singleton.client";

export interface ByElectionId {
electionId: ElectionId;
}

type BasicElectionQueryKey = ByElectionId & ConditionalExecution;

export const useElections = () => useSWR(["get_elections"], () => votingClient.get_elections({}));
export const useElections = () =>
useSWR(["get_elections"], () => votingContractClient.get_elections({}));

export const useActiveElections = () =>
useSWR(["get_active_elections"], () => votingClient.get_active_elections());
useSWR(["get_active_elections"], () => votingContractClient.get_active_elections());

export const useElection = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(
["get_election", electionId],

([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_election({ election_id }),
!enabled ? undefined : votingContractClient.get_election({ election_id }),
);

export const useIsVotingPeriod = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(
["is_voting_period", electionId],

([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.is_voting_period({ election_id }),
!enabled ? undefined : votingContractClient.is_voting_period({ election_id }),
);

export const useElectionCandidates = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(
["get_election_candidates", electionId],

([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_election_candidates({ election_id }),
!enabled ? undefined : votingContractClient.get_election_candidates({ election_id }),
);

export const useElectionCandidateVotes = ({
Expand All @@ -50,20 +51,22 @@ export const useElectionCandidateVotes = ({
["get_candidate_votes", electionId, accountId],

([_queryKey, election_id, candidate_id]: [string, ElectionId, AccountId]) =>
!enabled ? undefined : votingClient.get_candidate_votes({ election_id, candidate_id }),
!enabled
? undefined
: votingContractClient.get_candidate_votes({ election_id, candidate_id }),
);

export const useElectionVotes = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(["get_election_votes", electionId], ([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_election_votes({ election_id }),
!enabled ? undefined : votingContractClient.get_election_votes({ election_id }),
);

export const useElectionVoteCount = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(
["get_election_vote_count", electionId],

([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_election_vote_count({ election_id }),
!enabled ? undefined : votingContractClient.get_election_vote_count({ election_id }),
);

export const useVotingRoundVoterVotes = ({
Expand All @@ -75,7 +78,7 @@ export const useVotingRoundVoterVotes = ({
["get_voter_votes", electionId, accountId],

([_queryKey, election_id, voter]: [string, ElectionId, AccountId]) =>
!enabled ? undefined : votingClient.get_voter_votes({ election_id, voter }),
!enabled ? undefined : votingContractClient.get_voter_votes({ election_id, voter }),
);

export const useVoterRemainingCapacity = ({
Expand All @@ -87,12 +90,14 @@ export const useVoterRemainingCapacity = ({
["get_voter_remaining_capacity", electionId, accountId],

([_queryKey, election_id, voter]: [string, ElectionId, AccountId]) =>
!enabled ? undefined : votingClient.get_voter_remaining_capacity({ election_id, voter }),
!enabled
? undefined
: votingContractClient.get_voter_remaining_capacity({ election_id, voter }),
);

export const useUniqueVoters = ({ electionId, enabled = true }: BasicElectionQueryKey) =>
useSWR(["get_unique_voters", electionId], ([_queryKey, election_id]: [string, ElectionId]) =>
!enabled ? undefined : votingClient.get_unique_voters({ election_id }),
!enabled ? undefined : votingContractClient.get_unique_voters({ election_id }),
);

export const usePotElections = ({ potId }: ByPotId) => {
Expand Down
6 changes: 3 additions & 3 deletions src/common/contracts/core/voting/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as votingHooks from "./hooks";
import * as votingContractHooks from "./hooks";

export type * from "./hooks";
export * from "./interfaces";
export { votingClient } from "./singleton.client";
export { votingContractClient } from "./singleton.client";

export { votingHooks };
export { votingContractHooks };
2 changes: 1 addition & 1 deletion src/common/contracts/core/voting/singleton.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { VOTING_CONTRACT_ACCOUNT_ID } from "@/common/_config";

import { createVotingClient } from "./client";

export const votingClient = createVotingClient(VOTING_CONTRACT_ACCOUNT_ID);
export const votingContractClient = createVotingClient(VOTING_CONTRACT_ACCOUNT_ID);
4 changes: 2 additions & 2 deletions src/entities/campaign/components/SingleCampaignBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from "next/router";
import { LazyLoadImage } from "react-lazy-load-image-component";

import { useNearToUsdWithFallback } from "@/common/_deprecated/useNearToUsdWithFallback";
import { Campaign, campaignsClient } from "@/common/contracts/core";
import { Campaign, campaignsContractClient } from "@/common/contracts/core";
import { yoctoNearToFloat } from "@/common/lib";
import getTimePassed from "@/common/lib/getTimePassed";
import { SocialsShare } from "@/common/ui/components/molecules/social-share";
Expand All @@ -30,7 +30,7 @@ export const SingleCampaignBanner = () => {
if (!campaignId) return;
setLoading(true);

campaignsClient
campaignsContractClient
.get_campaign({ campaign_id: parseInt(campaignId as string) as any })
.then((response) => {
setCampaign(response);
Expand Down
16 changes: 8 additions & 8 deletions src/entities/campaign/hooks/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Temporal } from "temporal-polyfill";
import { infer as FromSchema, ZodError } from "zod";

import { walletApi } from "@/common/api/near/client";
import { campaignsClient } from "@/common/contracts/core";
import { campaignsContractClient } from "@/common/contracts/core";
import { floatToYoctoNear, useRouteQuery } from "@/common/lib";
import { dispatch } from "@/store";

Expand Down Expand Up @@ -34,7 +34,7 @@ export const useCampaignForm = () => {

const handleDeleteCampaign = () => {
if (!campaignId) return;
campaignsClient.delete_campaign({ args: { campaign_id: Number(campaignId) } });
campaignsContractClient.delete_campaign({ args: { campaign_id: Number(campaignId) } });

dispatch.campaignEditor.updateCampaignModalState({
header: `Campaign Deleted Successfully`,
Expand Down Expand Up @@ -71,23 +71,23 @@ export const useCampaignForm = () => {
};

if (campaignId) {
campaignsClient.update_campaign({
campaignsContractClient.update_campaign({
args: { campaign_id: Number(campaignId), ...args },
});

dispatch.campaignEditor.updateCampaignModalState({
header: `You’ve successfully created a campaignsClient for ${values.name}.`,
header: `You’ve successfully created a campaignsContractClient for ${values.name}.`,
description:
"If you are not a member of the project, the campaignsClient will be considered unofficial until it has been approved by the project.",
"If you are not a member of the project, the campaignsContractClient will be considered unofficial until it has been approved by the project.",
type: CampaignEnumType.UPDATE_CAMPAIGN,
});
} else {
campaignsClient.create_campaign({ args });
campaignsContractClient.create_campaign({ args });

dispatch.campaignEditor.updateCampaignModalState({
header: `You’ve successfully created a campaignsClient for ${values.name}.`,
header: `You’ve successfully created a campaignsContractClient for ${values.name}.`,
description:
"If you are not a member of the project, the campaignsClient will be considered unofficial until it has been approved by the project.",
"If you are not a member of the project, the campaignsContractClient will be considered unofficial until it has been approved by the project.",
type: CampaignEnumType.CREATE_CAMPAIGN,
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/entities/campaign/hooks/useCampaign.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useEffect, useState } from "react";

import { Campaign, CampaignDonation, campaignsClient } from "@/common/contracts/core";
import { Campaign, CampaignDonation, campaignsContractClient } from "@/common/contracts/core";

export const useCampaign = ({ campaignId }: { campaignId: string }) => {
const [campaign, setCampaign] = useState<Campaign>();
const [donations, setDonations] = useState<CampaignDonation[]>([]);

useEffect(() => {
campaignsClient
campaignsContractClient
.get_campaign({ campaign_id: parseInt(campaignId as string) as any })
.then((response) => {
setCampaign(response);
Expand All @@ -16,7 +16,7 @@ export const useCampaign = ({ campaignId }: { campaignId: string }) => {
}, [campaignId]);

useEffect(() => {
campaignsClient
campaignsContractClient
.get_donations_for_campaign({
campaign_id: parseInt(campaignId as string) as any,
limit: 999,
Expand Down
4 changes: 2 additions & 2 deletions src/entities/list/components/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LazyLoadImage } from "react-lazy-load-image-component";

import { ListRegistration } from "@/common/api/indexer";
import { walletApi } from "@/common/api/near/client";
import { RegistrationStatus, listsClient } from "@/common/contracts/core";
import { RegistrationStatus, listsContractClient } from "@/common/contracts/core";
import { truncate } from "@/common/lib";
import {
Button,
Expand Down Expand Up @@ -88,7 +88,7 @@ export const AccountCard = ({
);

const handleUpdateStatus = () => {
listsClient
listsContractClient
.update_registered_project({
registration_id: dataForList.id,
...(note && { notes: note }),
Expand Down
6 changes: 3 additions & 3 deletions src/entities/list/components/ListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FaHeart } from "react-icons/fa";
import { LazyLoadImage } from "react-lazy-load-image-component";

import { walletApi } from "@/common/api/near/client";
import { listsClient } from "@/common/contracts/core";
import { listsContractClient } from "@/common/contracts/core";
import { truncate } from "@/common/lib";
import { fetchSocialImages } from "@/common/services/social";
import { LayersIcon } from "@/common/ui/svg";
Expand Down Expand Up @@ -50,14 +50,14 @@ export const ListCard = ({
e.stopPropagation();

if (isUpvoted) {
listsClient.remove_upvote({ list_id: dataForList?.on_chain_id });
listsContractClient.remove_upvote({ list_id: dataForList?.on_chain_id });

dispatch.listEditor.handleListToast({
name: truncate(dataForList?.name, 15),
type: ListFormModalType.DOWNVOTE,
});
} else {
listsClient.upvote({ list_id: dataForList?.on_chain_id });
listsContractClient.upvote({ list_id: dataForList?.on_chain_id });

dispatch.listEditor.handleListToast({
name: truncate(dataForList?.name, 15),
Expand Down
8 changes: 4 additions & 4 deletions src/entities/list/components/ListDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { prop } from "remeda";

import { List } from "@/common/api/indexer";
import { walletApi } from "@/common/api/near/client";
import { listsClient } from "@/common/contracts/core";
import { listsContractClient } from "@/common/contracts/core";
import { truncate } from "@/common/lib";
import { fetchSocialImages } from "@/common/services/social";
import {
Expand Down Expand Up @@ -84,7 +84,7 @@ export const ListDetails = ({ admins, listDetails, savedUsers }: ListDetailsType
} = useListForm();

const applyToListModal = (note: string) => {
listsClient
listsContractClient
.register_batch({
list_id: parseInt(listDetails?.on_chain_id as any) as any,
notes: note,
Expand Down Expand Up @@ -125,7 +125,7 @@ export const ListDetails = ({ admins, listDetails, savedUsers }: ListDetailsType

const handleUpvote = () => {
if (isUpvoted) {
listsClient
listsContractClient
.remove_upvote({ list_id: Number(listDetails.on_chain_id) })
.catch((error) => console.error("Error upvoting:", error));

Expand All @@ -134,7 +134,7 @@ export const ListDetails = ({ admins, listDetails, savedUsers }: ListDetailsType
type: ListFormModalType.DOWNVOTE,
});
} else {
listsClient
listsContractClient
.upvote({ list_id: Number(listDetails.on_chain_id) })
.catch((error) => console.error("Error upvoting:", error));

Expand Down
8 changes: 4 additions & 4 deletions src/entities/list/components/ListFormDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SubmitHandler, useForm } from "react-hook-form";

import { walletApi } from "@/common/api/near/client";
import { IPFS_NEAR_SOCIAL_URL } from "@/common/constants";
import { RegistrationStatus, listsClient } from "@/common/contracts/core";
import { RegistrationStatus, listsContractClient } from "@/common/contracts/core";
import uploadFileToIPFS from "@/common/services/ipfs";
import { fetchSocialImages } from "@/common/services/social";
import { AccountId } from "@/common/types";
Expand Down Expand Up @@ -93,7 +93,7 @@ export const ListFormDetails: React.FC = () => {
useEffect(() => {
const fetchListDetails = async () => {
try {
const response: any = await listsClient.getList({
const response: any = await listsContractClient.getList({
list_id: parseInt(id as string) as any,
});

Expand Down Expand Up @@ -136,7 +136,7 @@ export const ListFormDetails: React.FC = () => {
) { return; }

if (onEditPage) {
listsClient.update_list({
listsContractClient.update_list({
...data,
admins,
list_id: parseInt(id as any),
Expand All @@ -155,7 +155,7 @@ export const ListFormDetails: React.FC = () => {

dispatch.listEditor.reset()
} else {
listsClient.create_list({
listsContractClient.create_list({
...data,
admins,
accounts: accounts.map((account) => ({
Expand Down
Loading

0 comments on commit efe3d70

Please sign in to comment.