Skip to content

Commit

Permalink
Merge pull request #451 from DXgovernance/release/v2.2.0
Browse files Browse the repository at this point in the history
Release/v2.2.0
  • Loading branch information
rossneilson authored Dec 12, 2022
2 parents bcba1b1 + 0a7f9b7 commit 72e9539
Show file tree
Hide file tree
Showing 90 changed files with 5,816 additions and 674 deletions.
5 changes: 3 additions & 2 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (config, env) => {
type: 'javascript/auto',
resolve: {
fullySpecified: false,
}
},
});

config.plugins = [
Expand All @@ -20,11 +20,12 @@ module.exports = (config, env) => {
process: 'process/browser',
Buffer: ['buffer', 'Buffer'],
}),
]
];
if (env !== 'production') {
return config;
}
config.output.filename = `static/js/[name].js`;
config.output.chunkFilename = `static/js/[name].chunk.js`;
return config;
};

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "davi",
"version": "2.1.1",
"version": "2.2.0",
"description": "Decentralized Autonomous Voting Interface",
"scripts": {
"dev": "./scripts/dev.sh",
Expand Down Expand Up @@ -64,10 +64,10 @@
"copy-to-clipboard": "^3.3.1",
"crypto-js": "^4.1.1",
"diff": "^5.1.0",
"dxdao-contracts": "https://github.com/DXgovernance/dxdao-contracts.git#develop",
"dxdao-contracts": "https://github.com/DXgovernance/dxdao-contracts.git#50db3f0754b5ea1a46342857b9520fa0c5250221",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-cypress": "^2.12.1",
"ethers": "^5.5.2",
"ethers": "^5.7.2",
"git-revision-webpack-plugin": "^3.0.6",
"hardhat": "^2.9.1",
"hardhat-dependency-compiler": "^1.1.2",
Expand Down Expand Up @@ -114,8 +114,8 @@
"ts-node": "^10.9.1",
"turndown": "^7.1.1",
"typechain-target-ethers-v5": "^5.0.1",
"typescript": "^4.5.5",
"wagmi": "^0.5.6",
"typescript": "^4.9.3",
"wagmi": "^0.7.15",
"webpack": "4.44.2",
"webpack-manifest-plugin": "^2.2.0",
"workbox-webpack-plugin": "^5.1.4"
Expand Down
2 changes: 1 addition & 1 deletion src/Modules/Guilds/Hooks/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const MOCK_CONTRACT_ADDRESSES = [
'0x0000000000000000000000000000000000000002',
'0x0000000000000000000000000000000000000003',
];
export const MOCK_PROPOSAL_ID = '1';
export const MOCK_PROPOSAL_ID = '0x01';
export const MOCK_PROPOSAL_VOTES = 1;
export const MOCK_TOTAL_LOCKED_AT = 1;
export const MOCK_USER_ADDRESS = '0x0000000000000000000000000000000000000004';
Expand Down
22 changes: 16 additions & 6 deletions src/Modules/Guilds/Hooks/useCurrentSnapshotId.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useGuildImplementationTypeConfig from 'Modules/Guilds/Hooks/useGuildImplementationType';
import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json';
import { useContractRead } from 'wagmi';
import { useContractEvent, useContractRead } from 'wagmi';
import { SnapshotERC20Guild } from 'contracts/ts-files/SnapshotERC20Guild';

interface useCurrentSnapshotIdProps {
contractAddress: string;
Expand All @@ -10,13 +10,23 @@ const useCurrentSnapshotId = ({
contractAddress,
}: useCurrentSnapshotIdProps) => {
const { isSnapshotGuild } = useGuildImplementationTypeConfig(contractAddress);
return useContractRead({
const { data, refetch, ...rest } = useContractRead({
enabled: isSnapshotGuild,
addressOrName: contractAddress,
contractInterface: SnapshotERC20Guild.abi,
address: contractAddress,
abi: SnapshotERC20Guild.abi,
functionName: 'getCurrentSnapshotId',
watch: true,
});

useContractEvent({
address: isSnapshotGuild ? contractAddress : null,
abi: SnapshotERC20Guild.abi,
eventName: 'ProposalStateChanged',
listener(node, label, owner) {
refetch();
},
});

return { data, refetch, ...rest };
};

export default useCurrentSnapshotId;
22 changes: 16 additions & 6 deletions src/Modules/Guilds/Hooks/useGuildActiveProposals.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import BaseERC20Guild from 'contracts/BaseERC20Guild.json';
import { useContractRead } from 'wagmi';
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';
import { useContractEvent, useContractRead } from 'wagmi';

const useActiveProposalsNow = (guildAddress: string) => {
return useContractRead({
addressOrName: guildAddress,
contractInterface: BaseERC20Guild.abi,
const { data, refetch, ...rest } = useContractRead({
address: guildAddress,
abi: BaseERC20Guild.abi,
functionName: 'getActiveProposalsNow',
watch: true,
});

useContractEvent({
address: guildAddress,
abi: BaseERC20Guild.abi,
eventName: 'ProposalStateChanged',
listener() {
refetch();
},
});

return { data, refetch, ...rest };
};

export default useActiveProposalsNow;
29 changes: 20 additions & 9 deletions src/Modules/Guilds/Hooks/useGuildConfig.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { BigNumber } from 'ethers';
import { useMemo } from 'react';
import BaseERC20GuildContract from 'contracts/BaseERC20Guild.json';
import useGuildToken from 'Modules/Guilds/Hooks/useGuildToken';
import { useContractReads } from 'wagmi';
import { useVotingPowerForProposalExecution } from 'Modules/Guilds/Hooks/useVotingPowerForProposalExecution';
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';

export type GuildConfigProps = {
permissionRegistry: string;
name: string;
token: `0x${string}`;
permissionRegistry: string;
proposalTime: BigNumber;
timeForExecution: BigNumber;
maxActiveProposals: BigNumber;
votingPowerForProposalCreation: BigNumber;
tokenVault: string;
votingPowerForProposalExecution: BigNumber;
tokenVault: `0x${string}`;
lockTime: BigNumber;
voteGas: BigNumber;
maxGasPrice: BigNumber;
votingPowerPercentageForProposalExecution: BigNumber;
votingPowerPercentageForProposalCreation: BigNumber;
minimumMembersForProposalCreation: BigNumber;
minimumTokensLockedForProposalCreation: BigNumber;
votingPowerForProposalExecution: BigNumber;
token: string;
};

const GETTER_FUNCTIONS = [
Expand All @@ -41,14 +41,18 @@ const GETTER_FUNCTIONS = [
'getMinimumTokensLockedForProposalCreation',
];

export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
export const useGuildConfig = (
guildAddress: string,
proposalId?: `0x${string}`
) => {
const { data, ...rest } = useContractReads({
contracts: GETTER_FUNCTIONS.map(functionName => ({
addressOrName: guildAddress,
contractInterface: BaseERC20GuildContract.abi,
address: guildAddress,
abi: BaseERC20Guild.abi,
functionName,
})),
});

const { data: token } = useGuildToken(guildAddress);
const { data: votingPowerForProposalExecution } =
useVotingPowerForProposalExecution({
Expand All @@ -74,6 +78,13 @@ export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
minimumTokensLockedForProposalCreation,
] = data;

// Made to prevent
// "Type '{} & readonly unknown[]' is not assignable to type '`0x${string}`'"
// doesn't accept ternary operator
let safeTokenVault;
if (!tokenVault) safeTokenVault = undefined;
else safeTokenVault = tokenVault;

return {
permissionRegistry: permissionRegistry?.toString(),
name: name?.toString(),
Expand All @@ -87,7 +98,7 @@ export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
votingPowerForProposalCreation: votingPowerForProposalCreation
? BigNumber.from(votingPowerForProposalCreation)
: undefined,
tokenVault: tokenVault?.toString(),
tokenVault: safeTokenVault,
lockTime: lockTime ? BigNumber?.from(lockTime) : undefined,
voteGas: voteGas ? BigNumber?.from(voteGas) : undefined,
maxGasPrice: maxGasPrice ? BigNumber?.from(maxGasPrice) : undefined,
Expand Down
85 changes: 45 additions & 40 deletions src/Modules/Guilds/Hooks/useGuildMemberTotal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,81 @@ import {
MOCK_GUILD_MEMBERS_TOTAL,
MOCK_GUILD_ADDRESS,
MOCK_TOKEN,
MOCK_CONTRACT_INTERFACE,
} from 'Modules/Guilds/Hooks/fixtures';
import wagmi, { useContractRead } from 'wagmi';
import wagmi, { useContractReads } from 'wagmi';
import { ERC20SnapshotRep } from 'contracts/ts-files/ERC20SnapshotRep';
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';

jest.mock('wagmi', () => ({
useContractRead: () => ({
useContractReads: () => ({
data: MOCK_GUILD_MEMBERS_TOTAL,
isLoading: false,
isError: false,
}),

useContractEvent: () => jest.fn(),
}));

describe('useGuildMemberTotal', () => {
it('should return guild member totals', () => {
const { data, isError, isLoading } = useGuildMemberTotal(
MOCK_GUILD_ADDRESS,
MOCK_TOKEN,
false
);
const { data } = useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, false);

expect(data).toMatchInlineSnapshot(`3`);
expect(isError).toBe(false);
expect(isLoading).toBe(false);
});

it('should call getTotalHolders when isRepGuild is true', () => {
const isRepGuild = true;

const mockUseContractRead = jest
.spyOn(wagmi, 'useContractRead')
.spyOn(wagmi, 'useContractReads')
.mockImplementationOnce(() => ({
...useContractRead({
addressOrName: MOCK_GUILD_ADDRESS,
contractInterface: MOCK_CONTRACT_INTERFACE,
functionName: 'getTotalHolders',
}),
isLoading: false,
isError: false,
...(useContractReads({
contracts: [
{
address: MOCK_TOKEN,
abi: ERC20SnapshotRep.abi,
functionName: 'getTotalHolders',
},
],
}) as any),
}));

useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, isRepGuild);

expect(mockUseContractRead).toBeCalledWith(
expect.objectContaining({
functionName: 'getTotalHolders',
})
);
expect(mockUseContractRead).toHaveBeenCalledWith({
contracts: [
{
address: MOCK_TOKEN,
abi: ERC20SnapshotRep.abi,
functionName: 'getTotalHolders',
},
],
});
});

it('should call getTotalMembers when isRepGuild is false', () => {
const isRepGuild = false;

const mockUseContractRead = jest
.spyOn(wagmi, 'useContractRead')
.spyOn(wagmi, 'useContractReads')
.mockImplementationOnce(() => ({
...useContractRead({
addressOrName: MOCK_GUILD_ADDRESS,
contractInterface: MOCK_CONTRACT_INTERFACE,
functionName: 'getTotalMembers',
}),
isLoading: false,
isError: false,
...(useContractReads({
contracts: [
{
address: MOCK_GUILD_ADDRESS,
abi: BaseERC20Guild.abi,
functionName: 'getTotalMembers',
},
],
}) as any),
}));

useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, isRepGuild);

expect(mockUseContractRead).toBeCalledWith(
expect.objectContaining({
functionName: 'getTotalMembers',
})
);
expect(mockUseContractRead).toHaveBeenCalledWith({
contracts: [
{
address: MOCK_GUILD_ADDRESS,
abi: BaseERC20Guild.abi,
functionName: 'getTotalMembers',
},
],
});
});
});
Loading

0 comments on commit 72e9539

Please sign in to comment.