Skip to content

Commit

Permalink
Have a way show archived pools
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed Dec 18, 2024
1 parent 0c49706 commit 98d5055
Show file tree
Hide file tree
Showing 12 changed files with 1,155 additions and 1,174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Button,
DisplayNumber,
EthAddress,
InfoBox,
Statistic,
} from "@/components";
import CancelButton from "@/components/CancelButton";
Expand All @@ -39,7 +40,7 @@ import { useConvictionRead } from "@/hooks/useConvictionRead";
import { ConditionObject, useDisableButtons } from "@/hooks/useDisableButtons";
import { useMetadataIpfsFetch } from "@/hooks/useIpfsFetch";
import { useSubgraphQuery } from "@/hooks/useSubgraphQuery";
import { alloABI, safeABI } from "@/src/generated";
import { alloABI } from "@/src/generated";
import { PoolTypes, ProposalStatus } from "@/types";

import { useErrorDetails } from "@/utils/getErrorName";
Expand Down Expand Up @@ -257,13 +258,13 @@ export default function Page({
);
}

const handleRefreshConviction = async (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setConvictionRefreshing(true);
await triggerConvictionRefetch?.();
setConvictionRefreshing(false);
};
// const handleRefreshConviction = async (e: React.MouseEvent) => {
// e.preventDefault();
// e.stopPropagation();
// setConvictionRefreshing(true);
// await triggerConvictionRefetch?.();
// setConvictionRefreshing(false);
// };

const status = ProposalStatus[proposalData.proposalStatus];
return (
Expand Down Expand Up @@ -327,81 +328,91 @@ export default function Page({
</Statistic>
</div>
<div className="flex items-end">
{isProposerConnected && proposalStatus === "active" ?
<CancelButton
proposalData={{ ...proposalData, ...metadata }}
/>
: <DisputeButton
isMemberCommunity={isMemberCommunity}
proposalData={{ ...proposalData, ...metadata }}
/>
}
{proposalData.strategy.isEnabled &&
(isProposerConnected && proposalStatus === "active" ?
<CancelButton
proposalData={{ ...proposalData, ...metadata }}
/>
: <DisputeButton
isMemberCommunity={isMemberCommunity}
proposalData={{ ...proposalData, ...metadata }}
/>)}
</div>
</div>
</div>
</div>
{!proposalData.strategy.isEnabled && (
<InfoBox infoBoxType="warning">
The pool is not enabled.
</InfoBox>
)}
</header>
<section className="section-layout">
{status && status !== "active" && status !== "disputed" ?
<h4
className={`text-center ${status === "executed" ? "text-primary-content" : "text-error-content"}`}
>
{status === "executed" ?
"Proposal passed and executed successfully!"
: `Proposal has been ${status}.`}
</h4>
: <>
<div className="flex justify-between">
<h2>Metrics</h2>
<Button
icon={<AdjustmentsHorizontalIcon height={24} width={24} />}
onClick={() => manageSupportClicked()}
disabled={!isConnected || missmatchUrl || !isMemberCommunity}
tooltip={tooltipMessage}
>
Manage support
</Button>
</div>
<div className="flex flex-col gap-7">
<ConvictionBarChart
currentConvictionPct={currentConvictionPct}
thresholdPct={thresholdPct}
proposalSupportPct={totalSupportPct}
isSignalingType={isSignalingType}
proposalNumber={Number(proposalIdNumber)}
timeToPass={Number(timeToPass)}
onReadyToExecute={triggerConvictionRefetch}
defaultChartMaxValue
/>
<div className="flex justify-center lg:justify-end w-full">
{status === "active" && !isSignalingType && (
<Button
onClick={() =>
writeDistribute?.({
args: [
BigInt(poolId),
[proposalData?.strategy.id as Address],
encodedDataProposalId(proposalIdNumber),
],
})
}
disabled={
currentConvictionPct < thresholdPct || !isConnected
}
tooltip={
(tooltipMessage ?? currentConvictionPct < thresholdPct) ?
"Proposal not executable"
: undefined
}
>
Execute
</Button>
)}
{proposalData.strategy.isEnabled && (
<section className="section-layout">
{status && status !== "active" && status !== "disputed" ?
<h4
className={`text-center ${status === "executed" ? "text-primary-content" : "text-error-content"}`}
>
{status === "executed" ?
"Proposal passed and executed successfully!"
: `Proposal has been ${status}.`}
</h4>
: <>
<div className="flex justify-between">
<h2>Metrics</h2>
<Button
icon={<AdjustmentsHorizontalIcon height={24} width={24} />}
onClick={() => manageSupportClicked()}
disabled={!isConnected || missmatchUrl || !isMemberCommunity}
tooltip={tooltipMessage}
>
Manage support
</Button>
</div>
</div>
</>
}
</section>
<div className="flex flex-col gap-7">
<ConvictionBarChart
currentConvictionPct={currentConvictionPct}
thresholdPct={thresholdPct}
proposalSupportPct={totalSupportPct}
isSignalingType={isSignalingType}
proposalNumber={Number(proposalIdNumber)}
timeToPass={Number(timeToPass)}
onReadyToExecute={triggerConvictionRefetch}
defaultChartMaxValue
/>
<div className="flex justify-center lg:justify-end w-full">
{status === "active" && !isSignalingType && (
<Button
onClick={() =>
writeDistribute?.({
args: [
BigInt(poolId),
[proposalData?.strategy.id as Address],
encodedDataProposalId(proposalIdNumber),
],
})
}
disabled={
currentConvictionPct < thresholdPct || !isConnected
}
tooltip={
(
(tooltipMessage ??
currentConvictionPct < thresholdPct)
) ?
"Proposal not executable"
: undefined
}
>
Execute
</Button>
)}
</div>
</div>
</>
}
</section>
)}
{filteredAndSortedProposalSupporters.length > 0 && (
<ProposalSupportersTable
_proposalSupporters={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,20 @@ export default function Page({
chainId={chain}
/>
)}
<section ref={proposalSectionRef}>
<Proposals
poolToken={poolToken}
strategy={strategyObj}
alloInfo={alloInfo}
communityAddress={communityAddress}
createProposalUrl={`/gardens/${chain}/${garden}/${communityAddress}/${poolId}/create-proposal`}
proposalType={proposalType}
/>
</section>
</>
)}
{strategyObj.proposals.length && (
<section ref={proposalSectionRef}>
<Proposals
poolToken={poolToken}
strategy={strategyObj}
alloInfo={alloInfo}
communityAddress={communityAddress}
createProposalUrl={`/gardens/${chain}/${garden}/${communityAddress}/${poolId}/create-proposal`}
proposalType={proposalType}
/>
</section>
)}
</div>
);
}
42 changes: 40 additions & 2 deletions apps/web/app/(app)/gardens/[chain]/[garden]/[community]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Dnum, multiply } from "dnum";
import Image from "next/image";
import Link from "next/link";
import { Address } from "viem";
import { useAccount, useToken } from "wagmi";
import { useAccount, useContractRead, useToken } from "wagmi";
import {
getCommunityDocument,
getCommunityQuery,
Expand All @@ -38,6 +38,7 @@ import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useDisableButtons } from "@/hooks/useDisableButtons";
import { useSubgraphQuery } from "@/hooks/useSubgraphQuery";
import { safeABI } from "@/src/generated";
import { PoolTypes } from "@/types";
import { fetchIpfs } from "@/utils/ipfsUtils";
import {
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function Page({
variables: {
communityAddr: communityAddr.toLowerCase(),
tokenAddr: tokenAddr.toLowerCase(),
showArchived: true,
},
changeScope: [
{ topic: "community", id: communityAddr },
Expand All @@ -76,6 +78,18 @@ export default function Page({
});
const registryCommunity = result?.registryCommunity;

const { data: isCouncilMember } = useContractRead({
address: registryCommunity?.councilSafe as Address,
abi: safeABI,
functionName: "isOwner",
chainId: Number(chain),
enabled: !!accountAddress,
args: [accountAddress as Address],
onError: () => {
console.error("Error reading isOwner from Coucil Safe");
},
});

let {
communityName,
members,
Expand Down Expand Up @@ -144,7 +158,11 @@ export default function Page({
);
const activePools = strategies?.filter((strategy) => strategy?.isEnabled);

const poolsInReview = strategies.filter((strategy) => !strategy.isEnabled);
const poolsInReview = strategies.filter(
(strategy) => !strategy.isEnabled && !strategy.archived,
);

const poolsArchived = strategies.filter((strategy) => strategy.archived);

// const [tokenDataArray, setTokenDataArray] = useState([]);

Expand Down Expand Up @@ -376,6 +394,26 @@ export default function Page({
))}
</div>
</div>
{(!!isCouncilMember ||
accountAddress?.toLowerCase() ===
registryCommunity.councilSafe?.toLowerCase() ||
localStorage.getItem("showArchived") === "true") && (
<div className="flex flex-col gap-4">
<h4 className="text-secondary-content">
Pools archived ({poolsArchived.length})
</h4>
<div className="flex flex-row flex-wrap gap-10">
{poolsArchived.map((pool) => (
<PoolCard
key={pool.poolId}
token={pool.token}
chainId={chain}
pool={pool}
/>
))}
</div>
</div>
)}
</section>
<section ref={covenantSectionRef} className="section-layout">
<h2 className="mb-4">Covenant</h2>
Expand Down
9 changes: 6 additions & 3 deletions apps/web/components/PoolCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import {
ArchiveBoxIcon,
BoltIcon,
ClockIcon,
CurrencyDollarIcon,
Expand Down Expand Up @@ -28,7 +29,7 @@ type Props = {
token: string;
pool: Pick<
CVStrategy,
"id" | "isEnabled" | "poolAmount" | "poolId" | "metadata"
"id" | "isEnabled" | "poolAmount" | "poolId" | "metadata" | "archived"
> & {
proposals: Pick<CVProposal, "id">[];
config: Pick<CVStrategyConfig, "proposalType" | "pointSystem">;
Expand Down Expand Up @@ -95,8 +96,10 @@ export function PoolCard({ pool, token, chainId }: Props) {
</div>
{!isEnabled ?
<div className="banner md:min-w-[262px]">
<ClockIcon className="h-8 w-8 text-secondary-content" />
<h6>Waiting for approval</h6>
{pool.archived ?
<ArchiveBoxIcon className="h-8 w-8 text-secondary-content" />
: <ClockIcon className="h-8 w-8 text-secondary-content" />}
<h6>{pool.archived ? "Archived" : "Waiting for approval"}</h6>
</div>
: <Image
src={poolType && PoolTypes[poolType] === "funding" ? blueLand : grass}
Expand Down
12 changes: 9 additions & 3 deletions apps/web/components/PoolHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
ChartBarIcon,
CheckIcon,
ClockIcon,
ArchiveBoxIcon,
InformationCircleIcon,
Square3Stack3DIcon,
} from "@heroicons/react/24/outline";
import {
ArchiveBoxIcon,
NoSymbolIcon,
StopIcon,
Cog6ToothIcon,
Expand Down Expand Up @@ -581,8 +581,14 @@ export default function PoolHeader({
)}
{!isEnabled ?
<div className="banner">
<ClockIcon className="h-8 w-8 text-secondary-content" />
<h6>Waiting for council approval</h6>
{isArchived ?
<ArchiveBoxIcon className="h-8 w-8 text-secondary-content" />
: <ClockIcon className="h-8 w-8 text-secondary-content" />}
<h6>
{isArchived ?
"This pool has been archived"
: "Waiting for council approval"}
</h6>
</div>
: <Image
src={PoolTypes[proposalType] === "funding" ? blueLand : grassLarge}
Expand Down
Loading

0 comments on commit 98d5055

Please sign in to comment.