Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CreateProposalTemplateForm into generic ProposalBuilder #1524

Merged
merged 20 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2fdb0fc
Refactor CreateProposalTemplateForm into ProposalBuilder and make it …
mudrila Apr 8, 2024
9fd2565
Prettier
mudrila Apr 8, 2024
392eeea
Eliminate CreateProposal and use ProposalBuilder instead
mudrila Apr 8, 2024
2285855
Merge pull request #1527 from decentdao/hotfix/20240408-templatehash-…
adamgall Apr 8, 2024
6b0aade
Fix problem with missing bigNumberValue during prepareProposal
mudrila Apr 8, 2024
ac192ff
Explicitly set bigNumberValue to null while creating proposal templat…
mudrila Apr 8, 2024
e3ff66b
Do not type amountInputValue and value on BigNumberInput with explici…
mudrila Apr 9, 2024
520fe1d
Transform ProposalBuilderMode into enum
mudrila Apr 9, 2024
ee0d4fd
Prettier
mudrila Apr 9, 2024
4fa08c6
If signature is empty - do not call encodeFunction but simply return …
mudrila Apr 9, 2024
6886d70
Validate based on function name and not signature. If function name n…
mudrila Apr 9, 2024
43025de
Merge pull request #1529 from decentdao/feature/#1513-allow-proposal-…
mudrila Apr 9, 2024
b26a222
Rearrange order of types in useGetMultisigMetadata
mudrila Apr 9, 2024
c2b60ee
Merge pull request #1525 from decentdao/feature/#1363-use-proposal-bu…
mudrila Apr 9, 2024
537b744
Merge remote-tracking branch 'origin/feature/#1363-generic-templates-…
mudrila Apr 11, 2024
50dfaaa
Merge pull request #1528 from decentdao/hotfix/eth-value
mudrila Apr 11, 2024
278dcf9
Update src/i18n/locales/en/proposal.json
mudrila Apr 14, 2024
b2c1780
Merge branch 'develop' into feature/#1363-generic-templates-builder
mudrila Apr 14, 2024
db9e409
Fix import
mudrila Apr 14, 2024
b9514d9
Prettier
mudrila Apr 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormikProps } from 'formik';
import { Fragment, PropsWithChildren } from 'react';
import { useTranslation } from 'react-i18next';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../constants/common';
import { CreateProposalTemplateForm } from '../../types/createProposalTemplate';
import { CreateProposalForm } from '../../types/proposalBuilder';
import Markdown from '../ui/proposal/Markdown';
import '../../assets/css/Markdown.css';

Expand All @@ -29,10 +29,10 @@ export function TransactionValueContainer({
}

export default function ProposalTemplateDetails({
values: { proposalTemplateMetadata, transactions },
}: FormikProps<CreateProposalTemplateForm>) {
values: { proposalMetadata, transactions },
}: FormikProps<CreateProposalForm>) {
const { t } = useTranslation(['proposalTemplate', 'proposal']);
const trimmedTitle = proposalTemplateMetadata.title?.trim();
const trimmedTitle = proposalMetadata.title?.trim();

return (
<Box
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function ProposalTemplateDetails({
<HStack justifyContent="space-between">
<Text color="grayscale.500">{t('proposalTemplateDescription')}</Text>
<Markdown
content={proposalTemplateMetadata.description}
content={proposalMetadata.description}
collapsedLines={2}
/>
</HStack>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { Button, Divider, VStack } from '@chakra-ui/react';
import { FormikProps } from 'formik';
import { useTranslation } from 'react-i18next';
import {
CreateProposalTemplateForm,
CreateProposalTemplateFormState,
} from '../../types/createProposalTemplate';
import { CreateProposalState } from '../../types';
import { CreateProposalForm } from '../../types/proposalBuilder';
import { InputComponent, TextareaComponent } from '../ui/forms/InputComponent';

export interface ProposalTemplateMetadataProps extends FormikProps<CreateProposalTemplateForm> {
setFormState: (state: CreateProposalTemplateFormState) => void;
export interface ProposalMetadataProps extends FormikProps<CreateProposalForm> {
setFormState: (state: CreateProposalState) => void;
}

export default function ProposalTemplateMetadata({
values: { proposalTemplateMetadata },
export default function ProposalMetadata({
values: { proposalMetadata },
setFieldValue,
errors: { proposalTemplateMetadata: proposalTemplateMetadataError },
errors: { proposalMetadata: proposalMetadataError },
setFormState,
}: ProposalTemplateMetadataProps) {
}: ProposalMetadataProps) {
const { t } = useTranslation(['proposalTemplate', 'common']);

return (
Expand All @@ -30,8 +28,8 @@ export default function ProposalTemplateMetadata({
label={t('proposalTemplateTitle')}
helper={t('proposalTemplateTitleHelperText')}
isRequired
value={proposalTemplateMetadata.title}
onChange={e => setFieldValue('proposalTemplateMetadata.title', e.target.value)}
value={proposalMetadata.title}
onChange={e => setFieldValue('proposalMetadata.title', e.target.value)}
disabled={false}
testId="metadata.title"
maxLength={50}
Expand All @@ -41,8 +39,8 @@ export default function ProposalTemplateMetadata({
subLabel={t('')}
helper={t('proposalTemplateDescriptionHelperText')}
isRequired={false}
value={proposalTemplateMetadata.description}
onChange={e => setFieldValue('proposalTemplateMetadata.description', e.target.value)}
value={proposalMetadata.description}
onChange={e => setFieldValue('proposalMetadata.description', e.target.value)}
disabled={false}
rows={12}
/>
Expand All @@ -54,8 +52,8 @@ export default function ProposalTemplateMetadata({
/>
<Button
w="100%"
onClick={() => setFormState(CreateProposalTemplateFormState.TRANSACTIONS_FORM)}
isDisabled={!!proposalTemplateMetadataError || !proposalTemplateMetadata.title}
onClick={() => setFormState(CreateProposalState.TRANSACTIONS_FORM)}
isDisabled={!!proposalMetadataError || !proposalMetadata.title}
>
{t('next', { ns: 'common' })}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ import { VStack, HStack, Text, Box, Flex, IconButton } from '@chakra-ui/react';
import { AddPlus, Minus } from '@decent-org/fractal-ui';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { CreateProposalTemplateTransaction } from '../../types/createProposalTemplate';
import { CreateProposalTransaction } from '../../types/proposalBuilder';
import ABISelector, { ABIElement } from '../ui/forms/ABISelector';
import ExampleLabel from '../ui/forms/ExampleLabel';
import { BigNumberComponent, InputComponent } from '../ui/forms/InputComponent';
import { DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION } from './constants';
import { DEFAULT_PROPOSAL_TRANSACTION } from './constants';

interface ProposalTemplateTransactionProps {
transaction: CreateProposalTemplateTransaction;
interface ProposalTransactionProps {
transaction: CreateProposalTransaction;
transactionIndex: number;
transactionPending: boolean;
txAddressError?: string;
txFunctionError?: string;
setFieldValue: (field: string, value: any, shouldValidate?: boolean | undefined) => void;
}

export default function ProposalTemplateTransaction({
export default function ProposalTransaction({
transaction,
transactionIndex,
transactionPending,
txAddressError,
txFunctionError,
setFieldValue,
}: ProposalTemplateTransactionProps) {
}: ProposalTransactionProps) {
const { t } = useTranslation(['proposal', 'proposalTemplate', 'common']);
const handleABISelectorChange = useCallback(
(value: ABIElement) => {
Expand Down Expand Up @@ -123,7 +123,7 @@ export default function ProposalTemplateTransaction({
onClick={() =>
setFieldValue(`transactions.${transactionIndex}.parameters`, [
...transaction.parameters,
DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION,
DEFAULT_PROPOSAL_TRANSACTION,
])
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,22 @@ import { FormikErrors, FormikProps } from 'formik';
import { Dispatch, SetStateAction } from 'react';
import { useTranslation } from 'react-i18next';
import { BigNumberValuePair } from '../../types';
import {
CreateProposalTemplateForm,
CreateProposalTemplateTransaction,
} from '../../types/createProposalTemplate';
import ProposalTemplateTransaction from './ProposalTemplateTransaction';
import { CreateProposalForm, CreateProposalTransaction } from '../../types/proposalBuilder';
import ProposalTransaction from './ProposalTransaction';

interface ProposalTemplateTransactionsProps extends FormikProps<CreateProposalTemplateForm> {
interface ProposalTransactionsProps extends FormikProps<CreateProposalForm> {
pendingTransaction: boolean;
expandedIndecies: number[];
setExpandedIndecies: Dispatch<SetStateAction<number[]>>;
}
export default function ProposalTemplateTransactions({
export default function ProposalTransactions({
values: { transactions },
errors,
setFieldValue,
pendingTransaction,
expandedIndecies,
setExpandedIndecies,
}: ProposalTemplateTransactionsProps) {
}: ProposalTransactionsProps) {
const { t } = useTranslation(['proposal', 'proposalTemplate', 'common']);

const removeTransaction = (transactionIndex: number) => {
Expand All @@ -46,7 +43,7 @@ export default function ProposalTemplateTransactions({
>
{transactions.map((_, index) => {
const txErrors = errors?.transactions?.[index] as
| FormikErrors<CreateProposalTemplateTransaction<BigNumberValuePair>>
| FormikErrors<CreateProposalTransaction<BigNumberValuePair>>
| undefined;
const txAddressError = txErrors?.targetAddress;
const txFunctionError = txErrors?.functionName;
Expand Down Expand Up @@ -101,8 +98,8 @@ export default function ProposalTemplateTransactions({
)}
</HStack>
<AccordionPanel p={0}>
<ProposalTemplateTransaction
transaction={transactions[index]}
<ProposalTransaction
transaction={transactions[index] as CreateProposalTransaction}
txFunctionError={txFunctionError}
txAddressError={txAddressError}
transactionIndex={index}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ import { Info } from '@decent-org/fractal-ui';
import { FormikProps } from 'formik';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
CreateProposalTemplateForm,
CreateProposalTemplateFormState,
} from '../../types/createProposalTemplate';
import { CreateProposalState } from '../../types';
import { CreateProposalForm } from '../../types/proposalBuilder';
import { scrollToBottom } from '../../utils/ui';
import ProposalTemplateTransactions from './ProposalTemplateTransactions';
import { DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION } from './constants';
import ProposalTransactions from './ProposalTransactions';
import { DEFAULT_PROPOSAL_TRANSACTION } from './constants';

interface ProposalTemplateTransactionsFormProps extends FormikProps<CreateProposalTemplateForm> {
interface ProposalTransactionsFormProps extends FormikProps<CreateProposalForm> {
pendingTransaction: boolean;
setFormState: (state: CreateProposalTemplateFormState) => void;
setFormState: (state: CreateProposalState) => void;
canUserCreateProposal?: boolean;
safeNonce?: number;
}

export default function ProposalTemplateTransactionsForm(
props: ProposalTemplateTransactionsFormProps,
) {
export default function ProposalTransactionsForm(props: ProposalTransactionsFormProps) {
const {
pendingTransaction,
setFormState,
Expand All @@ -41,7 +37,7 @@ export default function ProposalTemplateTransactionsForm(

return (
<Box>
<ProposalTemplateTransactions
<ProposalTransactions
expandedIndecies={expandedIndecies}
setExpandedIndecies={setExpandedIndecies}
{...props}
Expand All @@ -54,7 +50,7 @@ export default function ProposalTemplateTransactionsForm(
<Button
variant="text"
onClick={() => {
setFieldValue('transactions', [...transactions, DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION]);
setFieldValue('transactions', [...transactions, DEFAULT_PROPOSAL_TRANSACTION]);
setExpandedIndecies([transactions.length]);
scrollToBottom();
}}
Expand Down Expand Up @@ -85,7 +81,7 @@ export default function ProposalTemplateTransactionsForm(
textStyle="text-md-mono-regular"
color="gold.500"
cursor="pointer"
onClick={() => setFormState(CreateProposalTemplateFormState.METADATA_FORM)}
onClick={() => setFormState(CreateProposalState.METADATA_FORM)}
mb={4}
>
{t('back', { ns: 'common' })}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CreateProposalTemplateTransaction } from '../../types/createProposalTemplate';
import { CreateProposalTransaction } from '../../types/proposalBuilder';

export const DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION: CreateProposalTemplateTransaction = {
export const DEFAULT_PROPOSAL_TRANSACTION: CreateProposalTransaction = {
targetAddress: '',
ethValue: { value: '', bigNumberValue: undefined },
functionName: '',
Expand All @@ -15,9 +15,9 @@ export const DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION: CreateProposalTemplateTransa

export const DEFAULT_PROPOSAL_TEMPLATE = {
nonce: undefined,
proposalTemplateMetadata: {
proposalMetadata: {
title: '',
description: '',
},
transactions: [DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION],
transactions: [DEFAULT_PROPOSAL_TRANSACTION],
};
Loading