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 proposals navigation w/o proposalId #41

Merged
merged 1 commit into from
Feb 14, 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
193 changes: 95 additions & 98 deletions apps/astraplusplus/widget/DAO/Proposals/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,122 +3,119 @@ const proposalId = props.proposalId;
const accountId = context.accountId ?? "";

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;

State.init({
isProposalModalOpen: false,
hideProposalBtn: false
isProposalModalOpen: false,
hideProposalBtn: false
});

if (proposalId) {
return (
<div>
<Widget
src="/*__@appAccount__*//widget/DAO.Proposals.Card.index"
props={props}
/>
</div>
);
return (
<div>
<Widget
src="/*__@appAccount__*//widget/DAO.Proposals.Card.index"
props={props}
/>
</div>
);
}

if (isCongressDaoID) {
const policy = Near.view(daoId, "get_members");
const isMember = policy?.members?.includes(accountId);
State.update({ hideProposalBtn: !isMember });
const policy = Near.view(daoId, "get_members");
const isMember = policy?.members?.includes(accountId);
State.update({ hideProposalBtn: !isMember });
}

if (daoId === VotingBodyDaoId) {
const resp = useCache(
() =>
asyncFetch(
`https://api.pikespeak.ai/sbt/sbt-by-owner?holder=${accountId}&registry=registry.i-am-human.near`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
"x-api-key": "/*__@replace:pikespeakApiKey__*/"
}
}
).then((res) => res.body),
daoId + "-is-human-info",
{ subscribe: false }
);
State.update({
hideProposalBtn: !resp?.length > 0
});
const resp = useCache(
() =>
asyncFetch(
`https://api.pikespeak.ai/sbt/sbt-by-owner?holder=${accountId}&registry=registry.i-am-human.near`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
"x-api-key": "/*__@replace:pikespeakApiKey__*/"
}
}
).then((res) => res.body),
daoId + "-is-human-info",
{ subscribe: false }
);
State.update({
hideProposalBtn: !resp?.length > 0
});
}

return (
<>
<div style={{ width: "98%" }}>
<div className="d-flex justify-content-between flex-wrap mb-3 align-items-center gap-3 pb-3">
<h2 className="my-auto">Proposals</h2>
{!state.hideProposalBtn && (
<Widget
src="/*__@appAccount__*//widget/Common.Layout.CardModal"
props={{
title: "Create Proposal",
onToggle: () =>
State.update({
isProposalModalOpen:
!state.isProposalModalOpen
}),
isOpen: state.isProposalModalOpen,
toggle: (
<Widget
src="nearui.near/widget/Input.Button"
props={{
children: (
<>
Create Proposal
<i className="bi bi-16 bi-plus-lg"></i>
</>
),
variant: "info"
}}
/>
),
content: (
<div
className="d-flex flex-column align-items-stretch"
style={{
width: "800px",
maxWidth: "100vw"
}}
>
<Widget
src={
"/*__@appAccount__*//widget/DAO.Proposal.Create"
}
props={{
daoId: daoId,
dev: props.dev
}}
/>
</div>
)
}}
/>
)}
</div>
<>
<div style={{ width: "98%" }}>
<div className="d-flex justify-content-between flex-wrap mb-3 align-items-center gap-3 pb-3">
<h2 className="my-auto">Proposals</h2>
{!state.hideProposalBtn && (
<Widget
src="/*__@appAccount__*//widget/Common.Layout.CardModal"
props={{
title: "Create Proposal",
onToggle: () =>
State.update({
isProposalModalOpen: !state.isProposalModalOpen
}),
isOpen: state.isProposalModalOpen,
toggle: (
<Widget
src="nearui.near/widget/Input.Button"
props={{
children: (
<>
Create Proposal
<i className="bi bi-16 bi-plus-lg"></i>
</>
),
variant: "info"
}}
/>
),
content: (
<div
className="d-flex flex-column align-items-stretch"
style={{
width: "800px",
maxWidth: "100vw"
}}
>
<Widget
src={"/*__@appAccount__*//widget/DAO.Proposal.Create"}
props={{
daoId: daoId,
dev: props.dev
}}
/>
</div>
)
}}
/>
)}
</div>

<Widget
src="/*__@appAccount__*//widget/DAO.Proposals.ProposalsPikespeak"
props={{ daoId: daoId, dev: props.dev }}
/>
</div>
</>
<Widget
src="/*__@appAccount__*//widget/DAO.Proposals.ProposalsPikespeak"
props={{ daoId: daoId, dev: props.dev }}
/>
</div>
</>
);
Loading
Loading