Skip to content

Commit 89b0975

Browse files
Merge pull request #331 from IntersectMBO/fix/-Submitting-Governance-Action-with-IPFS-Metadata-URL-Fails-Due-to-Unsupported-URL-Scheme-(#3979)
Fix/ submitting governance action with ipfs metadata url fails due to unsupported url scheme (#3979)
2 parents 00f15a6 + 0b81cf2 commit 89b0975

File tree

4 files changed

+63
-38
lines changed

4 files changed

+63
-38
lines changed

pdf-ui/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
As a minor extension, we also keep a semantic version for the `UNRELEASED`
99
changes.
1010

11+
## [v1.0.10-beta](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/1.0.10-beta) 2025-07-29
12+
- Submitting Governance Action with IPFS Metadata URL Fails Due to Unsupported URL Scheme #3979
13+
1114
## [v1.0.9-beta](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/1.0.9-beta) 2025-07-03
1215
- Support IPFS Links for Governance Action Submissions #3851
1316

pdf-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@intersect.mbo/pdf-ui",
3-
"version": "1.0.9-beta",
3+
"version": "1.0.10-beta",
44
"description": "Proposal discussion ui",
55
"main": "./src/index.js",
66
"exports": {

pdf-ui/src/components/SubmissionGovernanceAction/Steps/InformationStorageStep.jsx

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { IconExternalLink } from '@intersect.mbo/intersectmbo.org-icons-set';
3131
import { useTheme } from '@emotion/react';
3232

3333
const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
34-
3534
const theme = useTheme();
3635
const navigate = useNavigate();
3736
const { walletAPI, validateMetadata } = useAppContext();
@@ -112,12 +111,17 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
112111
const hash = await walletAPI.createHash(jsonLd);
113112
setHashData(hash);
114113
};
115-
const proposalGATypeId= proposal?.attributes?.content?.attributes.gov_action_type_id;
114+
const proposalGATypeId =
115+
proposal?.attributes?.content?.attributes.gov_action_type_id;
116116
const handleGASubmission = async () => {
117117
try {
118+
let url = fileURL;
118119
setCheckingDataModal(true);
120+
if (fileURL.startsWith('ipfs://')) {
121+
url = `https://ipfs.io/ipfs/${fileURL.replace('ipfs://', '')}`;
122+
}
119123
const response = await validateMetadata({
120-
url: fileURL,
124+
url: url,
121125
hash: hashData,
122126
standard: 'CIP108',
123127
});
@@ -135,43 +139,52 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
135139
await walletAPI.buildTreasuryGovernanceAction({
136140
hash: hashData,
137141
url: fileURL,
138-
withdrawals: getWithdrawalsArray()
142+
withdrawals: getWithdrawalsArray(),
139143
});
140-
}
141-
else if (parseInt(proposalGATypeId) === 3)
142-
{
143-
const constitUrl = proposal?.attributes?.content?.attributes.proposal_constitution_content.data.attributes.prop_constitution_url;
144+
} else if (parseInt(proposalGATypeId) === 3) {
145+
const constitUrl =
146+
proposal?.attributes?.content?.attributes
147+
.proposal_constitution_content.data.attributes
148+
.prop_constitution_url;
144149
const constiUrlHash = await getHashFromUrl(constitUrl);
145150
govActionBuilder =
146-
await walletAPI.buildNewConstitutionGovernanceAction({
147-
hash: hashData,
148-
url: fileURL,
149-
constitutionUrl: constitUrl,
150-
constitutionHash: constiUrlHash
151-
//prevGovernanceActionHash: string;
152-
//prevGovernanceActionIndex: number;
153-
//scriptHash: string;
154-
});
155-
}
156-
else if(parseInt(proposalGATypeId) === 4)
157-
{ ///Motion of No Confidence
158-
govActionBuilder =
159-
await walletAPI.buildNoConfidenceGovernanceAction({
151+
await walletAPI.buildNewConstitutionGovernanceAction({
160152
hash: hashData,
161153
url: fileURL,
154+
constitutionUrl: constitUrl,
155+
constitutionHash: constiUrlHash,
156+
//prevGovernanceActionHash: string;
157+
//prevGovernanceActionIndex: number;
158+
//scriptHash: string;
162159
});
163-
}
164-
else if(parseInt(proposalGATypeId) === 6)
165-
{ ///Hard Fork Initiation
160+
} else if (parseInt(proposalGATypeId) === 4) {
161+
///Motion of No Confidence
166162
govActionBuilder =
167-
await walletAPI.buildHardForkInitiationGovernanceActions({
168-
prevGovernanceActionHash: proposal?.attributes?.content?.attributes?.proposal_hard_fork_content.previous_ga_hash,
169-
prevGovernanceActionIndex: proposal?.attributes?.content?.attributes?.proposal_hard_fork_content.previous_ga_id,
170-
major: proposal?.attributes?.content?.attributes?.proposal_hard_fork_content.major,
171-
minor: proposal?.attributes?.content?.attributes?.proposal_hard_fork_content.minor,
163+
await walletAPI.buildNoConfidenceGovernanceAction({
172164
hash: hashData,
173165
url: fileURL,
174166
});
167+
} else if (parseInt(proposalGATypeId) === 6) {
168+
///Hard Fork Initiation
169+
govActionBuilder =
170+
await walletAPI.buildHardForkInitiationGovernanceActions(
171+
{
172+
prevGovernanceActionHash:
173+
proposal?.attributes?.content?.attributes
174+
?.proposal_hard_fork_content
175+
.previous_ga_hash,
176+
prevGovernanceActionIndex:
177+
proposal?.attributes?.content?.attributes
178+
?.proposal_hard_fork_content
179+
.previous_ga_id,
180+
major: proposal?.attributes?.content?.attributes
181+
?.proposal_hard_fork_content.major,
182+
minor: proposal?.attributes?.content?.attributes
183+
?.proposal_hard_fork_content.minor,
184+
hash: hashData,
185+
url: fileURL,
186+
}
187+
);
175188
}
176189

177190
if (govActionBuilder) {
@@ -212,12 +225,17 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
212225

213226
const getWithdrawalsArray = () => {
214227
let withdrawalsArray = [];
215-
let x = proposal?.attributes?.content?.attributes?.proposal_withdrawals.forEach((withdrawal) =>
216-
{
217-
withdrawalsArray.push({receivingAddress:withdrawal.prop_receiving_address,amount:withdrawal.prop_amount.toString()})
218-
});
228+
let x =
229+
proposal?.attributes?.content?.attributes?.proposal_withdrawals.forEach(
230+
(withdrawal) => {
231+
withdrawalsArray.push({
232+
receivingAddress: withdrawal.prop_receiving_address,
233+
amount: withdrawal.prop_amount.toString(),
234+
});
235+
}
236+
);
219237
return withdrawalsArray;
220-
}
238+
};
221239

222240
const handleDownloadJsonLD = () => {
223241
const blob = new Blob([JSON.stringify(jsonLdData, null, 2)], {
@@ -239,7 +257,9 @@ const InformationStorageStep = ({ proposal, handleCloseSubmissionDialog }) => {
239257
throw new Error('url is not defined or null');
240258
}
241259
// Fetch the data from the URL
242-
const response = (await fetch(url,{'User-Agent': "govtool-agent"}));
260+
const response = await fetch(url, {
261+
'User-Agent': 'govtool-agent',
262+
});
243263
// Check if the response is successful
244264
if (!response.ok) {
245265
throw new Error(`HTTP error! Status: ${response.status}`);

pdf-ui/src/lib/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export function isValidURLLength(s) {
6464
}
6565

6666
export const openInNewTab = (url) => {
67-
if (!url.startsWith('http://') && !url.startsWith('https://')) {
67+
if (url.startsWith('ipfs://')) {
68+
url = `https://ipfs.io/ipfs/${url.replace('ipfs://', '')}`;
69+
} else if (!url.startsWith('http://') && !url.startsWith('https://')) {
6870
url = 'https://' + url;
6971
}
7072
const newWindow = window.open(url, '_blank', 'noopener,noreferrer');

0 commit comments

Comments
 (0)