From d3d032b6de6f1d10ecece5121a33ca6d51847924 Mon Sep 17 00:00:00 2001 From: chaojun Date: Mon, 21 Oct 2024 18:19:08 +0800 Subject: [PATCH] Show not member hint for whitelist --- next/components/postCreate/information.js | 10 ++++++++-- next/components/postCreate/societyMemberHint.js | 15 +++++++++++++++ next/components/postCreate/societyMemberHit.js | 16 ---------------- next/components/postCreate/styled.js | 6 ++++++ .../components/postCreate/whitelistMemberHint.js | 14 ++++++++++++++ next/components/postDetail/postVote.js | 13 +++++++++++-- next/hooks/useIsWhitelistMember.js | 10 ++++++++++ 7 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 next/components/postCreate/societyMemberHint.js delete mode 100644 next/components/postCreate/societyMemberHit.js create mode 100644 next/components/postCreate/styled.js create mode 100644 next/components/postCreate/whitelistMemberHint.js create mode 100644 next/hooks/useIsWhitelistMember.js diff --git a/next/components/postCreate/information.js b/next/components/postCreate/information.js index 17c5d2e0..c62aa909 100644 --- a/next/components/postCreate/information.js +++ b/next/components/postCreate/information.js @@ -20,7 +20,8 @@ import { } from "../../store/reducers/statusSlice"; import BalanceRow from "@/components/postCreate/BalanceRow"; import { hasBalanceStrategy } from "frontedUtils/strategy"; -import SocietyMemberHit from "./societyMemberHit"; +import SocietyMemberHint from "./societyMemberHint"; +import WhitelistMemberHint from "./whitelistMemberHint"; const Hint = styled.div` margin-top: 4px !important; @@ -107,7 +108,12 @@ export default function Information({ space }) { /> )} - {space.accessibility === "society" && } + {space.accessibility === "society" && } + {space.accessibility === "whitelist" && ( + + Only members can create a proposal + + )} ); diff --git a/next/components/postCreate/societyMemberHint.js b/next/components/postCreate/societyMemberHint.js new file mode 100644 index 00000000..22d4c42a --- /dev/null +++ b/next/components/postCreate/societyMemberHint.js @@ -0,0 +1,15 @@ +import { useIsSocietyMember } from "hooks/useIsSocietyMember"; +import { Hint } from "./styled"; +import { loginAddressSelector } from "store/reducers/accountSlice"; +import { useSelector } from "react-redux"; + +export default function SocietyMemberHint() { + const loginAddress = useSelector(loginAddressSelector); + const isSocietyMember = useIsSocietyMember(); + + if (!loginAddress || isSocietyMember) { + return null; + } + + return You are not a society member; +} diff --git a/next/components/postCreate/societyMemberHit.js b/next/components/postCreate/societyMemberHit.js deleted file mode 100644 index 1cd34cce..00000000 --- a/next/components/postCreate/societyMemberHit.js +++ /dev/null @@ -1,16 +0,0 @@ -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 You are not a society member; -} diff --git a/next/components/postCreate/styled.js b/next/components/postCreate/styled.js new file mode 100644 index 00000000..650099c4 --- /dev/null +++ b/next/components/postCreate/styled.js @@ -0,0 +1,6 @@ +import styled from "styled-components"; + +export const Hint = styled.div` + margin-top: 4px !important; + color: var(--textFeedbackError); +`; diff --git a/next/components/postCreate/whitelistMemberHint.js b/next/components/postCreate/whitelistMemberHint.js new file mode 100644 index 00000000..cd7e73dc --- /dev/null +++ b/next/components/postCreate/whitelistMemberHint.js @@ -0,0 +1,14 @@ +import { loginAddressSelector } from "store/reducers/accountSlice"; +import { Hint } from "./styled"; +import { useIsWhitelistMember } from "hooks/useIsWhitelistMember"; +import { useSelector } from "react-redux"; + +export default function WhitelistMemberHint({ whitelist, children }) { + const loginAddress = useSelector(loginAddressSelector); + const isMember = useIsWhitelistMember(whitelist); + if (!loginAddress || isMember) { + return null; + } + + return {children}; +} diff --git a/next/components/postDetail/postVote.js b/next/components/postDetail/postVote.js index 2bb35ead..7fd55795 100644 --- a/next/components/postDetail/postVote.js +++ b/next/components/postDetail/postVote.js @@ -41,8 +41,9 @@ import { Tooltip } from "@osn/common-ui"; import VoteBalanceDetail from "./VoteBalanceDetail"; import DelegationInfo from "./delegationInfo"; import { hasBalanceStrategy } from "frontedUtils/strategy"; -import SocietyMemberHit from "../postCreate/societyMemberHit"; +import SocietyMemberHint from "../postCreate/societyMemberHint"; import SocietyMemberButton from "../societyMemberButton"; +import WhitelistMemberHint from "../postCreate/whitelistMemberHint"; const Wrapper = styled.div` > :not(:first-child) { @@ -145,6 +146,8 @@ function BalanceInfo({ proposal, balance, balanceDetail, delegation }) { const proxyDelegation = useSelector(proxyDelegationSelector); const isSocietyProposal = proposal.networksConfig?.accessibility === "society"; + const isWhitelistProposal = + proposal.networksConfig?.accessibility === "whitelist"; const { network: loginNetwork } = useSelector(loginNetworkSelector) || {}; @@ -181,7 +184,13 @@ function BalanceInfo({ proposal, balance, balanceDetail, delegation }) { ); } } else if (isSocietyProposal) { - balanceInfo = ; + balanceInfo = ; + } else if (isWhitelistProposal) { + balanceInfo = ( + + Only members can vote + + ); } return ( diff --git a/next/hooks/useIsWhitelistMember.js b/next/hooks/useIsWhitelistMember.js new file mode 100644 index 00000000..1f3c2aba --- /dev/null +++ b/next/hooks/useIsWhitelistMember.js @@ -0,0 +1,10 @@ +import { isSameAddress } from "frontedUtils/address"; +import { useSelector } from "react-redux"; +import { loginAddressSelector } from "store/reducers/accountSlice"; + +export function useIsWhitelistMember(whitelist) { + const loginAddress = useSelector(loginAddressSelector); + return (whitelist || []).some((address) => + isSameAddress(address, loginAddress), + ); +}