From 1fba4465dc2187d604cc37ba371cd53b0d526744 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 Date: Tue, 9 Apr 2024 21:35:49 +0530 Subject: [PATCH] fixed remove action on members page --- .../widget/DAO/Members/MembersGroup.jsx | 2 +- .../widget/DAO/Members/index.jsx | 337 +++++++++--------- 2 files changed, 169 insertions(+), 170 deletions(-) diff --git a/apps/astraplusplus/widget/DAO/Members/MembersGroup.jsx b/apps/astraplusplus/widget/DAO/Members/MembersGroup.jsx index 322fb9c..62c343c 100644 --- a/apps/astraplusplus/widget/DAO/Members/MembersGroup.jsx +++ b/apps/astraplusplus/widget/DAO/Members/MembersGroup.jsx @@ -23,7 +23,7 @@ const RolesColor = rolesArray.map((item, i) => { const onRemoveUserProposal = (memberId, roleId) => { Near.call([ { - contractName: daoId, + contractName: props.daoId, methodName: "add_proposal", args: { proposal: { diff --git a/apps/astraplusplus/widget/DAO/Members/index.jsx b/apps/astraplusplus/widget/DAO/Members/index.jsx index 56d2f60..becf6cd 100644 --- a/apps/astraplusplus/widget/DAO/Members/index.jsx +++ b/apps/astraplusplus/widget/DAO/Members/index.jsx @@ -4,215 +4,214 @@ const baseApi = "https://api.pikespeak.ai"; let voters = []; const CoADaoId = props.dev - ? "/*__@replace:CoADaoIdTesting__*/" - : "/*__@replace:CoADaoId__*/"; + ? "/*__@replace:CoADaoIdTesting__*/" + : "/*__@replace:CoADaoId__*/"; const VotingBodyDaoId = props.dev - ? "/*__@replace:VotingBodyDaoIdTesting__*/" - : "/*__@replace:VotingBodyDaoId__*/"; + ? "/*__@replace:VotingBodyDaoIdTesting__*/" + : "/*__@replace:VotingBodyDaoId__*/"; const TCDaoId = props.dev - ? "/*__@replace:TCDaoIdTesting__*/" - : "/*__@replace:TCDaoId__*/"; + ? "/*__@replace:TCDaoIdTesting__*/" + : "/*__@replace:TCDaoId__*/"; const HoMDaoId = props.dev - ? "/*__@replace:HoMDaoIdTesting__*/" - : "/*__@replace:HoMDaoId__*/"; + ? "/*__@replace:HoMDaoIdTesting__*/" + : "/*__@replace:HoMDaoId__*/"; const isCongressDaoID = - daoId === HoMDaoId || daoId === CoADaoId || daoId === TCDaoId; + daoId === HoMDaoId || daoId === CoADaoId || daoId === TCDaoId; function fetchIsHuman(account) { - const userSBTs = Near.view("registry.i-am-human.near", "is_human", { - account: account + const userSBTs = Near.view("registry.i-am-human.near", "is_human", { + account: account + }); + let isHuman = false; + if (userSBTs) { + userSBTs.forEach((sbt) => { + if ("fractal.i-am-human.near" === sbt[0]) { + isHuman = true; + } }); - let isHuman = false; - if (userSBTs) { - userSBTs.forEach((sbt) => { - if ("fractal.i-am-human.near" === sbt[0]) { - isHuman = true; - } - }); - } - return isHuman; + } + return isHuman; } function fetchIsUserFollowed(account) { - const followEdge = Social.keys( - `${context.accountId}/graph/follow/${account}`, - undefined, - { - values_only: true - } - ); - return Object.keys(followEdge || {}).length > 0; + const followEdge = Social.keys( + `${context.accountId}/graph/follow/${account}`, + undefined, + { + values_only: true + } + ); + return Object.keys(followEdge || {}).length > 0; } function addNonVotedMembers() { - if (!policy?.users) { - return; + if (!policy?.users) { + return; + } + Object.keys(policy.users)?.map((item) => { + const index = voters.findIndex((d) => d.account === item); + if (index === -1) { + voters.push({ + account: item, + groups: policy.users?.[item], + approve: 0, + rejected: 0, + isHuman: fetchIsHuman(item), + isUserFollowed: fetchIsUserFollowed(item) + }); } - Object.keys(policy.users)?.map((item) => { - const index = voters.findIndex((d) => d.account === item); - if (index === -1) { - voters.push({ - account: item, - groups: policy.users?.[item], - approve: 0, - rejected: 0, - isHuman: fetchIsHuman(item), - isUserFollowed: fetchIsUserFollowed(item) - }); - } - }); + }); } function fetchVotes() { - const res = fetch(`${baseApi}/daos/votes/${daoId}`, { - method: "GET", - mode: "cors", - headers: { - "Content-Type": "application/json", - "x-api-key": publicApiKey + const res = fetch(`${baseApi}/daos/votes/${daoId}`, { + method: "GET", + mode: "cors", + headers: { + "Content-Type": "application/json", + "x-api-key": publicApiKey + } + }); + + if (res?.body?.length) { + res?.body?.map((item) => { + item.voters?.map((voterData) => { + const accountIndex = voters.findIndex( + (d) => d.account === voterData.account + ); + if (accountIndex !== -1) { + voters[accountIndex] = { + ...voters[accountIndex], + rejected: voters[accountIndex].rejected + voterData.rejected, + approve: voters[accountIndex].approve + voterData.approve + }; + } else { + voters.push({ + ...voterData, + isHuman: fetchIsHuman(voterData.account), + isUserFollowed: fetchIsUserFollowed(voterData.account) + }); } + }); }); - - if (res?.body?.length) { - res?.body?.map((item) => { - item.voters?.map((voterData) => { - const accountIndex = voters.findIndex( - (d) => d.account === voterData.account - ); - if (accountIndex !== -1) { - voters[accountIndex] = { - ...voters[accountIndex], - rejected: - voters[accountIndex].rejected + voterData.rejected, - approve: - voters[accountIndex].approve + voterData.approve - }; - } else { - voters.push({ - ...voterData, - isHuman: fetchIsHuman(voterData.account), - isUserFollowed: fetchIsUserFollowed(voterData.account) - }); - } - }); - }); - // if any member have not voted on any proposal their data is not their in voters API - if (policy?.users) { - addNonVotedMembers(); - } - } else { - addNonVotedMembers(); + // if any member have not voted on any proposal their data is not their in voters API + if (policy?.users) { + addNonVotedMembers(); } + } else { + addNonVotedMembers(); + } } const processPolicy = (policy) => { - const obj = { - policy, - users: {}, - roles: {}, - everyone: {} - }; - policy.roles.forEach((role) => { - if (role.kind === "Everyone") { - obj.everyone = role; - } - if (role.kind.Group) { - if (!obj.roles[role.name]) { - obj.roles[role.name] = role; - } - role.kind.Group.forEach((user) => { - if (!obj.users[user]) { - obj.users[user] = []; - } - - obj.users[user].push(role.name); - }); + const obj = { + policy, + users: {}, + roles: {}, + everyone: {} + }; + policy.roles.forEach((role) => { + if (role.kind === "Everyone") { + obj.everyone = role; + } + if (role.kind.Group) { + if (!obj.roles[role.name]) { + obj.roles[role.name] = role; + } + role.kind.Group.forEach((user) => { + if (!obj.users[user]) { + obj.users[user] = []; } - }); - return obj; + obj.users[user].push(role.name); + }); + } + }); + + return obj; }; function processCongressMembers(members) { - let group = ""; - switch (daoId) { - case HoMDaoId: - group = "HoM Members"; - break; - case CoADaoId: - group = "CoA Members"; - break; - - case TCDaoId: - group = "Transparency Commission Members"; - break; - } - const obj = { - policy, - users: {}, - roles: { - [group]: { - permissions: members?.permissions - } - }, - everyone: {} - }; - - members?.members?.map((item) => { - obj.users[item] = [group]; - }); - return obj; + let group = ""; + switch (daoId) { + case HoMDaoId: + group = "HoM Members"; + break; + case CoADaoId: + group = "CoA Members"; + break; + + case TCDaoId: + group = "Transparency Commission Members"; + break; + } + const obj = { + policy, + users: {}, + roles: { + [group]: { + permissions: members?.permissions + } + }, + everyone: {} + }; + + members?.members?.map((item) => { + obj.users[item] = [group]; + }); + return obj; } const policy = isCongressDaoID - ? useCache( - () => - Near.asyncView(daoId, "get_members").then((members) => - processCongressMembers(members) - ), - daoId + "-processed_congress_policy", - { subscribe: false } - ) - : daoId === VotingBodyDaoId - ? null - : useCache( - () => - Near.asyncView(daoId, "get_policy").then((policy) => - processPolicy(policy) - ), - daoId + "-processed_policy", - { subscribe: false } - ); + ? useCache( + () => + Near.asyncView(daoId, "get_members").then((members) => + processCongressMembers(members) + ), + daoId + "-processed_congress_policy", + { subscribe: false } + ) + : daoId === VotingBodyDaoId + ? null + : useCache( + () => + Near.asyncView(daoId, "get_policy").then((policy) => + processPolicy(policy) + ), + daoId + "-processed_policy", + { subscribe: false } + ); if (policy === null) return ""; fetchVotes(); const Wrapper = styled.div` - .userRow { - width: 100%; - @media screen and (min-width: 600px) { - width: calc(50% - 1rem); - } - @media screen and (min-width: 1400px) { - width: calc(33% - 1rem); - } + .userRow { + width: 100%; + @media screen and (min-width: 600px) { + width: calc(50% - 1rem); + } + @media screen and (min-width: 1400px) { + width: calc(33% - 1rem); } + } `; return ( -
- - - -
+
+ + + +
);