Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Megha-Dev-19 committed Oct 13, 2024
1 parent 40043e6 commit 4cf23f8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
49 changes: 24 additions & 25 deletions apps/astraplusplus/widget/DAO/Proposals/Card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ if (isHuman === null) {
const policy = isCongressDaoID
? Near.view(daoId, "get_members")
: isVotingBodyDao
? ""
: Near.view(daoId, "get_policy");
? ""
: Near.view(daoId, "get_policy");
let roles = policy;

function getPreVoteVotes(supported) {
Expand Down Expand Up @@ -276,10 +276,10 @@ const expensiveWork = () => {
typeof my_proposal.kind === "string"
? my_proposal.kind
: isCongressDaoID || isVotingBodyDao
? Object.keys(my_proposal.kind)[0]
: typeof my_proposal.kind.typeEnum === "string"
? my_proposal.kind.typeEnum
: Object.keys(my_proposal.kind)[0];
? Object.keys(my_proposal.kind)[0]
: typeof my_proposal.kind.typeEnum === "string"
? my_proposal.kind.typeEnum
: Object.keys(my_proposal.kind)[0];

const isAllowedToVote = isVotingBodyDao
? [isHuman, isHuman, isHuman, isHuman]
Expand All @@ -294,31 +294,30 @@ const expensiveWork = () => {
let totalVotesNeeded = 0;

if (policy?.roles) {
policy.roles.forEach((role) => {
// Determine if the role is eligible for the given proposalType
const isRoleAllowedToVote =
const groupWithPermissions = policy.roles.filter(
(role) =>
// Determine if the role is eligible for the given proposalType
role.permissions.includes(`${proposalKinds[kindName]}:VoteApprove`) ||
role.permissions.includes(`${proposalKinds[kindName]}:VoteReject`) ||
role.permissions.includes(`${proposalKinds[kindName]}:*`) ||
role.permissions.includes(`*:VoteApprove`) ||
role.permissions.includes(`*:VoteReject`) ||
role.permissions.includes("*:*");

if (isRoleAllowedToVote) {
const threshold = (role.vote_policy &&
role.vote_policy[proposalKinds[kindName]]?.threshold) ||
policy["default_vote_policy"]?.threshold || [0, 0];
const eligibleVoters = role.kind.Group ? role.kind.Group.length : 0;

// Apply the threshold
if (eligibleVoters === 0) {
return;
}
const votesNeeded =
Math.floor((threshold[0] / threshold[1]) * eligibleVoters) + 1;

totalVotesNeeded += votesNeeded;
role.permissions.includes("*:*")
);
groupWithPermissions.map((role) => {
const threshold = (role.vote_policy &&
role.vote_policy[proposalKinds[kindName]]?.threshold) ||
policy["default_vote_policy"]?.threshold || [0, 0];
const eligibleVoters = role.kind.Group ? role.kind.Group.length : 0;

// Apply the threshold
if (eligibleVoters === 0) {
return;
}
const votesNeeded =
Math.floor((threshold[0] / threshold[1]) * eligibleVoters) + 1;

totalVotesNeeded += votesNeeded;
});
}
my_proposal.typeName = kindName.replace(/([A-Z])/g, " $1").trim(); // Add spaces between camelCase
Expand Down
19 changes: 18 additions & 1 deletion apps/astraplusplus/widget/DAO/Proposals/ProposalsPikespeak.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ State.init({
multiSelectMode: defaultMultiSelectMode ?? false,
tableView: defaultTableView ?? false,
daoConfig: null,
tab: "active"
tab: "active",
sputnikProposalsLastCount: null
});

if (
Expand Down Expand Up @@ -131,6 +132,12 @@ function fetchCongressDaoProposals() {
return data;
}

useEffect(() => {
Near.asyncView(daoId, "get_last_proposal_id", {}).then((resp) => {
State.update({ sputnikProposalsLastCount: resp - 1 });
});
}, [daoId]);

function fetchDaoProposals() {
const resp = fetch(
forgeUrl(apiUrl, {
Expand Down Expand Up @@ -377,6 +384,16 @@ return (
</div>
) : (
<>
{!state.filters.proposal_types.length &&
!state.filters.status.length &&
res?.body?.[0] &&
res.body[0].proposal_id < state.sputnikProposalsLastCount && (
<div className="alert alert-danger mt-4" role="alert">
The Pikespeak indexer is currently delayed. New proposals have
been created, so please check back later for an updated proposals
feed.
</div>
)}
{isVotingBodyDao && (
<div className="w-100 mt-2">
<Widget
Expand Down

0 comments on commit 4cf23f8

Please sign in to comment.