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

From Pre prod to Main backend fix #52

Merged
merged 4 commits into from
Dec 5, 2024
Merged
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
31 changes: 28 additions & 3 deletions backend/src/api/proposal/controllers/proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
/**
* proposal controller
*/
const {Address,RewardAddress} = require("@emurgo/cardano-serialization-lib-nodejs");

const { createCoreController } = require("@strapi/strapi").factories;

const { createCoreController } = require("@strapi/strapi").factories;
async function isRewardAddress(address) {
try {
const stake = RewardAddress.from_address(Address.from_bech32(address));
return stake ? true : false;
} catch (e) {
return false;
}
}
module.exports = createCoreController(
"api::proposal.proposal",
({ strapi }) => ({
Expand All @@ -22,7 +31,7 @@ module.exports = createCoreController(
}

/////GOV ACTION TYPE///////////
const hasGovActionTypeIDFilter = ctx?.query?.filters["$and"]?.find(
const hasGovActionTypeIDFilter = sanitizedQueryParams.filters["$and"]?.find(
(elem) => elem?.hasOwnProperty("gov_action_type_id")
);

Expand Down Expand Up @@ -255,8 +264,24 @@ module.exports = createCoreController(
return ctx.badRequest(null, "Proposal content not deleted");
}
};

try {
// chek if treasuiry action have adress and amount
const gaTypes = await strapi.entityService.findOne("api::governance-action-type.governance-action-type",data?.gov_action_type_id)

if(gaTypes.gov_action_type_name === 'Treasury')
{
// check if withdrawal parameters exist
if (data?.proposal_withdrawals?.length === 0) {
return ctx.badRequest(null, "Withdrawal parametars not exist");
}
// Check if data is invalid
const isInvalid = await Promise.all(data.proposal_withdrawals.map(async (item) => {
return !(await isRewardAddress(item.prop_receiving_address)) || !item.prop_amount || item.prop_amount <= 0;
})).then(results => results.some(result => result));
if(isInvalid)
return ctx.badRequest(null, "Withdrawal addrress or amount parametars not valid");
}
// Create the Proposal
try {
proposal = await strapi.entityService.create(
Expand Down
Loading