Skip to content

Commit

Permalink
Merge pull request #164 from PotLock/fix/registry-admins
Browse files Browse the repository at this point in the history
Fix/registry admins
  • Loading branch information
lachlanglen authored Feb 5, 2024
2 parents 2e12437 + 8256770 commit e9ee0e5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions apps/potlock/widget/Components/ListSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const filterList = [
"Least to Most Donations",
];

console.log("props.items.length: ", props.items.length);

const donationContractId = "donate.potlock.near";
const [totalProjects, setTotalProjects] = useState(props.items);
const [displayProject, setDisplayProject] = useState([]);
Expand Down
1 change: 0 additions & 1 deletion apps/potlock/widget/Components/ModalDonationSuccess.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ if (projectId && !state.successfulDonationRecipientProfile) {
State.update({ successfulDonationRecipientProfile: profile });
}
}
console.log("props modation", props);
const twitterIntent = useMemo(() => {
if (!projectId) return;
const twitterIntentBase = "https://twitter.com/intent/tweet?text=";
Expand Down
14 changes: 10 additions & 4 deletions apps/potlock/widget/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ State.init({
nearToUsd: null,
isCartModalOpen: false,
isNavMenuOpen: false,
registryAdmins: null,
registryConfig: null,
userIsRegistryAdmin: null,
registeredProjects: null,
donnorProjectId: null,
amount: null,
Expand Down Expand Up @@ -146,9 +147,14 @@ if (!state.registeredProjects) {
});
}

if (state.registryAdmins === null) {
const registryAdmins = Near.view(registryContractId, "get_admins", {});
State.update({ registryAdmins });
if (state.registryConfig === null) {
const registryConfig = Near.view(registryContractId, "get_config", {});
if (registryConfig) {
State.update({
registryConfig,
userIsRegistryAdmin: registryConfig.admins.includes(context.accountId),
});
}
}

const tabContentWidget = {
Expand Down
2 changes: 1 addition & 1 deletion apps/potlock/widget/Project/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ return (
/>
</Header>
<Actions />
{props.registryAdmins && props.registryAdmins.includes(context.accountId) && (
{props.registryConfig && props.registryConfig.admins.includes(context.accountId) && (
<Widget
src={`${ownerId}/widget/Inputs.Select`}
props={{
Expand Down
18 changes: 8 additions & 10 deletions apps/potlock/widget/Project/Detail.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const { ownerId } = props;
const { ownerId, projectId, userIsRegistryAdmin } = props;
const registryId = "registry.potlock.near";

const profile = props.profile ?? Social.getr(`${props.projectId}/profile`);
const profile = props.profile ?? Social.getr(`${projectId}/profile`);

const projects = props.projects ?? Near.view(registryId, "get_projects", {});
const project = Near.view(registryId, "get_project_by_id", { project_id: projectId });

if (!profile || !projects) {
if (!profile || !project) {
return "Loading";
}

const registeredProject = projects.find(
(project) => project.id == props.projectId && project.status == "Approved"
);
const projectIsViewable = project.status === "Approved" || userIsRegistryAdmin;

const name = profile.name || "No-name profile";
const image = profile.image;
Expand Down Expand Up @@ -61,14 +59,14 @@ props.navOptions = [
id: "home",
disabled: false,
source: `${ownerId}/widget/Project.About`,
href: `?tab=project&projectId=${props.projectId}&nav=home`,
href: `?tab=project&projectId=${projectId}&nav=home`,
},
{
label: "Social Feed",
id: "feed",
disabled: false,
source: `${ownerId}/widget/Project.Feed`,
href: `?tab=project&projectId=${props.projectId}&nav=feed`,
href: `?tab=project&projectId=${projectId}&nav=feed`,
},
{
label: "Pots",
Expand All @@ -94,7 +92,7 @@ const profileImageTranslateYPx = 220;

return (
<Wrapper>
{!registeredProject ? (
{!projectIsViewable ? (
<div style={{ textAlign: "center", paddingTop: "12px" }}>Project not found</div>
) : (
<>
Expand Down
8 changes: 3 additions & 5 deletions apps/potlock/widget/Project/ListPage.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ownerId } = props;
const { ownerId, userIsRegistryAdmin } = props;
const registryId = "registry.potlock.near";

const IPFS_BASE_URL = "https://nftstorage.link/ipfs/";
Expand Down Expand Up @@ -100,14 +100,12 @@ const InfoCardsContainer = styled.div`
}
`;

const userIsAdmin = props.registryAdmins && props.registryAdmins.includes(context.accountId);

const projects = useMemo(
() =>
userIsAdmin
userIsRegistryAdmin
? props.registeredProjects
: props.registeredProjects.filter((project) => project.status === "Approved"),
[props.registeredProjects, userIsAdmin]
[props.registeredProjects, userIsRegistryAdmin]
);

const [totalDonations, totalDonors] = useMemo(() => {
Expand Down

0 comments on commit e9ee0e5

Please sign in to comment.