Skip to content

Commit

Permalink
Merge pull request #26 from RamboGj/fix-join-now
Browse files Browse the repository at this point in the history
Validating if user is community or council member
  • Loading branch information
elliotBraem authored Jan 13, 2024
2 parents 5e23690 + 402e154 commit fe4cbfd
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const CTASection = styled.div`

const userWidgets = Social.keys(`${context.accountId}/widget/**`) || [];

const { Bullet } = VM.require("buildhub.near/widget/components.Bullet")

const daoId = "build.sputnik-dao.near";
const accountId = context.accountId;

Expand All @@ -147,12 +149,19 @@ const policy = Near.view(daoId, "get_policy");
if (policy === null) {
return "";
}
const alreadyJoinedRolesNames = ["community", "council"];

const deposit = policy.proposal_bond;
const roleId = "community";

const group = policy.roles
.filter((role) => role.name === roleId)
.map((role) => role.kind.Group);
.filter((role) => alreadyJoinedRolesNames.includes(role.name))
.map((role) => {
return role.kind.Group;
});

const accounts = new Set(group[0].concat(group[1]));

const isCommunityOrCouncilMember = accounts.has(accountId);

const proposalId = Near.view(daoId, "get_last_proposal_id") - 1;

Expand All @@ -165,8 +174,7 @@ if (proposal === null) {
return "";
}

// check if the potential member submitted last proposal
const canJoin = accountId && accountId !== proposal.proposer;
const canJoin = accountId && accountId !== proposal.proposer && !isCommunityOrCouncilMember

const groupMembers = group.join(", ");

Expand Down Expand Up @@ -234,9 +242,9 @@ const CreateSomethingView = (props) => {
/>
) : (
<>
<span className={!validMember ? "pending" : "joined"}>
<Bullet variant={!validMember ? "default" : "light"}>
{!validMember ? "Pending..." : "Joined"}
</span>
</Bullet>
<a href={"/feed"}>
View Activity{" "}
<svg
Expand Down
40 changes: 40 additions & 0 deletions apps/builddao/widget/components/Bullet.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { theme } = VM.require("rambo-dev.near/widget/ThemeProvider");

const StyledBullet = styled.div`
width: fit-content;
display: flex;
justify-content: center;
align-items: center;
padding: 4px 12px;
font-family: Aeonik, sans-serif;
font-size: 0.875rem;
font-weight: 500;
border-radius: 8px;
${({ variant, theme }) => {
const isDefault = variant === "default";
const background = isDefault
? theme.colors.blue500
: theme.colors.seablue500;
const color = isDefault ? theme.colors.blue500 : theme.colors.seablue500;
const border = `1px solid ${background}33`;
return `
background: ${background}33;
color: ${color};
border: ${border};
`;
}}
`;

function Bullet({ children, variant }) {
const defaultVariant = variant || "default";

return (
<StyledBullet theme={theme} variant={defaultVariant}>
{children}
</StyledBullet>
);
}

return { Bullet };
20 changes: 20 additions & 0 deletions apps/builddao/widget/components/ThemeProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const colors = {
yellow500: "#FFAF51",
seablue500: "#51FFEA",
blue500: "#51B6FF",
bg1: "#0B0C14",
bg2: "#23242B",
black100: "#000000",
black50: "Black/50",
white100: "#FFFFFF",
white50: "White/50",
error: "#FD2A5C",
success: "#38C793",
warning: "#F17B2C",
};

Storage.set("theme", { colors });

const theme = Storage.get("theme");

return { theme };
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
const daoId = "build.sputnik-dao.near";
const accountId = context.accountId;
const alreadyJoinedRolesNames = ["community", "council"];
const searchRange = 100;

// get DAO policy, deposit, and group
const policy = Near.view(daoId, "get_policy");

const lastProposalId = Near.view(daoId, "get_last_proposal_id") - 1;

const lastProposals = Near.view(daoId, "get_proposals", {
from_index: lastProposalId - searchRange,
limit: searchRange,
}) || [];

const alreadyMadeAProposal =
lastProposals.filter((proposal) => {
return proposal.proposer === accountId;
}).length > 0;

if (policy === null) {
return "";
}

const deposit = policy.proposal_bond;
const roleId = "community";
const group = policy.roles
.filter((role) => role.name === roleId)
.map((role) => role.kind.Group);

const proposalId = Near.view(daoId, "get_last_proposal_id") - 1;
const group = policy.roles
.filter((role) => alreadyJoinedRolesNames.includes(role.name))
.map((role) => {
return role.kind.Group;
});

// get data from last proposal
const proposal = Near.view(daoId, "get_proposal", {
id: proposalId,
});
const accounts = new Set(group[0].concat(group[1]));

if (proposal === null) {
return "";
}
const isCommunityOrCouncilMember = accounts.has(accountId);

// check if the potential member submitted last proposal
const canJoin = accountId && accountId !== proposal.proposer;
const canJoin =
accountId && !alreadyMadeAProposal && !isCommunityOrCouncilMember;

const Button = styled.a`
width: max-content;
Expand Down
33 changes: 10 additions & 23 deletions src/components/navigation/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,15 @@ export function Navbar(props) {
</NavLink>
</div>
<div className="d-none d-md-block flex-grow-1" style={{ flexBasis: 0 }}>
{!props.signedIn && (
<button
className="sign-in"
style={{ width: "max-content", marginLeft: "auto" }}
onClick={props.requestSignIn}
>
Sign In
</button>
)}
{props.signedIn && (
<div>
<Widget
src="buildhub.near/widget/components.button.join-now"
config={{
redirectMap: redirectStore.redirectMap,
}}
props={{
children: <UserDropdown {...props} />,
}}
/>
</div>
)}
<Widget
src="buildhub.near/widget/components.buttons.JoinNow"
config={{
redirectMap: redirectStore.redirectMap,
}}
props={{
children: <UserDropdown {...props} />,
}}
/>
</div>
<div className="d-block d-md-none">
<MobileDropdownButton onClick={toggleDropdown}>
Expand Down Expand Up @@ -271,7 +258,7 @@ export function Navbar(props) {
{props.signedIn && (
<div>
<Widget
src="buildhub.near/widget/components.button.join-now"
src="buildhub.near/widget/components.buttons.JoinNow"
config={{
redirectMap: redirectStore.redirectMap,
}}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/JoinPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function JoinPage(props) {
const redirectMapStore = useBosLoaderStore();

const CurrentView = props.signedIn
? "buildhub.near/widget/create-something"
? "buildhub.near/widget/JoinSection"
: "buildhub.near/widget/login";

return (
Expand Down

0 comments on commit fe4cbfd

Please sign in to comment.