Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion backend/src/api/proxy/controllers/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
method = "GET",
data = {},
params = {},
headers = {},
headers = { "User-Agent": "govtool-proxy" },
} = ctx.request.body;
const response = await axios({ url, method, data, params, headers });
ctx.send({ status: response.status, data: response.data });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const ConstitutionManager = ({
}) => {
const theme = useTheme();

console.log(proposalData);

useEffect(() => {
if (proposalData?.proposal_constitution_content?.data?.attributes) {
setProposalData({
...proposalData,
proposal_constitution_content:
proposalData.proposal_constitution_content.data.attributes,
});
} else {
return;
}
}, [proposalData]);

const togglePropHhaveGuScript = (checked) => {
let pk = proposalData.proposal_constitution_content;
pk.prop_have_guardrails_script = checked;
Expand Down Expand Up @@ -41,7 +55,10 @@ const ConstitutionManager = ({
const handleUrlChange = (url_text) => {
constcheckLinkValue(url_text, 'prop_constitution_url');
let pk = { ...proposalData.proposal_constitution_content }
? { ...proposalData.proposal_constitution_content }
? {
...proposalData.proposal_constitution_content?.data
?.attributes,
}
: {};
pk.prop_constitution_url = url_text;
setProposalData({ ...proposalData, proposal_constitution_content: pk });
Expand Down Expand Up @@ -88,7 +105,9 @@ const ConstitutionManager = ({
};

useEffect(() => {
let pk = proposalData.proposal_constitution_content;
let pk =
proposalData.proposal_constitution_content ||
proposalData.data?.attributes?.proposal_constitution_content;
if (pk != undefined) {
if (Boolean(pk.prop_constitution_url))
constcheckLinkValue(
Expand Down
32 changes: 18 additions & 14 deletions pdf-ui/src/components/EditProposalDialog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const EditProposalDialog = ({
setIsSaveDisabled(false);
}
}
if (draft?.gov_action_type_id == 6) {
if (draft?.gov_action_type_id == 6) {
if (
draft?.proposal_hard_fork_content?.major == '' ||
draft?.proposal_hard_fork_content?.minor == '' ||
Expand All @@ -177,8 +177,8 @@ const EditProposalDialog = ({
// draft.proposal_hard_fork_content.previous_ga_hash = draft.proposal_hard_fork_content.data.attributes.previous_ga_hash
// draft.proposal_hard_fork_content.previous_ga_id = draft.proposal_hard_fork_content.data.attributes.previous_ga_id
// draft.proposal_hard_fork_content.major = draft.proposal_hard_fork_content.data.attributes.major
// draft.proposal_hard_fork_content.minor = draft.proposal_hard_fork_content.data.attributes.minor
// // delete draft.proposal_hard_fork_content.data
// draft.proposal_hard_fork_content.minor = draft.proposal_hard_fork_content.data.attributes.minor
// // delete draft.proposal_hard_fork_content.data
// setDraftData(draft)
// }

Expand Down Expand Up @@ -246,8 +246,7 @@ const EditProposalDialog = ({
?.proposal_constitution_content,
proposal_hard_fork_content:
proposalData?.attributes?.content?.attributes
?.proposal_hard_fork_content
|| {},
?.proposal_hard_fork_content || {},
};
return draft;
};
Expand Down Expand Up @@ -313,14 +312,17 @@ const EditProposalDialog = ({
}

try {
let payload = {...draft, proposal_hard_fork_content :
{
previous_ga_hash : draft.proposal_hard_fork_content.previous_ga_hash,
previous_ga_id : draft.proposal_hard_fork_content.previous_ga_id,
major : draft.proposal_hard_fork_content.major,
minor : draft.proposal_hard_fork_content.minor
}
}
let payload = {
...draft,
proposal_hard_fork_content: {
previous_ga_hash:
draft.proposal_hard_fork_content.previous_ga_hash,
previous_ga_id:
draft.proposal_hard_fork_content.previous_ga_id,
major: draft.proposal_hard_fork_content.major,
minor: draft.proposal_hard_fork_content.minor,
},
};
const response = await createProposalContent({
...payload,
...proposalConentObj,
Expand Down Expand Up @@ -413,6 +415,9 @@ const EditProposalDialog = ({
open={openEditDialog}
onClose={handleCloseEditDialog}
data-testid='edit-proposal-dialog'
PaperProps={{
sx: { borderRadius: 0 },
}}
>
<Box height={'100%'} position={'relative'}>
<Grid
Expand Down Expand Up @@ -907,7 +912,6 @@ const EditProposalDialog = ({
}
isEdit={true}
/>

) : null
}
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
GovernanceActionSubmittedModal,
InsufficientBallanceModal,
} from '../../../components/SubmissionGovernanceAction';
import { updateProposalContent } from '../../../lib/api';
import { getViaProxy, updateProposalContent } from '../../../lib/api';
import {
isValidURLFormat,
isValidURLLength,
Expand Down Expand Up @@ -256,25 +256,24 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
if (!url) {
throw new Error('url is not defined or null');
}
// Fetch the data from the URL
const response = await fetch(url, {
'User-Agent': 'govtool-agent',
});
// Check if the response is successful
if (!response.ok) {
const response = await getViaProxy('', { url: url, method: 'GET' });
console.log('🚀 ~ getHashFromUrl ~ response:', response);
if (response.status !== 200) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
// Read the text content from the response
const content = await response.text();
// Create a hash from the fetched content
const content =
typeof response.data === 'string'
? response.data
: JSON.stringify(response.data);
const urlHash = await walletAPI.createHash(content);
return urlHash;
} catch (error) {
console.error('Error fetching or hashing the content:', error);
throw error; // Re-throw the error if you want to handle it further up the call stack
alert(
`Error fetching data from URL: Please verify that the URL is publicly accessible and try again.`
);
throw error;
}
}

useEffect(() => {
if (proposal && walletAPI) {
handleCreateGAJsonLD();
Expand Down
10 changes: 10 additions & 0 deletions pdf-ui/src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,3 +599,13 @@ export const getHardForkData = async () => {
throw error;
}
};

export const getViaProxy = async (endpoint = '', payload) => {
try {
const { data } = await axiosInstance.post(`/api/proxy`, payload);
return data;
} catch (error) {
console.error('Error posting data via govtool proxy:', error);
throw error;
}
};