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

Normalise daoSnapshotENS to lower case #2247

Merged
merged 4 commits into from
Aug 17, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { URL_DOCS_GOV_TYPES } from '../../../constants/url';
import { createAccountSubstring } from '../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { ICreationStepProps, VotingStrategyType, GovernanceType } from '../../../types';
import { GovernanceType, ICreationStepProps, VotingStrategyType } from '../../../types';
import { InputComponent, LabelComponent } from '../../ui/forms/InputComponent';
import LabelWrapper from '../../ui/forms/LabelWrapper';
import { RadioWithText } from '../../ui/forms/Radio/RadioWithText';
Expand Down Expand Up @@ -70,7 +70,7 @@ export function EstablishEssentials(props: ICreationStepProps) {
helper={t('helperDAOName')}
isRequired
value={values.essentials.daoName}
id="searchEssentials-daoName"
id="essentials-daoName"
onChange={cEvent => setFieldValue('essentials.daoName', cEvent.target.value, true)}
onBlur={cEvent => setFieldValue('essentials.daoName', cEvent.target.value.trim(), true)}
disabled={daoNameDisabled}
Expand Down Expand Up @@ -159,7 +159,7 @@ export function EstablishEssentials(props: ICreationStepProps) {
<Input
value={values.essentials.snapshotENS}
onChange={cEvent =>
setFieldValue('essentials.snapshotENS', cEvent.target.value, true)
setFieldValue('essentials.snapshotENS', cEvent.target.value.toLowerCase(), true)
}
isDisabled={snapshotENSDisabled}
data-testid="essentials-snapshotENS"
Expand Down
2 changes: 1 addition & 1 deletion src/components/Proposals/ProposalInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex, Button, Link } from '@chakra-ui/react';
import { Box, Button, Flex, Link } from '@chakra-ui/react';
import { ArrowUpRight } from '@phosphor-icons/react';
import { useTranslation } from 'react-i18next';
import { Shield } from '../../assets/theme/custom/icons/Shield';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button } from '@chakra-ui/react';
import { useState, useEffect, ChangeEventHandler } from 'react';
import { ChangeEventHandler, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { isHex, getAddress } from 'viem';
import { getAddress, isHex } from 'viem';
import { DAO_ROUTES } from '../../../../constants/routes';
import useSubmitProposal from '../../../../hooks/DAO/proposal/useSubmitProposal';
import { useCanUserCreateProposal } from '../../../../hooks/utils/useCanUserSubmitProposal';
Expand Down Expand Up @@ -43,8 +43,9 @@ export function MetadataContainer() {
}, [daoName, daoSnapshotENS, daoAddress]);

const handleSnapshotENSChange: ChangeEventHandler<HTMLInputElement> = e => {
setSnapshotENS(e.target.value);
if (validateENSName(e.target.value) || (e.target.value === '' && daoSnapshotENS)) {
const lowerCasedValue = e.target.value.toLowerCase();
setSnapshotENS(lowerCasedValue);
if (validateENSName(lowerCasedValue) || (e.target.value === '' && daoSnapshotENS)) {
setSnapshotENSValid(true);
} else {
setSnapshotENSValid(false);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/cards/DAOInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex, Text, Link, Center } from '@chakra-ui/react';
import { Box, Center, Flex, Link, Text } from '@chakra-ui/react';
import { Link as RouterLink } from 'react-router-dom';
import { DAO_ROUTES } from '../../../constants/routes';
import useDisplayName from '../../../hooks/utils/useDisplayName';
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/cards/DAONodeInfoCard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Flex, Text, FlexProps, Link, Center, VStack } from '@chakra-ui/react';
import { Center, Flex, FlexProps, Link, Text, VStack } from '@chakra-ui/react';
import { Link as RouterLink } from 'react-router-dom';
import { DAO_ROUTES } from '../../../constants/routes';
import useDisplayName from '../../../hooks/utils/useDisplayName';
import { useFractal } from '../../../providers/App/AppProvider';
import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider';
import { FreezeGuard, FractalGuardContracts, FractalNode } from '../../../types';
import { FractalGuardContracts, FractalNode, FreezeGuard } from '../../../types';
import { SnapshotButton } from '../badges/Snapshot';
import { FavoriteIcon } from '../icons/FavoriteIcon';
import AddressCopier from '../links/AddressCopier';
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/forms/ABISelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Select, Text } from '@chakra-ui/react';
import axios from 'axios';
import detectProxyTarget from 'evm-proxy-detection';
import { useMemo, useState, useEffect } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { isAddress } from 'viem';
import { useEnsAddress, usePublicClient } from 'wagmi';
Expand All @@ -28,7 +28,7 @@ export default function ABISelector({ target, onChange }: IABISelector) {
const [abi, setABI] = useState<ABIElement[]>([]);
const { etherscanAPIUrl } = useNetworkConfig();
const { t } = useTranslation('common');
const { data: ensAddress } = useEnsAddress({ name: target });
const { data: ensAddress } = useEnsAddress({ name: target?.toLowerCase() });
const client = usePublicClient();

useEffect(() => {
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/DAO/loaders/snapshot/useSnapshotProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ import {
SnapshotVote,
SnapshotWeightedVotingChoice,
} from '../../../../types';
import useSnapshotSpaceName from './useSnapshotSpaceName';
import { createSnapshotGraphQlClient } from './';

export default function useSnapshotProposal(proposal: FractalProposal | null | undefined) {
const [extendedSnapshotProposal, setExtendedSnapshotProposal] =
useState<ExtendedSnapshotProposal>();
const {
node: { daoSnapshotENS },
readOnly: {
user: { address },
},
} = useFractal();
const daoSnapshotSpaceName = useSnapshotSpaceName();
const snaphshotGraphQlClient = useMemo(() => createSnapshotGraphQlClient(), []);

const snapshotProposal = proposal as SnapshotProposal;
Expand Down Expand Up @@ -108,7 +107,7 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
const { choices, type, privacy } = proposalQueryResult;

if (type === 'weighted') {
Object.keys(choices).forEach((choice: string, choiceIndex) => {
Object.keys(choices).forEach((_choice: string, choiceIndex) => {
adamgall marked this conversation as resolved.
Show resolved Hide resolved
votesBreakdown[choiceIndex + 1] = {
votes: [],
total: 0,
Expand Down Expand Up @@ -214,7 +213,7 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
query UserVotingWeight {
vp(
voter: "${address}"
space: "${daoSnapshotSpaceName}"
space: "${daoSnapshotENS}"
proposal: "${snapshotProposal.snapshotProposalId}"
) {
vp
Expand All @@ -239,7 +238,7 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
}

return emptyVotingWeight;
}, [address, snapshotProposal?.snapshotProposalId, snaphshotGraphQlClient, daoSnapshotSpaceName]);
}, [address, snapshotProposal?.snapshotProposalId, snaphshotGraphQlClient, daoSnapshotENS]);

return {
loadVotingWeight,
Expand Down
17 changes: 9 additions & 8 deletions src/hooks/DAO/loaders/snapshot/useSnapshotProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useFractal } from '../../../../providers/App/AppProvider';
import { FractalGovernanceAction } from '../../../../providers/App/governance/action';
import { FractalProposalState } from '../../../../types';
import { SnapshotProposal } from '../../../../types/daoProposal';
import useSnapshotSpaceName from './useSnapshotSpaceName';
import { createSnapshotGraphQlClient } from './';

export const useSnapshotProposals = () => {
const { action } = useFractal();
const daoSnapshotSpaceName = useSnapshotSpaceName();
const {
node: { daoSnapshotENS },
action,
} = useFractal();
const currentSnapshotENS = useRef<string | undefined>();
const snaphshotGraphQlClient = useMemo(() => createSnapshotGraphQlClient(), []);

Expand All @@ -22,7 +23,7 @@ export const useSnapshotProposals = () => {
proposals(
first: 50,
where: {
space_in: ["${daoSnapshotSpaceName}"]
space_in: ["${daoSnapshotENS}"]
},
orderBy: "created",
orderDirection: desc
Expand Down Expand Up @@ -72,11 +73,11 @@ export const useSnapshotProposals = () => {
});
});
}
}, [action, daoSnapshotSpaceName, snaphshotGraphQlClient]);
}, [action, daoSnapshotENS, snaphshotGraphQlClient]);

useEffect(() => {
if (!daoSnapshotSpaceName || daoSnapshotSpaceName === currentSnapshotENS.current) return;
currentSnapshotENS.current = daoSnapshotSpaceName;
if (!daoSnapshotENS || daoSnapshotENS === currentSnapshotENS.current) return;
currentSnapshotENS.current = daoSnapshotENS;
loadSnapshotProposals();
}, [daoSnapshotSpaceName, loadSnapshotProposals]);
}, [daoSnapshotENS, loadSnapshotProposals]);
};
9 changes: 0 additions & 9 deletions src/hooks/DAO/loaders/snapshot/useSnapshotSpaceName.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/hooks/DAO/loaders/useLoadDAONode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLazyQuery } from '@apollo/client';
import { useCallback } from 'react';
import { isAddress, getAddress } from 'viem';
import { getAddress, isAddress } from 'viem';
import { DAO, DAOQueryDocument, DAOQueryQuery } from '../../../../.graphclient';
import { logError } from '../../../helpers/errorLogging';
import { useSafeAPI } from '../../../providers/App/hooks/useSafeAPI';
Expand Down
10 changes: 4 additions & 6 deletions src/hooks/DAO/proposal/useCastVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import encryptWithShutter from '../../../utils/shutter';
import useSafeContracts from '../../safe/useSafeContracts';
import { useTransaction } from '../../utils/useTransaction';
import useSnapshotSpaceName from '../loaders/snapshot/useSnapshotSpaceName';
import useUserERC721VotingTokens from './useUserERC721VotingTokens';

const useCastVote = ({
Expand All @@ -40,7 +39,6 @@ const useCastVote = ({
},
} = useFractal();
const baseContracts = useSafeContracts();
const daoSnapshotSpaceName = useSnapshotSpaceName();
const signer = useEthersSigner();
const client = useMemo(() => {
if (daoSnapshotENS) {
Expand Down Expand Up @@ -146,7 +144,7 @@ const useCastVote = ({
signer &&
signer?.provider &&
address &&
daoSnapshotSpaceName &&
daoSnapshotENS &&
extendedSnapshotProposal &&
client
) {
Expand Down Expand Up @@ -177,7 +175,7 @@ const useCastVote = ({
extendedSnapshotProposal.proposalId,
);
await client.vote(signer.provider as ethers.providers.Web3Provider, address, {
space: daoSnapshotSpaceName,
space: daoSnapshotENS,
proposal: extendedSnapshotProposal.proposalId,
type: extendedSnapshotProposal.type,
privacy: extendedSnapshotProposal.privacy,
Expand All @@ -186,7 +184,7 @@ const useCastVote = ({
});
} else {
await client.vote(signer.provider as ethers.providers.Web3Provider, address, {
space: daoSnapshotSpaceName,
space: daoSnapshotENS,
proposal: extendedSnapshotProposal.proposalId,
type: extendedSnapshotProposal.type,
choice,
Expand All @@ -210,7 +208,7 @@ const useCastVote = ({
[
signer,
address,
daoSnapshotSpaceName,
daoSnapshotENS,
extendedSnapshotProposal,
t,
selectedChoice,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/useGetDAOName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react';
import { Address, PublicClient, getContract, parseAbi, getAddress } from 'viem';
import { Address, PublicClient, getAddress, getContract, parseAbi } from 'viem';
import { usePublicClient } from 'wagmi';
import { useFractal } from '../../providers/App/AppProvider';
import { FractalContracts } from '../../types';
Expand All @@ -22,7 +22,7 @@ const getDAOName = async ({
throw new Error('Public client not available');
}

const ensName = await publicClient.getEnsName({ address: address }).catch((error: Error) => {
const ensName = await publicClient.getEnsName({ address }).catch((error: Error) => {
if (error.name === 'ChainDoesNotSupportContract') {
// Sliently fail, this is fine.
// https://github.com/wevm/viem/discussions/781
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/utils/useAvatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useNetworkConfig } from '../../providers/NetworkConfig/NetworkConfigPro
const useAvatar = (name: string) => {
const { chain } = useNetworkConfig();
const { data: avatarURL } = useEnsAvatar({
name: name,
name,
chainId: chain.id,
});

Expand Down
6 changes: 3 additions & 3 deletions src/models/DaoTxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { zeroAddress } from 'viem';
import { GnosisSafeL2 } from '../assets/typechain-types/usul/@gnosis.pm/safe-contracts/contracts';
import { buildContractCall, encodeMultiSend } from '../helpers';
import {
BaseContracts,
SafeMultisigDAO,
SafeTransaction,
AzoriusContracts,
AzoriusERC20DAO,
AzoriusERC721DAO,
BaseContracts,
SafeMultisigDAO,
SafeTransaction,
VotingStrategyType,
} from '../types';
import { BaseTxBuilder } from './BaseTxBuilder';
Expand Down