From 3ec1edf723c36903b1951f6f5ae84a3c9fe3f6e9 Mon Sep 17 00:00:00 2001 From: "Felix C. Morency" <1102868+fmorency@users.noreply.github.com> Date: Mon, 9 Dec 2024 15:46:20 -0500 Subject: [PATCH] chore: cleanup --- components/groups/forms/index.tsx | 1 - .../forms/proposals/ConfirmationForm.tsx | 292 ----- .../forms/proposals/ProposalDetailsForm.tsx | 139 -- .../forms/proposals/ProposalMessages.tsx | 1130 ----------------- .../forms/proposals/ProposalMetadataForm.tsx | 131 -- .../groups/forms/proposals/SuccessForm.tsx | 117 -- .../__tests__/ConfirmationForm.test.tsx | 80 -- .../__tests__/ProposalDetailsForm.test.tsx | 103 -- .../__tests__/ProposalMessages.test.tsx | 117 -- .../__tests__/ProposalMetadataForm.test.tsx | 124 -- .../proposals/__tests__/SuccessForm.test.tsx | 69 - components/groups/forms/proposals/index.tsx | 5 - components/groups/forms/proposals/messages.ts | 173 --- hooks/useQueries.ts | 155 --- .../submit-proposal/[policyAddress].tsx | 169 --- 15 files changed, 2805 deletions(-) delete mode 100644 components/groups/forms/proposals/ConfirmationForm.tsx delete mode 100644 components/groups/forms/proposals/ProposalDetailsForm.tsx delete mode 100644 components/groups/forms/proposals/ProposalMessages.tsx delete mode 100644 components/groups/forms/proposals/ProposalMetadataForm.tsx delete mode 100644 components/groups/forms/proposals/SuccessForm.tsx delete mode 100644 components/groups/forms/proposals/__tests__/ConfirmationForm.test.tsx delete mode 100644 components/groups/forms/proposals/__tests__/ProposalDetailsForm.test.tsx delete mode 100644 components/groups/forms/proposals/__tests__/ProposalMessages.test.tsx delete mode 100644 components/groups/forms/proposals/__tests__/ProposalMetadataForm.test.tsx delete mode 100644 components/groups/forms/proposals/__tests__/SuccessForm.test.tsx delete mode 100644 components/groups/forms/proposals/index.tsx delete mode 100644 components/groups/forms/proposals/messages.ts delete mode 100644 pages/groups/submit-proposal/[policyAddress].tsx diff --git a/components/groups/forms/index.tsx b/components/groups/forms/index.tsx index 6a376e2a..d20b7e11 100644 --- a/components/groups/forms/index.tsx +++ b/components/groups/forms/index.tsx @@ -1,2 +1 @@ export * from './groups'; -export * from './proposals'; diff --git a/components/groups/forms/proposals/ConfirmationForm.tsx b/components/groups/forms/proposals/ConfirmationForm.tsx deleted file mode 100644 index fb39814c..00000000 --- a/components/groups/forms/proposals/ConfirmationForm.tsx +++ /dev/null @@ -1,292 +0,0 @@ -import React from 'react'; -import { useFeeEstimation } from '@/hooks/useFeeEstimation'; -import { uploadJsonToIPFS } from '@/hooks/useIpfs'; -import { useTx } from '@/hooks/useTx'; -import { strangelove_ventures, cosmos, liftedinit } from '@liftedinit/manifestjs'; -import { Any } from '@liftedinit/manifestjs/dist/codegen/google/protobuf/any'; - -import { TruncatedAddressWithCopy } from '@/components/react/addressCopy'; -import { ProposalFormData } from '@/helpers/formReducer'; -import { chainName } from '@/config'; -import { MsgMultiSend, MsgSend } from '@liftedinit/manifestjs/dist/codegen/cosmos/bank/v1beta1/tx'; -import { - MsgRemovePending, - MsgRemoveValidator, - MsgSetPower, - MsgUpdateStakingParams, -} from '@liftedinit/manifestjs/dist/codegen/strangelove_ventures/poa/v1/tx'; -import { - MsgCreateGroupWithPolicy, - MsgExec, - MsgLeaveGroup, - MsgSubmitProposal, - MsgUpdateGroupAdmin, - MsgUpdateGroupMembers, - MsgUpdateGroupMetadata, - MsgUpdateGroupPolicyAdmin, - MsgVote, - MsgWithdrawProposal, -} from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/tx'; -import { - MsgPayout, - MsgBurnHeldBalance, -} from '@liftedinit/manifestjs/dist/codegen/liftedinit/manifest/v1/tx'; -import { - MsgSoftwareUpgrade, - MsgCancelUpgrade, -} from '@liftedinit/manifestjs/dist/codegen/cosmos/upgrade/v1beta1/tx'; - -export default function ConfirmationForm({ - policyAddress, - nextStep, - prevStep, - formData, - address, -}: Readonly<{ - policyAddress: string; - nextStep: () => void; - prevStep: () => void; - formData: ProposalFormData; - address: string; -}>) { - type MessageTypeMap = { - send: MsgSend; - removeValidator: MsgRemoveValidator; - removePending: MsgRemovePending; - updateStakingParams: MsgUpdateStakingParams; - setPower: MsgSetPower; - - payoutStakeholders: MsgPayout; - updateGroupAdmin: MsgUpdateGroupAdmin; - updateGroupMembers: MsgUpdateGroupMembers; - updateGroupMetadata: MsgUpdateGroupMetadata; - updateGroupPolicyAdmin: MsgUpdateGroupPolicyAdmin; - createGroupWithPolicy: MsgCreateGroupWithPolicy; - submitProposal: MsgSubmitProposal; - vote: MsgVote; - withdrawProposal: MsgWithdrawProposal; - exec: MsgExec; - leaveGroup: MsgLeaveGroup; - multiSend: MsgMultiSend; - softwareUpgrade: MsgSoftwareUpgrade; - cancelUpgrade: MsgCancelUpgrade; - customMessage: any; - }; - - const messageTypeToComposer: { - [K in keyof MessageTypeMap]: (value: MessageTypeMap[K]) => any; - } = { - send: cosmos.bank.v1beta1.MessageComposer.encoded.send, - removeValidator: strangelove_ventures.poa.v1.MessageComposer.encoded.removeValidator, - removePending: strangelove_ventures.poa.v1.MessageComposer.encoded.removePending, - updateStakingParams: strangelove_ventures.poa.v1.MessageComposer.encoded.updateStakingParams, - setPower: strangelove_ventures.poa.v1.MessageComposer.encoded.setPower, - - payoutStakeholders: liftedinit.manifest.v1.MessageComposer.encoded.payout, - updateGroupAdmin: cosmos.group.v1.MessageComposer.encoded.updateGroupAdmin, - updateGroupMembers: cosmos.group.v1.MessageComposer.encoded.updateGroupMembers, - updateGroupMetadata: cosmos.group.v1.MessageComposer.encoded.updateGroupMetadata, - updateGroupPolicyAdmin: cosmos.group.v1.MessageComposer.encoded.updateGroupPolicyAdmin, - createGroupWithPolicy: cosmos.group.v1.MessageComposer.encoded.createGroupWithPolicy, - submitProposal: cosmos.group.v1.MessageComposer.encoded.submitProposal, - vote: cosmos.group.v1.MessageComposer.encoded.vote, - withdrawProposal: cosmos.group.v1.MessageComposer.encoded.withdrawProposal, - customMessage: cosmos.bank.v1beta1.MessageComposer.encoded.send, - exec: cosmos.group.v1.MessageComposer.encoded.exec, - leaveGroup: cosmos.group.v1.MessageComposer.encoded.leaveGroup, - multiSend: cosmos.bank.v1beta1.MessageComposer.encoded.multiSend, - softwareUpgrade: cosmos.upgrade.v1beta1.MessageComposer.encoded.softwareUpgrade, - cancelUpgrade: cosmos.upgrade.v1beta1.MessageComposer.encoded.cancelUpgrade, - }; - const snakeToCamel = (str: string): string => - str.replace(/([-_][a-z])/gi, $1 => $1.toUpperCase().replace('-', '').replace('_', '')); - - const convertKeysToCamelCase = (obj: any): any => { - if (Array.isArray(obj)) { - return obj.map(v => convertKeysToCamelCase(v)); - } else if (obj !== null && typeof obj === 'object') { - return Object.keys(obj).reduce( - (acc, key) => { - acc[snakeToCamel(key)] = convertKeysToCamelCase(obj[key]); - return acc; - }, - {} as Record - ); - } - return obj; - }; - - const getMessageObject = (message: { type: keyof MessageTypeMap } & Record): Any => { - const composer = messageTypeToComposer[message.type]; - if (composer) { - let messageData = JSON.parse(JSON.stringify(message)); - - delete messageData.type; - - messageData = convertKeysToCamelCase(messageData); - if (messageData.amount && !Array.isArray(messageData.amount)) { - messageData.amount = [messageData.amount]; - } - const composedMessage = composer(messageData as MessageTypeMap[typeof message.type]); - if (!composedMessage || !composedMessage.value) { - console.error('Composed message or its value is undefined:', composedMessage); - throw new Error(`Failed to compose message for type: ${message.type}`); - } - - // Verify composedMessage structure - if (!composedMessage.typeUrl || typeof composedMessage.value !== 'object') { - console.error('Invalid composedMessage structure:', composedMessage); - throw new Error(`Invalid composedMessage structure for type: ${message.type}`); - } - - try { - const anyMessage = Any.fromPartial({ - typeUrl: composedMessage.typeUrl, - value: composedMessage.value, - }); - - return anyMessage; - } catch (error) { - console.error('Error encoding message:', error); - console.error('Message type:', message.type); - console.error('Composed message:', composedMessage); - throw error; - } - } - throw new Error(`Unknown message type: ${message.type}`); - }; - - const proposalMetadata = { - title: formData.metadata.title, - authors: formData.metadata.authors, - summary: formData.metadata.summary, - details: formData.metadata.details, - proposalForumURL: '', - voteOptionContext: '', - }; - - const jsonString = JSON.stringify(proposalMetadata); - - const { tx, isSigning, setIsSigning } = useTx(chainName); - - const { estimateFee } = useFeeEstimation('manifest'); - - const uploadMetaDataToIPFS = async () => { - const CID = await uploadJsonToIPFS(jsonString); - return CID; - }; - - const handleConfirm = async () => { - setIsSigning(true); - const CID = await uploadMetaDataToIPFS(); - - const messages: Any[] = formData.messages.map(message => getMessageObject(message)); - const msg = cosmos.group.v1.MessageComposer.fromPartial.submitProposal({ - groupPolicyAddress: policyAddress, - messages: messages, - metadata: CID, - proposers: [formData.proposers], - title: formData.title, - summary: formData.metadata.summary, - exec: 0, // For now - }); - const fee = await estimateFee(address ?? '', [msg]); - await tx([msg], { - fee, - onSuccess: () => { - nextStep(); - }, - }); - }; - - return ( -
-
-
-

{formData.title}

-
- -
- {/* Proposal Information */} -
-

- Proposal Information -

-
-
- - -
-
- -
- {formData.metadata.summary.length > 100 - ? `${formData.metadata.summary.slice(0, 100)}...` - : formData.metadata.summary} -
-
-
-
- - {/* Messages */} -
-

Messages

-
- {formData.messages.map((message, index) => ( -
-
Type
-
- {message.type} -
- {/* Add more message details here if needed */} -
- ))} -
-
- - {/* Metadata */} -
-

Metadata

-
-
-
Authors
-
{formData.metadata.authors}
-
-
-
Title
-
{formData.metadata.title}
-
-
-
-
Details
-
- {formData.metadata.details} -
-
-
-
-
- - {/* Buttons */} -
- - -
-
- ); -} diff --git a/components/groups/forms/proposals/ProposalDetailsForm.tsx b/components/groups/forms/proposals/ProposalDetailsForm.tsx deleted file mode 100644 index 8c789448..00000000 --- a/components/groups/forms/proposals/ProposalDetailsForm.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import React, { useState } from 'react'; -import { Formik, Form } from 'formik'; -import Yup from '@/utils/yupExtensions'; -import { ProposalFormData, ProposalAction } from '@/helpers/formReducer'; -import { MdContacts } from 'react-icons/md'; -import { TextInput, TextArea } from '@/components/react/inputs'; -import Link from 'next/link'; -import { useRouter } from 'next/router'; -import { TailwindModal } from '@/components/react'; -import { Contacts } from '@/components/react/views/Contacts'; - -const ProposalSchema = Yup.object().shape({ - title: Yup.string() - .required('Title is required') - .max(50, 'Title must not exceed 50 characters') - .noProfanity('Profanity is not allowed'), - proposers: Yup.string().manifestAddress().required('Required'), - summary: Yup.string() - .required('Summary is required') - .min(10, 'Summary must be at least 10 characters') - .max(500, 'Summary must not exceed 500 characters') - .noProfanity('Profanity is not allowed'), -}); - -export default function ProposalDetails({ - nextStep, - formData, - dispatch, - address, -}: Readonly<{ - nextStep: () => void; - formData: ProposalFormData; - dispatch: React.Dispatch; - address: string; -}>) { - const router = useRouter(); - const policyAddress = router.query.policyAddress as string; - const [isContactsOpen, setIsContactsOpen] = useState(false); - - const updateField = (field: keyof ProposalFormData, value: any) => { - dispatch({ type: 'UPDATE_FIELD', field, value }); - }; - - return ( -
- - {({ isValid, setFieldValue, handleChange }) => ( - <> - { - setFieldValue('proposers', selectedAddress); - updateField('proposers', selectedAddress); - setIsContactsOpen(false); - }} - /> - -
-
-
-

- Proposal details -

-
- ) => { - updateField('title', e.target.value); - handleChange(e); - }} - /> - ) => { - updateField('proposers', e.target.value); - handleChange(e); - }} - rightElement={ - - } - /> -