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

Upload to ipfs via backend #2589

Merged
merged 10 commits into from
Apr 7, 2022
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"@ant-design/icons": "^4.5.0",
"@davatar/react": "^1.8.1",
"@ethersproject/providers": "^5.5.2",
"@feathersjs/authentication-client": "^4.5.11",
"@feathersjs/feathers": "^4.5.11",
"@feathersjs/rest-client": "^4.5.11",
"@feathersjs/authentication-client": "^4.5.13",
"@feathersjs/feathers": "^4.5.12",
"@feathersjs/rest-client": "^4.5.12",
"@feathersjs/socketio-client": "^4.5.13",
"@giveth/bridge-contract": "^1.0.6",
"@giveth/liquidpledging-contract": "^2.0.0-beta.6",
"@giveth/lpp-campaign": "^2.0.0-beta.1",
Expand All @@ -23,7 +24,6 @@
"bnc-onboard": "^1.29.0",
"feathers-hooks-common": "^5.0.5",
"feathers-reactive": "^0.8.2",
"feathers-socketio": "^2.0.1",
"file-saver": "^2.0.5",
"history": "^4.9.0",
"jwt-decode": "^3.1.2",
Expand Down Expand Up @@ -100,7 +100,7 @@
"author": {
"name": "Giveth",
"email": "info@giveth.io",
"url": "http://giveth.io"
"url": "https://giveth.io"
},
"license": "GPL-3.0",
"browserslist": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function Editor(props) {
quill.setSelection(range.index + 1);
quill.disable();

saveToServer(e.target.result, range);
saveToServer(file, range);
imageUploader.current.value = '';
};
reader.readAsDataURL(compressFile);
Expand Down
3 changes: 0 additions & 3 deletions src/components/UploadPicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ const UploadPicture = ({ picture, setPicture, imgAlt, disabled, aspectRatio, lab
},
onChange(info) {
const { status } = info.file;
if (status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (status === 'done') {
console.log('file uploaded successfully.', info.file.response);
setPicture(info.file.response);
Expand Down
14 changes: 10 additions & 4 deletions src/components/views/CreateBounty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ function CreateBounty(props) {
const [loading, setLoading] = useState(false);
const [userIsCampaignOwner, setUserIsOwner] = useState(false);

function goBack() {
history.goBack();
}

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

setUserIsOwner(
campaign &&
currentUser.address &&
Expand All @@ -67,10 +77,6 @@ function CreateBounty(props) {
});
}

function goBack() {
history.goBack();
}

const submit = async () => {
const authenticated = await authenticateUser(currentUser, false, web3);

Expand Down
6 changes: 6 additions & 0 deletions src/components/views/CreateExpense.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ function CreateExpense(props) {
const itemAmountMap = useRef({});

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

if (currentUser.address && !expenseForm.recipientAddress) {
setExpenseForm({
...expenseForm,
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/CreateMilestone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function CreateMilestone(props) {
const [userIsCampaignOwner, setUserIsOwner] = useState(false);

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

setUserIsOwner(
campaign &&
currentUser.address &&
Expand Down
8 changes: 7 additions & 1 deletion src/components/views/CreatePayment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Context as UserContext } from '../../contextProviders/UserProvider';
import { Context as ConversionRateContext } from '../../contextProviders/ConversionRateProvider';
import { Context as Web3Context } from '../../contextProviders/Web3Provider';
import { Context as NotificationContext } from '../../contextProviders/NotificationModalProvider';
import { convertEthHelper, getStartOfDayUTC, ZERO_ADDRESS } from '../../lib/helpers';
import { convertEthHelper, getStartOfDayUTC, ZERO_ADDRESS, history } from '../../lib/helpers';
import ErrorHandler from '../../lib/ErrorHandler';
import { authenticateUser } from '../../lib/middleware';
import BridgedTrace from '../../models/BridgedTrace';
Expand Down Expand Up @@ -108,6 +108,12 @@ function CreatePayment(props) {
}, []);

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

if (currentUser.address && !payment.recipientAddress) {
setPayment({
...payment,
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/EditBounty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ function EditBounty(props) {
};

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

if (trace) {
setUserIsOwner(
[campaign.ownerAddress, campaign.coownerAddress].includes(currentUser.address),
Expand Down
105 changes: 53 additions & 52 deletions src/components/views/EditCampaign.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,63 +68,64 @@ const EditCampaign = () => {
}, []);

useEffect(() => {
if (userIsLoading || whitelistIsLoading || !currentUser.address) return () => {};

if (isNew) {
if (!currentUser.isProjectOwner && projectOwnersWhitelistEnabled) {
const modal = Modal.error({
title: 'Permission Denied',
content: 'You are not allowed to create a campaign',
closable: false,
centered: true,
onOk: () => history.replace('/'),
});

return () => {
modal.destroy();
};
const checks = async () => {
const authenticated = await authenticateUser(currentUser, false, web3);
if (!authenticated) {
goBack();
return;
}

checkProfile(currentUser).then(() => {
setCampaign({
owner: currentUser,
ownerAddress: currentUser.address,
});
setIsLoading(false);
});
} else {
CampaignService.get(campaignId)
.then(camp => {
if (isOwner(camp.ownerAddress, currentUser)) {
const imageIpfsPath = camp.image.match(/\/ipfs\/.*/);
if (isNew) {
if (!currentUser.isProjectOwner && projectOwnersWhitelistEnabled) {
Modal.error({
title: 'Permission Denied',
content: 'You are not allowed to create a campaign',
closable: false,
centered: true,
onOk: () => history.replace('/'),
});
} else
checkProfile(currentUser).then(() => {
setCampaign({
title: camp.title,
description: camp.description,
communityUrl: camp.communityUrl,
reviewerAddress: camp.reviewerAddress,
picture: imageIpfsPath ? imageIpfsPath[0] : camp.image,
owner: currentUser,
ownerAddress: currentUser.address,
});
campaignObject.current = camp;
setIsLoading(false);
} else {
ErrorHandler({}, 'You are not allowed to edit this Campaign.');
goBack();
}
})
.catch(err => {
if (err.status === 404) {
history.push('/notfound');
} else {
setIsLoading(false);
ErrorHandler(
err,
'There has been a problem loading the Campaign. Please refresh the page and try again.',
);
}
});
}
});
} else {
CampaignService.get(campaignId)
.then(camp => {
if (isOwner(camp.ownerAddress, currentUser)) {
const imageIpfsPath = camp.image.match(/\/ipfs\/.*/);
setCampaign({
title: camp.title,
description: camp.description,
communityUrl: camp.communityUrl,
reviewerAddress: camp.reviewerAddress,
picture: imageIpfsPath ? imageIpfsPath[0] : camp.image,
});
campaignObject.current = camp;
setIsLoading(false);
} else {
ErrorHandler({}, 'You are not allowed to edit this Campaign.');
goBack();
}
})
.catch(err => {
if (err.status === 404) {
history.push('/notfound');
} else {
setIsLoading(false);
ErrorHandler(
err,
'There has been a problem loading the Campaign. Please refresh the page and try again.',
);
}
});
}
};

return () => {};
if (userIsLoading || whitelistIsLoading || !currentUser.address) return;
checks().then();
}, [userIsLoading, currentUser, whitelistIsLoading]);

// TODO: Check if user Changes (in Class components checked in didUpdate)
Expand Down
109 changes: 56 additions & 53 deletions src/components/views/EditCommunity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,65 +69,68 @@ const EditCommunity = ({ isNew, match }) => {
}, []);

useEffect(() => {
if (userIsLoading || whitelistIsLoading || !currentUser.address) return () => {};

if (isNew) {
if (!currentUser.isDelegator && projectOwnersWhitelistEnabled) {
const modal = Modal.error({
title: 'Permission Denied',
content: 'You are not allowed to create a Community',
closable: false,
centered: true,
onOk: () => history.replace('/'),
});

return () => {
modal.destroy();
};
const checks = async () => {
const authenticated = await authenticateUser(currentUser, false, web3);
if (!authenticated) {
goBack();
return;
}

checkProfile(currentUser).then(() => {
setCommunity({
owner: currentUser,
ownerAddress: currentUser.address,
});
setIsLoading(false);
});
} else {
CommunityService.get(match.params.id)
.then(communityItem => {
if (isOwner(communityItem.ownerAddress, currentUser)) {
if (isNew) {
if (!currentUser.isDelegator && projectOwnersWhitelistEnabled) {
Modal.error({
title: 'Permission Denied',
content: 'You are not allowed to create a Community',
closable: false,
centered: true,
onOk: () => history.replace('/'),
});
} else {
checkProfile(currentUser).then(() => {
setCommunity({
title: communityItem.title,
description: communityItem.description,
communityUrl: communityItem.communityUrl,
id: match.params.id,
slug: communityItem.slug,
reviewerAddress: communityItem.reviewerAddress,
ownerAddress: communityItem.ownerAddress,
picture: communityItem.image.match(/\/ipfs\/.*/)[0],
owner: currentUser,
ownerAddress: currentUser.address,
});
communityObject.current = communityItem;
setIsLoading(false);
} else {
ErrorHandler({}, 'You are not allowed to edit this Community.');
goBack();
}
})
.catch(err => {
if (err.status === 404) {
history.push('/notfound');
} else {
setIsLoading(false);
ErrorHandler(
err,
'There has been a problem loading the Community. Please refresh the page and try again.',
);
}
});
}
});
}
} else {
CommunityService.get(match.params.id)
.then(communityItem => {
if (isOwner(communityItem.ownerAddress, currentUser)) {
setCommunity({
title: communityItem.title,
description: communityItem.description,
communityUrl: communityItem.communityUrl,
id: match.params.id,
slug: communityItem.slug,
reviewerAddress: communityItem.reviewerAddress,
ownerAddress: communityItem.ownerAddress,
picture: communityItem.image.match(/\/ipfs\/.*/)[0],
});
communityObject.current = communityItem;
setIsLoading(false);
} else {
ErrorHandler({}, 'You are not allowed to edit this Community.');
goBack();
}
})
.catch(err => {
if (err.status === 404) {
history.push('/notfound');
} else {
setIsLoading(false);
ErrorHandler(
err,
'There has been a problem loading the Community. Please refresh the page and try again.',
);
}
});
}
};

return () => {};
if (userIsLoading || whitelistIsLoading || !currentUser.address) return;
checks().then();
}, [userIsLoading, currentUser, whitelistIsLoading]);

// TODO: Check if user Changes (in Class components checked in didUpdate)
Expand Down
6 changes: 6 additions & 0 deletions src/components/views/EditExpense.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ function EditExpense(props) {
};

useEffect(() => {
if (currentUser.address) {
authenticateUser(currentUser, false, web3).then(auth => {
if (!auth) history.goBack();
});
}

if (trace) {
setUserIsOwner(
[campaign.ownerAddress, campaign.coownerAddress].includes(currentUser.address),
Expand Down
Loading