Skip to content

Commit

Permalink
Hide proxy and snapshot for permanence
Browse files Browse the repository at this point in the history
  • Loading branch information
hyifeng committed Oct 18, 2024
1 parent 9649387 commit aaf44d7
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 302 deletions.
4 changes: 2 additions & 2 deletions backend/packages/backend/src/scripts/init-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const { stafiConfig } = require("./spaces/stafi");
const { creditcoinConfig } = require("./spaces/creditcoin");
const { creditcoinEnterpriseConfig } = require("./spaces/creditcoinEnterprise");
const { dotaConfig } = require("./spaces/dota");
const { permanenceDaoConfig } = require("./spaces/permanencedao");
const { permanenceConfig } = require("./spaces/permanence");

const spaces = [
polkadotConfig,
Expand Down Expand Up @@ -75,7 +75,7 @@ const spaces = [
creditcoinConfig,
creditcoinEnterpriseConfig,
dotaConfig,
permanenceDaoConfig,
permanenceConfig,
];

if (["1", "true", "TRUE"].includes(process.env.DEVELOPMENT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const { Accessibility } = require("../../consts/space");
const { networks, strategies } = require("./consts");

const config = {
id: "permanencedao",
name: "PermanenceDAO",
id: "permanence",
name: "Permanence",
symbol: "DOT",
decimals: 10,
accessibility: Accessibility.WHITELIST,
Expand Down Expand Up @@ -34,11 +34,11 @@ const config = {
],
weightStrategy: [strategies.onePersonOneVote],
version: "4",
spaceIcon: "permanencedao.svg",
spaceIcon: "permanence.svg",
seoCoverFilename: "permanence_dao.jpg",
admins: [],
};

module.exports = {
permanenceDaoConfig: config,
permanenceConfig: config,
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function checkWhitelistMember(networksConfig, address) {
isSameAddress(item, address),
) === -1
) {
throw new HttpError(400, "You are not the member");
throw new HttpError(400, "Only members can create a proposal");
}
}

Expand Down Expand Up @@ -61,5 +61,4 @@ async function createWhitelistProposal({

module.exports = {
createWhitelistProposal,
checkWhitelistMember,
};
12 changes: 11 additions & 1 deletion backend/packages/backend/src/services/proposal.service/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
hasSocietyStrategy,
hasOnePersonOneVoteStrategy,
} = require("../../utils/strategy");
const { checkWhitelistMember } = require("./createWhitelistProposal");
const { isSameAddress } = require("../../utils/address");

async function getDelegatorBalances({ proposal, voter, voterNetwork }) {
const snapshotHeight = proposal.snapshotHeights?.[voterNetwork];
Expand Down Expand Up @@ -213,6 +213,16 @@ async function checkSocietyVote({ proposal, voterNetwork, voter }) {
}
}

async function checkWhitelistMember(networksConfig, address) {
if (
(networksConfig.whitelist || []).findIndex((item) =>
isSameAddress(item, address),
) === -1
) {
throw new HttpError(400, "Only members can vote on this proposal");
}
}

async function getSocietyVote({ voterNetwork, voter, snapshotHeight }) {
const societyMember = await getSocietyMember(
voterNetwork,
Expand Down
96 changes: 53 additions & 43 deletions next/components/postCreate/information.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import BalanceRow from "@/components/postCreate/BalanceRow";
import { hasBalanceStrategy } from "frontedUtils/strategy";
import SocietyMemberHit from "./societyMemberHit";
import { isSpaceNeedProxy } from "frontedUtils/isNeedProxy";

const Hint = styled.div`
margin-top: 4px !important;
Expand All @@ -35,62 +36,71 @@ const PostAddressWrapper = styled.div`
margin-top: 4px !important;
`;

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

function Proxy({ space }) {
const dispatch = useDispatch();
const balance = useSelector(targetBalanceSelector);
const useProxy = useSelector(useProxySelector);
const canUseProxy = useSelector(canUseProxySelector);
if (!canUseProxy) {
return null;
}

const needProxy = isSpaceNeedProxy(space);
if (!needProxy) {
return null;
}

return (
<>
<ProxyVoteWrapper>
<Row
header="Proxy vote"
content={
<Toggle
on={useProxy}
setOn={() => dispatch(setUseProxy(!useProxy))}
/>
}
/>
</ProxyVoteWrapper>
{useProxy && (
<PostAddressWrapper>
<PostAddress size="small" spaceId={space.id} />
</PostAddressWrapper>
)}
</>
);
}

function InfoHint({ space }) {
const { proposeThreshold: threshold, decimals, symbol } = space;

const balance = useSelector(targetBalanceSelector);
const loadBalanceError = useSelector(loadBalanceErrorSelector);
const useProxy = useSelector(useProxySelector);
const belowThreshold = new BigNumber(balance).isLessThan(threshold);
const loginAddress = useSelector(loginAddressSelector);

const proxyBalanceLoading = useSelector(proxyBalanceLoadingSelector);
const balanceLoading = useSelector(balanceLoadingSelector);

let proxyElements = null;
if (canUseProxy) {
proxyElements = (
<>
<ProxyVoteWrapper>
<Row
header="Proxy vote"
content={
<Toggle
on={useProxy}
setOn={() => dispatch(setUseProxy(!useProxy))}
/>
}
/>
</ProxyVoteWrapper>
{useProxy && (
<PostAddressWrapper>
<PostAddress size="small" spaceId={space.id} />
</PostAddressWrapper>
)}
</>
);
}

let hint = null;
if (!loginAddress) {
hint = <Hint>Link an address to create proposal.</Hint>;
return <Hint>Link an address to create proposal.</Hint>;
} else if (loadBalanceError) {
hint = <Hint>{loadBalanceError}</Hint>;
return <Hint>{loadBalanceError}</Hint>;
} else if (belowThreshold) {
hint = (
return (
<Hint>
You need to have a minimum of {toPrecision(threshold, decimals)}{" "}
{symbol} in order to publish a proposal.
</Hint>
);
}
}

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

const balance = useSelector(targetBalanceSelector);
const useProxy = useSelector(useProxySelector);

const proxyBalanceLoading = useSelector(proxyBalanceLoadingSelector);
const balanceLoading = useSelector(balanceLoadingSelector);

return (
<>
Expand All @@ -102,9 +112,9 @@ export default function Information({ space }) {
symbol={symbol}
/>
)}
{hint}
<InfoHint space={space} />
{space.accessibility === "society" && <SocietyMemberHit space={space} />}
{proxyElements}
<Proxy space={space} />
</>
);
}
Loading

0 comments on commit aaf44d7

Please sign in to comment.