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

Added isMember check to entrypoint, fixed the useUpdateProposal hook #1117

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@apollo/client": "^3.5.8",
"@aragon/ods": "^1.0.1",
"@aragon/sdk-client": "^1.18.2",
"@aragon/sdk-client": "^1.19.0",
"@elastic/apm-rum-react": "^2.0.0",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-dialog": "^1.0.4",
Expand Down
16 changes: 12 additions & 4 deletions src/components/proposalList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {MultisigProposalListItem} from '@aragon/sdk-client';
import {CardProposal, CardProposalProps, Spinner} from '@aragon/ods-old';
import {DaoAction} from '@aragon/sdk-client-common';
import {BigNumber} from 'ethers';
import React, {useMemo} from 'react';
import {useTranslation} from 'react-i18next';
Expand Down Expand Up @@ -52,9 +53,12 @@ function isMultisigProposalListItem(
}

const ProposalItem: React.FC<
{proposalId: string} & CardProposalProps
{proposalId: string; actions: DaoAction[]} & CardProposalProps
> = props => {
const {isAragonVerifiedUpdateProposal} = useUpdateProposal(props.proposalId);
const {isAragonVerifiedUpdateProposal} = useUpdateProposal(
props.proposalId,
props.actions
);
const {t} = useTranslation();

return (
Expand Down Expand Up @@ -88,7 +92,10 @@ const ProposalList: React.FC<ProposalListProps> = ({
{countOnly: true}
);

const mappedProposals: ({id: string} & CardProposalProps)[] = useMemo(
const mappedProposals: ({
id: string;
actions: DaoAction[];
} & CardProposalProps)[] = useMemo(
() =>
proposals.map(p =>
proposal2CardProps(
Expand Down Expand Up @@ -158,7 +165,7 @@ export function proposal2CardProps(
t: TFunction,
daoAddressOrEns: string,
address: string | null
): {id: string} & CardProposalProps {
): {id: string; actions: DaoAction[]} & CardProposalProps {
const publisherDisplayName =
address && proposal.creatorAddress.toLowerCase() === address.toLowerCase()
? t('labels.you')
Expand All @@ -173,6 +180,7 @@ export function proposal2CardProps(
publisherDisplayName,
publishLabel: t('governance.proposals.publishedBy'),
process: proposal.status.toLowerCase() as CardProposalProps['process'],
actions: proposal.actions,
onClick: () => {
trackEvent('governance_viewProposal_clicked', {
proposal_id: proposal.id,
Expand Down
26 changes: 23 additions & 3 deletions src/containers/navbar/updateBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect, useState} from 'react';
import {useTranslation} from 'react-i18next';
import styled from 'styled-components';
import {ButtonText, IconClose, IconUpdate} from '@aragon/ods-old';
Expand All @@ -11,23 +11,43 @@ import {
import {useNetwork} from 'context/network';
import {NewProposal} from 'utils/paths';
import {featureFlags} from 'utils/featureFlags';
import {useDaoDetailsQuery} from 'hooks/useDaoDetails';
import {PluginTypes, usePluginClient} from 'hooks/usePluginClient';
import {useWallet} from 'hooks/useWallet';

const UpdateBanner: React.FC = () => {
const {t} = useTranslation();
const navigate = useNavigate();
const {network} = useNetwork();
const {dao} = useParams();
const location = useLocation();
const {address} = useWallet();
const {data: daoDetails, isLoading} = useDaoDetailsQuery();
const pluginType = daoDetails?.plugins?.[0]?.id as PluginTypes;
const pluginAddress = daoDetails?.plugins?.[0]?.instanceAddress as string;
const pluginClient = usePluginClient(pluginType);
const [isMember, setIsMember] = useState(false);

useEffect(() => {
pluginClient?.methods
.isMember({
address: address as string,
pluginAddress,
})
.then(value => setIsMember(value));
}, [address, pluginAddress, pluginClient?.methods]);

if (
location.pathname.includes('new-proposal') ||
location.pathname.includes('settings') ||
location.pathname.includes('create')
location.pathname.includes('create') ||
isLoading
)
return null;

const daoUpdateEnabled =
featureFlags.getValue('VITE_FEATURE_FLAG_OSX_UPDATES') === 'true';
featureFlags.getValue('VITE_FEATURE_FLAG_OSX_UPDATES') === 'true' &&
isMember;

if (daoUpdateEnabled)
return (
Expand Down
8 changes: 6 additions & 2 deletions src/containers/proposalSnapshot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IconGovernance,
ListItemHeader,
} from '@aragon/ods-old';
import {DaoAction} from '@aragon/sdk-client-common';
import React from 'react';
import {useTranslation} from 'react-i18next';
import {generatePath, useNavigate} from 'react-router-dom';
Expand Down Expand Up @@ -34,9 +35,12 @@ type Props = {
};

const ProposalItem: React.FC<
{proposalId: string} & CardProposalProps
{proposalId: string; actions: DaoAction[]} & CardProposalProps
> = props => {
const {isAragonVerifiedUpdateProposal} = useUpdateProposal(props.proposalId);
const {isAragonVerifiedUpdateProposal} = useUpdateProposal(
props.proposalId,
props.actions
);
const {t} = useTranslation();

return (
Expand Down
33 changes: 13 additions & 20 deletions src/hooks/useUpdateProposal.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import {useQuery} from '@tanstack/react-query';
import {useClient} from './useClient';
import {DaoAction} from '@aragon/sdk-client-common';

/**
* This method is a Mock query of update proposal-related things until the real SDK functions are ready
* @param proposalId dao proposal id
* @returns queries the indicates the update proposal identity
*/
export function useUpdateProposal(proposalId: string | undefined) {
// FIXME: remove this function and use the real SDK function
function getRandomInt(max: number) {
return Math.floor(Math.random() * max);
}

const updateProposalCheck = useQuery({
queryKey: ['updateProposalCheck', proposalId],
queryFn: () =>
new Promise(resolve => {
setTimeout(() => resolve(Boolean(getRandomInt(2))));
}),
enabled: Boolean(proposalId),
});

export function useUpdateProposal(
proposalId: string | undefined,
proposalActions: DaoAction[]
) {
const {client} = useClient();
const aragonVerifiedUpdateProposalCheck = useQuery({
queryKey: ['aragonVerifiedUpdateProposalCheck', proposalId],
queryFn: () =>
new Promise(resolve => {
setTimeout(() => resolve(Boolean(getRandomInt(2))));
}),
queryFn: () => {
return (
client?.methods.isDaoUpdate(proposalActions) ||
client?.methods.isPluginUpdate(proposalActions)
);
},
enabled: Boolean(proposalId),
});

Expand All @@ -34,7 +28,6 @@ export function useUpdateProposal(proposalId: string | undefined) {
aragonVerifiedUpdateProposalCheck.data;

return {
updateProposalCheck,
aragonVerifiedUpdateProposalCheck,
isAragonVerifiedUpdateProposal,
};
Expand Down
22 changes: 18 additions & 4 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,33 @@ import {SettingsUpdateCard} from 'containers/settings/updateCard';
import {VersionInfoCard} from 'containers/settings/versionInfoCard';
import {useNetwork} from 'context/network';
import {useDaoDetailsQuery} from 'hooks/useDaoDetails';
import {PluginTypes} from 'hooks/usePluginClient';
import {PluginTypes, usePluginClient} from 'hooks/usePluginClient';
import useScreen from 'hooks/useScreen';
import {CHAIN_METADATA} from 'utils/constants';
import {featureFlags} from 'utils/featureFlags';
import {shortenAddress, toDisplayEns} from 'utils/library';
import {EditSettings} from 'utils/paths';
import {useWallet} from 'hooks/useWallet';

export const Settings: React.FC = () => {
const {t} = useTranslation();
const navigate = useNavigate();
const {isDesktop} = useScreen();

// move into components when proper loading experience is implemented
const {address} = useWallet();
const {data: daoDetails, isLoading} = useDaoDetailsQuery();
const pluginType = daoDetails?.plugins?.[0]?.id as PluginTypes;
const pluginAddress = daoDetails?.plugins?.[0]?.instanceAddress as string;
const pluginClient = usePluginClient(pluginType);
const [isMember, setIsMember] = useState(false);

useEffect(() => {
pluginClient?.methods
.isMember({
address: address as string,
pluginAddress,
})
.then(value => setIsMember(value));
}, [address, pluginAddress, pluginClient?.methods]);

if (isLoading) {
return <Loading />;
Expand All @@ -54,7 +67,8 @@ export const Settings: React.FC = () => {
}

const daoUpdateEnabled =
featureFlags.getValue('VITE_FEATURE_FLAG_OSX_UPDATES') === 'true';
featureFlags.getValue('VITE_FEATURE_FLAG_OSX_UPDATES') === 'true' &&
isMember;

return (
<SettingsWrapper>
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
dependencies:
ethers "^5.6.2"

"@aragon/sdk-client-common@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@aragon/sdk-client-common/-/sdk-client-common-1.10.0.tgz#603b4e4d8a5079283ba1fb08ef22de6d13b51f1b"
integrity sha512-nWkTPA1Tzk2ULcf0lGbwyalZJkhKUnYN4cd4xQiwnEwvy6traYaw9HRB2sNUlEFgPrLIKIkgjGS9diZjXXW0xQ==
"@aragon/sdk-client-common@^1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@aragon/sdk-client-common/-/sdk-client-common-1.11.0.tgz#37d4f4ab4012fd65e06e40c3f41b9c3163328dcf"
integrity sha512-zn3BP5vnW7NHgc0fDEbAkVzuiOk+hzSh9oCwOcHY9tLGdGR+g+D0Jzpwqu9McBBur6TpzcW3xdNgMMGTqr21ZA==
dependencies:
"@aragon/osx-ethers" "^1.3.0-rc0.4"
"@aragon/osx-ethers-v1.0.0" "npm:@aragon/[email protected]"
Expand All @@ -91,13 +91,13 @@
graphql-request "^4.3.0"
yup "^1.2.0"

"@aragon/sdk-client@^1.18.2":
version "1.18.2"
resolved "https://registry.yarnpkg.com/@aragon/sdk-client/-/sdk-client-1.18.2.tgz#ecbc244738553fd2d436280c5fb7a670a18633bd"
integrity sha512-ULzfJ0JrWYYUuD0f9E9wB7JBW3+D7O90ISbY8OSPfshpVB32YYzwefntWszqklVDSHewoAlGr2R/wobvO0nFCQ==
"@aragon/sdk-client@^1.19.0":
version "1.19.0"
resolved "https://registry.yarnpkg.com/@aragon/sdk-client/-/sdk-client-1.19.0.tgz#13f8e95c72aff84c4ff3520220dd8948cd9a3bd4"
integrity sha512-JXxLlkEnTA+ycGl4yTus4y8OvxJXQxoX9k2tfG9pIcVFxgeLAojCAGabDo88S+6AX5rDc0jEF9b3NQbjWo1lnA==
dependencies:
"@aragon/osx-ethers" "1.3.0-rc0.4"
"@aragon/sdk-client-common" "^1.10.0"
"@aragon/sdk-client-common" "^1.11.0"
"@aragon/sdk-ipfs" "^1.1.0"
"@ethersproject/abstract-signer" "^5.5.0"
"@ethersproject/bignumber" "^5.6.0"
Expand Down