Skip to content

Commit

Permalink
Hotfix: Proclamation creation (#700)
Browse files Browse the repository at this point in the history
* Fix dependencies

* Fix race condition
  • Loading branch information
tiltom authored Nov 28, 2023
1 parent e24befa commit f9c3795
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export const NewProposalForm: FC = () => {
setStep,
type: proposalType,
setType: setProposalType,
details,
setDetails,
submit,
} = useProposalContext();
const [isPreview, setIsPreview] = useState(false);
Expand Down Expand Up @@ -89,8 +87,6 @@ export const NewProposalForm: FC = () => {
if (step === ProposalCreationStep.Details) {
return (
<ProposalDataForm
value={details}
onChange={setDetails}
proposalType={proposalType}
onBack={() => setStep(ProposalCreationStep.SelectType)}
onPreview={handlePreview}
Expand All @@ -102,15 +98,13 @@ export const NewProposalForm: FC = () => {

return null;
}, [
details,
handleBack,
handlePreview,
handleSubmit,
setProposalType,
isConfirmButtonDisabled,
isPreview,
proposalType,
setDetails,
setStep,
step,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import { defaultChainId } from '../../../../../../../config/chains';
import { translations } from '../../../../../../../locales/i18n';
import { validateURL } from '../../../../../../../utils/helpers';
import { useProposalContext } from '../../../../contexts/NewProposalContext';
import {
ProposalCreationDetails,
ProposalCreationType,
} from '../../../../contexts/ProposalContext.types';
import { ProposalCreationType } from '../../../../contexts/ProposalContext.types';
import { Governor } from '../../NewProposalForm.types';
import {
MAXIMUM_SUMMARY_LENGTH,
Expand All @@ -45,8 +42,6 @@ import { generateFormGroupLabel } from './ProposalDataForm.utils';
const ACTIVE_CLASSNAME = 'text-primary-20';

export type ProposalDataFormProps = {
value: ProposalCreationDetails;
onChange: (value: ProposalCreationDetails) => void;
proposalType: ProposalCreationType;
onBack: () => void;
onSubmit: () => void;
Expand All @@ -55,32 +50,33 @@ export type ProposalDataFormProps = {
};

export const ProposalDataForm: FC<ProposalDataFormProps> = ({
value,
onChange,
proposalType,
onBack,
onSubmit,
onPreview,
updateConfirmButtonState,
}) => {
const [form, setForm] = useState<ProposalCreationDetails>(value);
const { setGovernor } = useProposalContext();
const {
setGovernor,
details: form,
setDetails: setForm,
} = useProposalContext();
const [governorOwner, setGovernorOwner] = useState('');
const [index, setIndex] = useState(0);
const handleInputChangeInput = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
setForm(prevForm => ({ ...prevForm, [name]: value }));
},
[],
[setForm],
);

const handleInputChangeTextarea = useCallback(
(event: ChangeEvent<HTMLTextAreaElement>) => {
const { name, value } = event.target;
setForm(prevForm => ({ ...prevForm, [name]: value }));
},
[],
[setForm],
);

const isValidUrl = useMemo(() => validateURL(form.link), [form.link]);
Expand All @@ -98,19 +94,16 @@ export const ProposalDataForm: FC<ProposalDataFormProps> = ({
}, [isSubmitDisabled, proposalType, updateConfirmButtonState]);

const handleBack = useCallback(() => {
onChange(form);
onBack();
}, [form, onBack, onChange]);
}, [onBack]);

const handleSubmit = useCallback(() => {
onChange(form);
onSubmit();
}, [form, onChange, onSubmit]);
}, [onSubmit]);

const handlePreview = useCallback(() => {
onChange(form);
onPreview();
}, [form, onChange, onPreview]);
}, [onPreview]);

const tabs = useMemo(
() => [
Expand Down Expand Up @@ -143,10 +136,6 @@ export const ProposalDataForm: FC<ProposalDataFormProps> = ({
[form.text, handleInputChangeTextarea],
);

useEffect(() => {
setForm(value);
}, [value]);

useEffect(() => {
if (proposalType === ProposalCreationType.Proclamation && !governorOwner) {
getProtocolContract(Governor.Owner, defaultChainId).then(owner => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ export const ProposalContextProvider: FC<PropsWithChildren> = ({
setIsOpen(true);
},
[
type,
details,
signer,
governor,
parameters,
signer,
type,
details.title,
details.link,
details.summary,
details.text,
setTitle,
setTransactions,
setIsOpen,
Expand Down

0 comments on commit f9c3795

Please sign in to comment.