Skip to content

Commit

Permalink
Show society member warning, #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
hyifeng committed Sep 4, 2024
1 parent a9447af commit 56f06af
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
12 changes: 12 additions & 0 deletions backend/packages/backend/src/features/society/getSocietyMember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
getSocietyMember: _getSocietyMember,
} = require("../../services/node.service/getSocietyMember");

async function getSocietyMember(ctx) {
const { network, address } = ctx.params;
ctx.body = await _getSocietyMember(network, address);
}

module.exports = {
getSocietyMember,
};
8 changes: 8 additions & 0 deletions backend/packages/backend/src/features/society/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Router = require("koa-router");
const { getSocietyMember } = require("./getSocietyMember");

const router = new Router();

router.get("/:network/society/members/:address", getSocietyMember);

module.exports = router;
1 change: 1 addition & 0 deletions backend/packages/backend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const commonFeatureRouters = [
require("./features/files/routes"),
require("./features/notifications/routes"),
require("./features/proposals/commonRoutes"),
require("./features/society/index"),
];

async function checkSpaceExisten(ctx, next) {
Expand Down
24 changes: 17 additions & 7 deletions next/components/postCreate/information.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
proxyBalanceLoadingSelector,
} from "../../store/reducers/statusSlice";
import BalanceRow from "@/components/postCreate/BalanceRow";
import { isOnePersonOnVoteOnly } from "frontedUtils/strategy";
import SocietyMemberHit from "./societyMemberHit";

const Hint = styled.div`
margin-top: 4px !important;
Expand All @@ -34,7 +36,12 @@ const PostAddressWrapper = styled.div`
`;

export default function Information({ space }) {
const { proposeThreshold: threshold, decimals, symbol } = space;
const {
proposeThreshold: threshold,
decimals,
symbol,
weightStrategy,
} = space;

const dispatch = useDispatch();
const balance = useSelector(targetBalanceSelector);
Expand Down Expand Up @@ -87,13 +94,16 @@ export default function Information({ space }) {

return (
<>
<BalanceRow
balance={balance}
isLoading={useProxy ? proxyBalanceLoading : balanceLoading}
decimals={decimals}
symbol={symbol}
/>
{!isOnePersonOnVoteOnly(weightStrategy) && (
<BalanceRow
balance={balance}
isLoading={useProxy ? proxyBalanceLoading : balanceLoading}
decimals={decimals}
symbol={symbol}
/>
)}
{hint}
{space.accessibility === "society" && <SocietyMemberHit space={space} />}
{proxyElements}
</>
);
Expand Down
16 changes: 16 additions & 0 deletions next/components/postCreate/societyMemberHit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useIsSocietyMember } from "hooks/useIsSocietyMember";
import styled from "styled-components";

const Hint = styled.div`
margin-top: 4px !important;
color: var(--textFeedbackError);
`;

export default function SocietyMemberHit() {
const isSocietyMember = useIsSocietyMember();
if (isSocietyMember) {
return null;
}

return <Hint>You are not the society member</Hint>;
}
3 changes: 3 additions & 0 deletions next/frontedUtils/strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isOnePersonOnVoteOnly(strategies) {
return strategies.length === 1 && strategies[0].type !== "one-person-on-vote";
}
25 changes: 25 additions & 0 deletions next/hooks/useIsSocietyMember.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import nextApi from "services/nextApi";
import {
loginAddressSelector,
loginNetworkSelector,
} from "store/reducers/accountSlice";

export function useIsSocietyMember() {
const network = useSelector(loginNetworkSelector);
const loginAddress = useSelector(loginAddressSelector);
const [isSocietyMember, setIsSocietyMember] = useState(false);
useEffect(() => {
if (!loginAddress || !network) {
return;
}
nextApi
.fetch(`${network.network}/society/members/${loginAddress}`)
.then(({ result }) => {
setIsSocietyMember(result?.data !== null);
});
}, [network, loginAddress]);

return isSocietyMember;
}

0 comments on commit 56f06af

Please sign in to comment.