Skip to content

Commit

Permalink
Fixed wrong token + Access proposal support from proposal Details page
Browse files Browse the repository at this point in the history
  • Loading branch information
kafann committed Nov 14, 2024
1 parent 8d846de commit 68c28bd
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { useEffect } from "react";
import { Hashicon } from "@emeraldpay/hashicon-react";
import { InformationCircleIcon, UserIcon } from "@heroicons/react/24/outline";
import { AdjustmentsHorizontalIcon, InformationCircleIcon, UserIcon } from "@heroicons/react/24/outline";
import { toast } from "react-toastify";
import { Address, encodeAbiParameters, formatUnits } from "viem";
import { useAccount, useToken } from "wagmi";
Expand Down Expand Up @@ -33,6 +33,8 @@ import { PoolTypes, ProposalStatus } from "@/types";

import { useErrorDetails } from "@/utils/getErrorName";
import { prettyTimestamp } from "@/utils/text";
import { usePathname,useRouter } from "next/navigation";
import { QUERY_PARAMS } from "@/constants/query-params";

export default function Page({
params: { proposalId, garden, poolId },
Expand Down Expand Up @@ -73,6 +75,8 @@ export default function Page({
hash: proposalData?.metadataHash,
enabled: !proposalData?.metadata,
});
const router = useRouter();
const path = usePathname();
const metadata = proposalData?.metadata ?? ipfsResult;
const isProposerConnected =
proposalData?.submitter === address?.toLowerCase();
Expand All @@ -89,6 +93,7 @@ export default function Page({
enabled: !!poolTokenAddr && !isSignalingType,
chainId,
});


const {
currentConvictionPct,
Expand Down Expand Up @@ -137,6 +142,15 @@ export default function Page({
},
});

const manageSupportClicked = () => {
const pathSegments = path.split("/");
pathSegments.pop();
if (pathSegments.length === 3) {
pathSegments.pop();
}
const newPath = pathSegments.join("/");
router.push(newPath+`?${QUERY_PARAMS.poolPage.allocationView}=true`,);
}
const distributeErrorName = useErrorDetails(errorDistribute);
useEffect(() => {
if (isErrorDistribute && distributeErrorName.errorName !== undefined) {
Expand Down Expand Up @@ -246,6 +260,8 @@ export default function Page({
<div className="flex justify-between">
<h2>Metrics</h2>
{status === "active" && !isSignalingType && (


<Button
onClick={() =>
writeDistribute?.({
Expand Down Expand Up @@ -280,6 +296,17 @@ export default function Page({
onReadyToExecute={triggerConvictionRefetch}
defaultChartMaxValue
/>
<Button
icon={
<AdjustmentsHorizontalIcon height={24} width={24} />
}
onClick={() => manageSupportClicked()}
// disabled={disableManSupportButton || !isAllowed}
// tooltip={tooltipMessage}
>
Manage support
</Button>

</>
}
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useEffect } from "react";
import { useEffect, useRef } from "react";
import { Address } from "viem";
import { useToken } from "wagmi";
import {
Expand All @@ -27,6 +27,7 @@ export default function Page({
params: { chain: string; poolId: number; garden: string };
}) {
const searchParams = useCollectQueryParams();
const proposalSectionRef = useRef<HTMLDivElement>(null);

const { data, refetch, error } = useSubgraphQuery<getPoolDataQuery>({
query: getPoolDataDocument,
Expand Down Expand Up @@ -55,7 +56,7 @@ export default function Page({
},
],
});

console.log("data", data);
const strategyObj = data?.cvstrategies?.[0];
const poolTokenAddr = strategyObj?.token as Address;
const proposalType = strategyObj?.config.proposalType;
Expand Down Expand Up @@ -102,9 +103,25 @@ export default function Page({
refetch();
}
}, [searchParams, strategyObj?.proposals]);

const tokenGarden = data?.tokenGarden;

useEffect(() => {
console.log("QUERY PARAM ALLOCATION",searchParams[QUERY_PARAMS.poolPage.allocationView]);
if (
searchParams[QUERY_PARAMS.poolPage.allocationView] !== undefined &&
proposalSectionRef.current
) {
const elementTop =
proposalSectionRef.current.getBoundingClientRect().top + window.scrollY;
window.scrollTo({
top: elementTop - 130,
behavior: "smooth",
});
}
// setAllocationView(searchParams[QUERY_PARAMS.poolPage.allocationView]);
}, [proposalSectionRef.current, searchParams]);

if (!tokenGarden || (!poolToken && PoolTypes[proposalType] === "funding")) {
return (
<div className="mt-96">
Expand Down Expand Up @@ -146,14 +163,18 @@ export default function Page({
chainId={chain}
/>
)}
<section ref={proposalSectionRef} className="section-layout">

<Proposals
poolToken={poolToken}
strategy={strategyObj}
alloInfo={alloInfo}
communityAddress={communityAddress}
createProposalUrl={`/gardens/${chain}/${garden}/${communityAddress}/${poolId}/create-proposal`}
proposalType={proposalType}
allocationViewInit={searchParams[QUERY_PARAMS.poolPage.allocationView] === "true"}
/>
</section>
</>
)}
</div>
Expand Down
51 changes: 35 additions & 16 deletions apps/web/app/(app)/gardens/[chain]/[garden]/[community]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useEffect, useRef, useState } from "react";
import React, { Fragment, useEffect, useRef, useState } from "react";
import {
CurrencyDollarIcon,
PlusIcon,
Expand Down Expand Up @@ -75,7 +75,7 @@ export default function Page({
{ topic: "member", containerId: communityAddr },
],
});

console.log(result);
const registryCommunity = result?.registryCommunity;

let {
Expand Down Expand Up @@ -148,6 +148,30 @@ export default function Page({

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

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

// useEffect(() => {
// // Initialize an empty array for holding token data for each pool
// const newTokenDataArray = fundingPools.map((pool) => ({
// poolId: pool.poolId,
// tokenData: null ,
// }));

// // Iterate over each pool and use `useToken` to get token data
// fundingPools.forEach((pool, index) => {
// const { data } = useToken({
// address: pool.token as Address,
// chainId: +chain,
// });

// // Update the tokenData in the array for this specific pool
// newTokenDataArray[index].tokenData = data;
// });

// // Once data is fetched, update the state
// setTokenDataArray(newTokenDataArray);
// }, [fundingPools, chain]);

useEffect(() => {
const newPoolId = searchParams[QUERY_PARAMS.communityPage.newPool];
const fetchedPools = poolsInReview.some((c) => c.poolId === newPoolId);
Expand Down Expand Up @@ -318,14 +342,13 @@ export default function Page({
</h4>
<div className="flex flex-row flex-wrap gap-10">
{fundingPools.map((pool) => (
<Fragment key={pool.poolId}>
<PoolCard
key={pool.poolId}
tokenGarden={{
decimals: tokenGarden?.decimals ?? 18,
symbol: tokenGarden?.symbol ?? "",
}}
token={pool.token}
chainId={chain}
pool={pool}
/>
/>
</Fragment>
))}
</div>
</div>
Expand All @@ -337,10 +360,8 @@ export default function Page({
{signalingPools.map((pool) => (
<PoolCard
key={pool.poolId}
tokenGarden={{
symbol: tokenGarden?.symbol ?? "",
decimals: tokenGarden?.decimals ?? 18,
}}
token={pool.token}
chainId={chain}
pool={pool}
/>
))}
Expand All @@ -354,10 +375,8 @@ export default function Page({
{poolsInReview.map((pool) => (
<PoolCard
key={pool.poolId}
tokenGarden={{
decimals: tokenGarden?.decimals ?? 18,
symbol: tokenGarden?.symbol ?? "",
}}
token={pool.token}
chainId={chain}
pool={pool}
/>
))}
Expand Down
21 changes: 17 additions & 4 deletions apps/web/components/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useMetadataIpfsFetch } from "@/hooks/useIpfsFetch";
import { PointSystems, PoolTypes } from "@/types";
import { capitalize } from "@/utils/text";
import { Address, useToken } from "wagmi";
import { useEffect } from "react";

type Props = {
tokenGarden: Pick<TokenGarden, "decimals" | "symbol">;
token: string;
pool: Pick<
CVStrategy,
"id" | "isEnabled" | "poolAmount" | "poolId" | "metadata"
> & {
proposals: Pick<CVProposal, "id">[];
config: Pick<CVStrategyConfig, "proposalType" | "pointSystem">;
};
chainId: number;
};

export function PoolCard({ pool, tokenGarden }: Props) {
export function PoolCard({ pool, token,chainId }: Props) {
const pathname = usePathname();
const searchParams = useCollectQueryParams();

Expand All @@ -47,6 +50,16 @@ export function PoolCard({ pool, tokenGarden }: Props) {

poolAmount = poolAmount || 0;
const poolType = config?.proposalType as number | undefined;
const { data: tokenGarden } = useToken({
address: token as Address,
chainId: +chainId,
});
//MAYBE: use getPoolDataQuery to get token address, but should be done
// from community page that already fetches pools and their data
useEffect(() => {
console.log("chainID", chainId);
console.log("token", token);
}, [chainId]);

const isNewPool =
searchParams[QUERY_PARAMS.communityPage.newPool] === pool.poolId.toString();
Expand Down Expand Up @@ -82,9 +95,9 @@ export function PoolCard({ pool, tokenGarden }: Props) {
{isEnabled && poolType && PoolTypes[poolType] === "funding" && (
<Statistic icon={<CurrencyDollarIcon />} label="funds">
<DisplayNumber
number={[BigInt(poolAmount), tokenGarden.decimals]}
number={[BigInt(poolAmount), tokenGarden?.decimals as number]}
compact={true}
tokenSymbol={tokenGarden.symbol}
tokenSymbol={tokenGarden?.symbol}
/>
</Statistic>
)}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/components/Proposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ interface ProposalsProps {
communityAddress: Address;
createProposalUrl: string;
proposalType: number;
allocationViewInit?: boolean;
}

export function Proposals({
Expand All @@ -93,9 +94,10 @@ export function Proposals({
poolToken,
communityAddress,
createProposalUrl,
allocationViewInit
}: ProposalsProps) {
// State
const [allocationView, setAllocationView] = useState(false);
const [allocationView, setAllocationView] = useState(allocationViewInit ?? false);
const [inputAllocatedTokens, setInputAllocatedTokens] = useState<number>(0);
const [inputs, setInputs] = useState<{ [key: string]: ProposalInputItem }>(
{},
Expand Down
1 change: 1 addition & 0 deletions apps/web/constants/query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const QUERY_PARAMS = {
},
poolPage: {
newProposal: "newProposal",
allocationView: "allocationView",
},
} as const;
12 changes: 6 additions & 6 deletions pkg/contracts/src/CVStrategy/CVStrategyV0_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
/*| CUSTOM ERRORS |*/
/*|--------------------------------------------|*/

// error UserCannotBeZero(); // 0xd1f28288
error UserCannotBeZero(); // 0xd1f28288
error UserNotInRegistry(); //0x6a5cfb6d
error UserIsInactive(); // 0x5fccb67f
error PoolIsEmpty(); // 0xed4421ad
error NotImplemented(); //0xd6234725
// error TokenCannotBeZero(); //0x596a094c
error TokenCannotBeZero(); //0x596a094c
error TokenNotAllowed(); // 0xa29c4986
error AmountOverMaxRatio(); // 0x3bf5ca14
error AddressCannotBeZero(); //0xe622e040
// error RegistryCannotBeZero(); // 0x5df4b1ef
error RegistryCannotBeZero(); // 0x5df4b1ef
error SupportUnderflow(uint256 _support, int256 _delta, int256 _result); // 0x3bbc7142
error NotEnoughPointsToSupport(uint256 pointsSupport, uint256 pointsBalance); // 0xd64182fe

// error ProposalDataIsEmpty(); //0xc5f7c4c0
// error ProposalIdCannotBeZero(); //0xf881a10d
error ProposalDataIsEmpty(); //0xc5f7c4c0
error ProposalIdCannotBeZero(); //0xf881a10d
error ProposalNotActive(uint256 _proposalId); // 0x44980d8f
error ProposalNotInList(uint256 _proposalId); // 0xc1d17bef
error ProposalSupportDuplicated(uint256 _proposalId, uint256 index); //0xadebb154
Expand All @@ -168,7 +168,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
error InsufficientCollateral(uint256 sentAmount, uint256 requiredAmount);
error OnlyArbitrator();
error ProposalNotDisputed(uint256 _proposalId);
// error ArbitratorCannotBeZero();
error ArbitratorCannotBeZero();
error OnlySubmitter(address submitter, address sender);
// Goss: Support Collateral Zero
// error CollateralVaultCannotBeZero();
Expand Down
2 changes: 1 addition & 1 deletion pkg/subgraph/.graphclient/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3672,7 +3672,7 @@ export type getCommunityQueryVariables = Exact<{
export type getCommunityQuery = {
registryCommunity?: Maybe<(Pick<RegistryCommunity, 'communityName' | 'id' | 'covenantIpfsHash' | 'communityFee' | 'protocolFee' | 'registerStakeAmount' | 'registerToken'> & {
members?: Maybe<Array<Pick<MemberCommunity, 'id' | 'stakedTokens'>>>;
strategies?: Maybe<Array<(Pick<CVStrategy, 'id' | 'isEnabled' | 'poolAmount' | 'poolId' | 'metadata'> & {
strategies?: Maybe<Array<(Pick<CVStrategy, 'id' | 'isEnabled' | 'poolAmount' | 'poolId' | 'token' | 'metadata'> & {
proposals: Array<Pick<CVProposal, 'id'>>;
config: Pick<CVStrategyConfig, 'proposalType' | 'pointSystem'>;
})>>;
Expand Down
Loading

0 comments on commit 68c28bd

Please sign in to comment.