Skip to content

Commit

Permalink
Merge pull request #92 from Megha-Dev-19/fix-join-now
Browse files Browse the repository at this point in the history
Fix join now
  • Loading branch information
elliotBraem authored Jan 24, 2024
2 parents d13a7c1 + 980b3c3 commit 94b818e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 38 deletions.
46 changes: 10 additions & 36 deletions apps/builddao/widget/components/buttons/JoinNow.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
const daoId = "build.sputnik-dao.near";
const accountId = context.accountId;
const alreadyJoinedRolesNames = ["community", "council"];
const searchRange = 100;

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 group = policy.roles
.filter((role) => alreadyJoinedRolesNames.includes(role.name))
.map((role) => {
return role.kind.Group;
});

const accounts = new Set(group[0].concat(group[1]));
const { checkIsMemberOrPending } = VM.require(
"buildhub.near/widget/core.lib.common"
);

const isCommunityOrCouncilMember = accounts.has(accountId);
checkIsMemberOrPending || (checkIsMemberOrPending = () => {});

const canJoin =
(accountId && !isCommunityOrCouncilMember )|| (accountId && !alreadyMadeAProposal);
const isMemberOrPending = checkIsMemberOrPending(context.accountId);

const Button = styled.a`
width: max-content;
Expand Down Expand Up @@ -83,6 +53,10 @@ const Container = styled.div`

return (
<Container>
{canJoin ? <Button href={"/join"}>Join Now</Button> : props.children}
{!isMemberOrPending ? (
<Button href={"/join"}>Join Now</Button>
) : (
props.children
)}
</Container>
);
37 changes: 37 additions & 0 deletions apps/builddao/widget/core/lib/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// checks if the user is already dao's community/council member or has an active proposal
const checkIsMemberOrPending = (accountId) => {
const daoId = "build.sputnik-dao.near";
if (!accountId) {
return false;
}
const alreadyJoinedRolesNames = ["community", "council"];
const searchRange = 100;

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

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

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

policy.roles
.filter((role) => alreadyJoinedRolesNames.includes(role.name))
.map((role) => {
if (Array.isArray(role.kind.Group) && !isDaoMember) {
isDaoMember = role.kind.Group.includes(accountId);
}
});
return isDaoMember || alreadyMadeAProposal;
};

return { checkIsMemberOrPending };
10 changes: 9 additions & 1 deletion apps/builddao/widget/section/cta.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const { checkIsMemberOrPending } = VM.require(
"buildhub.near/widget/core.lib.common"
);

checkIsMemberOrPending || (checkIsMemberOrPending = () => {});

const isMemberOrPending = checkIsMemberOrPending(context.accountId);

const logoLink =
"https://ipfs.near.social/ipfs/bafkreihbwho3qfvnu4yss3eh5jrx6uxhrlzdgtdjyzyjrpa6odro6wdxya";
const gridLink =
Expand Down Expand Up @@ -133,7 +141,7 @@ return (
<Card>
<Logo src={logoLink} />
<h1>Together, we can build a better future.</h1>
<a href="/join">Join Now</a>
{!isMemberOrPending && <a href="/join">Join Now</a>}
</Card>
<Grid src={gridLink} />
<LeftBlur src={leftBlur} />
Expand Down
10 changes: 9 additions & 1 deletion apps/builddao/widget/section/join.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const { checkIsMemberOrPending } = VM.require(
"buildhub.near/widget/core.lib.common"
);

checkIsMemberOrPending || (checkIsMemberOrPending = () => {});

const isMemberOrPending = checkIsMemberOrPending(context.accountId);

const SectionPill = ({ title, icon }) => {
const Pill = styled.div`
display: flex;
Expand Down Expand Up @@ -356,7 +364,7 @@ return (
<br />
3. Fulfill contribution requirements
</p>
<a href="/join">Join Now</a>
{!isMemberOrPending && <a href="/join">Join Now</a>}
</CTAContent>
</CTAContainer>
</JoinContainer>
Expand Down

0 comments on commit 94b818e

Please sign in to comment.