Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix join now #92

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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