From 6ebb9c75fed93ec0aa31e7ae2be74fabdb343e46 Mon Sep 17 00:00:00 2001 From: Lucianosc Date: Thu, 8 Aug 2024 15:44:48 -0300 Subject: [PATCH 1/4] fix styles & commented code --- .../[poolId]/create-proposal/page.tsx | 4 +- apps/web/components/Forms/CommunityForm.tsx | 69 ------------------- apps/web/components/Forms/ProposalForm.tsx | 8 +-- 3 files changed, 6 insertions(+), 75 deletions(-) diff --git a/apps/web/app/(app)/gardens/[chain]/[garden]/[community]/[poolId]/create-proposal/page.tsx b/apps/web/app/(app)/gardens/[chain]/[garden]/[community]/[poolId]/create-proposal/page.tsx index 879f866f4..2c556fdd0 100644 --- a/apps/web/app/(app)/gardens/[chain]/[garden]/[community]/[poolId]/create-proposal/page.tsx +++ b/apps/web/app/(app)/gardens/[chain]/[garden]/[community]/[poolId]/create-proposal/page.tsx @@ -60,10 +60,10 @@ export default function Page({

- Create a Proposal in Pool + Create a Proposal in Pool #{poolId}

-

{metadata.title}

+

{metadata.title}

) => { - // if (!e.target.files) return; - // const selectedFile = e.target.files[0]; - - // const ipfsUpload = ipfsFileUpload(selectedFile); - - // toast - // .promise(ipfsUpload, { - // pending: "Uploading image...", - // success: "Successfully uploaded!", - // error: "Try uploading banner image again", - // }) - // .then((data) => { - // console.log("https://ipfs.io/ipfs/" + data); - // setFile(selectedFile); - // setIpfsFileHash(data); - // }) - // .catch((error: any) => { - // console.error(error); - // }); - // }; - const createCommunity = async () => { setLoading(true); const json = { @@ -370,53 +348,6 @@ export const CommunityForm = ({ placeholder="Covenant description..." /> - - {/* Upload image */} - {/* -
-
- {file ? ( - Project cover photo - ) : ( - <> -
-
- - )} -
-
*/} }
diff --git a/apps/web/components/Forms/ProposalForm.tsx b/apps/web/components/Forms/ProposalForm.tsx index 7d352fc03..b4b6efa4a 100644 --- a/apps/web/components/Forms/ProposalForm.tsx +++ b/apps/web/components/Forms/ProposalForm.tsx @@ -109,9 +109,9 @@ export const ProposalForm = ({ const spendingLimitNumber = spendingLimit / 10 ** tokenGarden.decimals; - // console.log("spendingLimit: %s", spendingLimit); - // console.log("spendingLimitNumber: %s", spendingLimitNumber); - // console.log("spendingLimitPct: %s", spendingLimitPct); + console.debug("spendingLimit: %s", spendingLimit); + console.debug("spendingLimitNumber: %s", spendingLimitNumber); + console.debug("spendingLimitPct: %s", spendingLimitPct); const spendingLimitString = formatTokenAmount( spendingLimit, @@ -255,7 +255,7 @@ export const ProposalForm = ({ formRows={formatFormRows()} previewTitle="Check proposals details" /> - :
+ :
{proposalTypeName === "funding" && (
Date: Thu, 8 Aug 2024 15:45:05 -0300 Subject: [PATCH 2/4] fix community form in section --- .../[garden]/create-community/page.tsx | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/apps/web/app/(app)/gardens/[chain]/[garden]/create-community/page.tsx b/apps/web/app/(app)/gardens/[chain]/[garden]/create-community/page.tsx index bfbfea05c..97df58350 100644 --- a/apps/web/app/(app)/gardens/[chain]/[garden]/create-community/page.tsx +++ b/apps/web/app/(app)/gardens/[chain]/[garden]/create-community/page.tsx @@ -17,10 +17,10 @@ export default function Page({ params: { chain: number; garden: string }; }) { const { data: result, error: getCommunityCreationDataQueryError } = - useSubgraphQuery({ - query: getCommunityCreationDataDocument, - variables: { addr: garden }, - }); + useSubgraphQuery({ + query: getCommunityCreationDataDocument, + variables: { addr: garden }, + }); useEffect(() => { if (getCommunityCreationDataQueryError) { @@ -36,32 +36,29 @@ export default function Page({ const alloContractAddr = result?.tokenGarden?.communities?.[0] .alloAddress as Address; - return tokenGarden ? ( -
-
-
-

- Welcome to the {tokenGarden.symbol} Community Form! -

-
-

- Create a vibrant community around the{" "} - {tokenGarden.name} by providing the necessary - details below. -

+ return tokenGarden ? +
+
+
+

+ Welcome to the {tokenGarden.symbol} Community Form! +

+
+

+ Create a vibrant community around the {tokenGarden.name} by + providing the necessary details below. +

+
-
-
- -
- ) : ( -
- -
- ); + +
+ + :
+ +
; } From 3ef97b74f67cc4b5ea711a01757904d6a3d932fc Mon Sep 17 00:00:00 2001 From: Lucianosc Date: Thu, 8 Aug 2024 16:19:28 -0300 Subject: [PATCH 3/4] fix communityFee input --- apps/web/components/Forms/CommunityForm.tsx | 41 +++++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/web/components/Forms/CommunityForm.tsx b/apps/web/components/Forms/CommunityForm.tsx index b0d339714..a84e5a0c2 100644 --- a/apps/web/components/Forms/CommunityForm.tsx +++ b/apps/web/components/Forms/CommunityForm.tsx @@ -9,7 +9,6 @@ import { TokenGarden } from "#/subgraph/.graphclient"; import { FormCheckBox } from "./FormCheckBox"; import { FormInput } from "./FormInput"; import { FormPreview, FormRow } from "./FormPreview"; -import { FormSelect, Option } from "./FormSelect"; import { Button } from "@/components"; import { getChain } from "@/configs/chainServer"; import { getConfigByChain } from "@/constants/contracts"; @@ -21,7 +20,10 @@ import { registryFactoryABI, safeABI } from "@/src/generated"; import { abiWithErrors } from "@/utils/abiWithErrors"; import { getEventFromReceipt } from "@/utils/contracts"; import { ipfsJsonUpload } from "@/utils/ipfsUtils"; -import { SCALE_PRECISION_DECIMALS } from "@/utils/numbers"; +import { + CV_PERCENTAGE_SCALE, + CV_PERCENTAGE_SCALE_DECIMALS, +} from "@/utils/numbers"; //protocol : 1 => means ipfs!, to do some checks later @@ -42,11 +44,6 @@ type FormRowTypes = { }; const ethereumAddressRegEx = /^(0x)?[0-9a-fA-F]{40}$/; -const feeOptions: Option[] = [ - { value: 0, label: "0%" }, - { value: 0.01, label: "1%" }, - { value: 0.02, label: "2%" }, -]; export const CommunityForm = ({ chainId, @@ -95,7 +92,7 @@ export const CommunityForm = ({ }, feeAmount: { label: "Community Fee Amount:", - parse: (value: number) => `${value * 100 ?? "0"} %`, + parse: (value: number) => `${value} %`, }, feeReceiver: { label: "Fee Receiver:" }, councilSafe: { label: "Council Safe:" }, @@ -160,8 +157,9 @@ export const CommunityForm = ({ ); const communityFeeAmount = parseUnits( previewData?.feeAmount.toString() as string, - SCALE_PRECISION_DECIMALS, + CV_PERCENTAGE_SCALE_DECIMALS, ); + const communityFeeReceiver = previewData?.feeReceiver; const councilSafeAddress = previewData?.councilSafe; // arb safe 0xda7bdebd79833a5e0c027fab1b1b9b874ddcbd10 @@ -281,13 +279,32 @@ export const CommunityForm = ({
- + type="number" + placeholder="0" + className="pr-14" + otherProps={{ + step: 1 / CV_PERCENTAGE_SCALE, + min: 1 / CV_PERCENTAGE_SCALE, + }} + registerOptions={{ + max: { + value: 100, + message: "Max amount cannot exceed 100%", + }, + min: { + value: 1 / CV_PERCENTAGE_SCALE, + message: `Amount must be greater than ${1 / CV_PERCENTAGE_SCALE}`, + }, + }} + > + % +
Date: Fri, 9 Aug 2024 15:41:12 -0300 Subject: [PATCH 4/4] fix shown amount in proposal form --- apps/web/components/Forms/ProposalForm.tsx | 45 +++++++++++++++++++--- apps/web/utils/numbers.ts | 6 ++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/apps/web/components/Forms/ProposalForm.tsx b/apps/web/components/Forms/ProposalForm.tsx index b4b6efa4a..f3fa6fb23 100644 --- a/apps/web/components/Forms/ProposalForm.tsx +++ b/apps/web/components/Forms/ProposalForm.tsx @@ -64,6 +64,37 @@ const abiParameters = [ const ethereumAddressRegEx = /^(0x)?[0-9a-fA-F]{40}$/; +function formatNumber(num: string | number): string { + // Convert to number if it's a string + const number = typeof num === "string" ? parseFloat(num) : num; + + // Check if the number is NaN + if (isNaN(number)) { + return "Invalid Number"; + } + + // If the absolute value is greater than or equal to 1, use toFixed(2) + if (Math.abs(number) >= 1) { + return number.toFixed(2); + } + + // For numbers between 0 and 1 (exclusive) + const parts = number.toString().split("e"); + const exponent = parts[1] ? parseInt(parts[1]) : 0; + + if (exponent < -3) { + // For very small numbers, use exponential notation with 4 significant digits + return number.toPrecision(4); + } else { + // For numbers between 0.001 and 1, show at least 4 decimal places + const decimalPlaces = Math.max( + 4, + -Math.floor(Math.log10(Math.abs(number))) + 3, + ); + return number.toFixed(decimalPlaces); + } +} + export const ProposalForm = ({ poolId, proposalType, @@ -109,13 +140,14 @@ export const ProposalForm = ({ const spendingLimitNumber = spendingLimit / 10 ** tokenGarden.decimals; - console.debug("spendingLimit: %s", spendingLimit); - console.debug("spendingLimitNumber: %s", spendingLimitNumber); - console.debug("spendingLimitPct: %s", spendingLimitPct); + // console.log("spendingLimit: %s", spendingLimit); + // console.log("spendingLimitNumber: %s", spendingLimitNumber); + // console.log("spendingLimitPct: %s", spendingLimitPct); const spendingLimitString = formatTokenAmount( spendingLimit, tokenGarden?.decimals as number, + 6, ); const proposalTypeName = poolTypes[proposalType]; @@ -246,6 +278,7 @@ export const ProposalForm = ({ return formattedRows; }; + return (
{showPreview ? @@ -255,18 +288,18 @@ export const ProposalForm = ({ formRows={formatFormRows()} previewTitle="Check proposals details" /> - :
+ :
{proposalTypeName === "funding" && (