Skip to content

Commit

Permalink
call proposal-status to get proposalEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiacodes committed Aug 1, 2024
1 parent 76a9d42 commit a95c82b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
30 changes: 30 additions & 0 deletions server/helpers/proposal-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fetch from 'node-fetch';

export async function getProposalStatus(id: string, space: string) {
const devUrl = 'https://develop.thelao.io/api/v1/governance/proposal-status';
const prodUrl = 'https://thelao.io/api/v1/governance/proposal-status';

const env = process.env.ENV;
const endpoint = env === 'prod' ? prodUrl : devUrl;

try {
const proposalStatus = await fetch(endpoint, {
method: 'POST',
body: JSON.stringify([{ id, space }]),
headers: {
'Content-Type': 'application/json'
}
});

if (!proposalStatus.ok) {
throw new Error(
`Something went wrong while fetching the proposals status for ${id} ${space}`
);
}

return await proposalStatus.json();
} catch (error) {
console.error(error);
return [];
}
}
7 changes: 6 additions & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
} from './helpers/adapters/postgres';
import pkg from '../package.json';
import db from './helpers/postgres';
import { getProposalStatus } from './helpers/proposal-status';

/**
* Values to insert into the `events` database.
Expand Down Expand Up @@ -453,9 +454,13 @@ router.post('/message', async (req, res) => {
const { payload: payloadToParse } = proposals[0];
const payload = jsonParse(payloadToParse, payloadToParse);

const proposalStatus = await getProposalStatus(payload.proposalId, space);
const proposalEnd =
proposalStatus.length > 0 ? proposalStatus[0].proposalEnd : payload.end;

const isNotInVotingWindow: boolean = ignoreVoteEndConstraint
? payload.start > ts
: ts > payload.end || payload.start > ts;
: ts > proposalEnd || payload.start > ts;

if (isNotInVotingWindow) return sendError(res, 'not in voting window');

Expand Down

0 comments on commit a95c82b

Please sign in to comment.