From 5bd18cc1271efa702b33cd4a4eeac181c12dbdea Mon Sep 17 00:00:00 2001 From: Sam Keen Date: Fri, 19 May 2023 16:19:28 +0100 Subject: [PATCH] feat(governance): avoid showing untitled proposals (#3851) --- .../proposal-header.spec.tsx | 2 +- .../proposal-detail-header/proposal-header.tsx | 15 +++++++++++++-- .../propose/freeform/propose-freeform.tsx | 9 ++++++++- .../propose-network-parameter.tsx | 9 ++++++++- .../propose/new-asset/propose-new-asset.tsx | 9 ++++++++- .../propose/new-market/propose-new-market.tsx | 9 ++++++++- .../propose/update-asset/propose-update-asset.tsx | 9 ++++++++- .../update-market/propose-update-market.tsx | 9 ++++++++- 8 files changed, 62 insertions(+), 9 deletions(-) diff --git a/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.spec.tsx b/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.spec.tsx index e64433d03..fa65d4748 100644 --- a/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.spec.tsx +++ b/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.spec.tsx @@ -124,7 +124,7 @@ describe('Proposal header', () => { }) ); expect(screen.getByTestId('proposal-title')).toHaveTextContent( - 'Unknown proposal' + 'New asset proposal' ); expect(screen.getByTestId('proposal-type')).toHaveTextContent('New asset'); expect(screen.getByTestId('proposal-details')).toHaveTextContent( diff --git a/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.tsx b/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.tsx index 3e029c429..854444e8c 100644 --- a/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.tsx +++ b/apps/governance/src/routes/proposals/components/proposal-detail-header/proposal-header.tsx @@ -21,6 +21,7 @@ export const ProposalHeader = ({ let details: ReactNode; let proposalType = ''; + let fallbackTitle = ''; const title = proposal?.rationale.title.trim(); @@ -29,6 +30,7 @@ export const ProposalHeader = ({ switch (change?.__typename) { case 'NewMarket': { proposalType = 'NewMarket'; + fallbackTitle = t('NewMarketProposal'); details = ( <> @@ -50,6 +52,7 @@ export const ProposalHeader = ({ } case 'UpdateMarket': { proposalType = 'UpdateMarket'; + fallbackTitle = t('UpdateMarketProposal'); details = ( <> {t('Market change')}:{' '} @@ -60,6 +63,7 @@ export const ProposalHeader = ({ } case 'NewAsset': { proposalType = 'NewAsset'; + fallbackTitle = t('NewAssetProposal'); details = ( <> {t('Symbol')}: {change.symbol}.{' '} @@ -81,6 +85,7 @@ export const ProposalHeader = ({ } case 'UpdateNetworkParameter': { proposalType = 'NetworkParameter'; + fallbackTitle = t('NetworkParameterProposal'); details = ( <> {t('Change')}:{' '} @@ -95,11 +100,13 @@ export const ProposalHeader = ({ } case 'NewFreeform': { proposalType = 'Freeform'; + fallbackTitle = t('FreeformProposal'); details = ; break; } case 'UpdateAsset': { proposalType = 'UpdateAsset'; + fallbackTitle = t('UpdateAssetProposal'); details = ( <> {t('AssetID')}:{' '} @@ -115,10 +122,14 @@ export const ProposalHeader = ({
{isListItem ? (
- +
) : ( - + )}
diff --git a/apps/governance/src/routes/proposals/propose/freeform/propose-freeform.tsx b/apps/governance/src/routes/proposals/propose/freeform/propose-freeform.tsx index dd9673684..124bd9709 100644 --- a/apps/governance/src/routes/proposals/propose/freeform/propose-freeform.tsx +++ b/apps/governance/src/routes/proposals/propose/freeform/propose-freeform.tsx @@ -49,6 +49,7 @@ export const ProposeFreeform = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -85,7 +86,13 @@ export const ProposeFreeform = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)), diff --git a/apps/governance/src/routes/proposals/propose/network-parameter/propose-network-parameter.tsx b/apps/governance/src/routes/proposals/propose/network-parameter/propose-network-parameter.tsx index 3d164ba26..a03ea85cf 100644 --- a/apps/governance/src/routes/proposals/propose/network-parameter/propose-network-parameter.tsx +++ b/apps/governance/src/routes/proposals/propose/network-parameter/propose-network-parameter.tsx @@ -89,6 +89,7 @@ export const ProposeNetworkParameter = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -148,7 +149,13 @@ export const ProposeNetworkParameter = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)), diff --git a/apps/governance/src/routes/proposals/propose/new-asset/propose-new-asset.tsx b/apps/governance/src/routes/proposals/propose/new-asset/propose-new-asset.tsx index a8647704c..f5ce50976 100644 --- a/apps/governance/src/routes/proposals/propose/new-asset/propose-new-asset.tsx +++ b/apps/governance/src/routes/proposals/propose/new-asset/propose-new-asset.tsx @@ -61,6 +61,7 @@ export const ProposeNewAsset = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -117,7 +118,13 @@ export const ProposeNewAsset = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)), diff --git a/apps/governance/src/routes/proposals/propose/new-market/propose-new-market.tsx b/apps/governance/src/routes/proposals/propose/new-market/propose-new-market.tsx index 34bedc606..f659ea703 100644 --- a/apps/governance/src/routes/proposals/propose/new-market/propose-new-market.tsx +++ b/apps/governance/src/routes/proposals/propose/new-market/propose-new-market.tsx @@ -59,6 +59,7 @@ export const ProposeNewMarket = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -107,7 +108,13 @@ export const ProposeNewMarket = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)), diff --git a/apps/governance/src/routes/proposals/propose/update-asset/propose-update-asset.tsx b/apps/governance/src/routes/proposals/propose/update-asset/propose-update-asset.tsx index 0e76980c6..77004c00a 100644 --- a/apps/governance/src/routes/proposals/propose/update-asset/propose-update-asset.tsx +++ b/apps/governance/src/routes/proposals/propose/update-asset/propose-update-asset.tsx @@ -59,6 +59,7 @@ export const ProposeUpdateAsset = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -107,7 +108,13 @@ export const ProposeUpdateAsset = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)), diff --git a/apps/governance/src/routes/proposals/propose/update-market/propose-update-market.tsx b/apps/governance/src/routes/proposals/propose/update-market/propose-update-market.tsx index 4e6fc54cf..867a24fac 100644 --- a/apps/governance/src/routes/proposals/propose/update-market/propose-update-market.tsx +++ b/apps/governance/src/routes/proposals/propose/update-market/propose-update-market.tsx @@ -106,6 +106,7 @@ export const ProposeUpdateMarket = () => { formState: { errors }, setValue, watch, + trigger, } = useForm(); const { finalizedProposal, submit, Dialog } = useProposalSubmit(); @@ -157,7 +158,13 @@ export const ProposeUpdateMarket = () => { await submit(assembleProposal(fields)); }; - const viewJson = () => { + const viewJson = async () => { + const isValid = await trigger(); + + if (!isValid) { + return; + } + const formData = watch(); downloadJson( JSON.stringify(assembleProposal(formData)),