Skip to content

Commit 72e9539

Browse files
authored
Merge pull request #451 from DXgovernance/release/v2.2.0
Release/v2.2.0
2 parents bcba1b1 + 0a7f9b7 commit 72e9539

File tree

90 files changed

+5816
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+5816
-674
lines changed

config-overrides.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (config, env) => {
1010
type: 'javascript/auto',
1111
resolve: {
1212
fullySpecified: false,
13-
}
13+
},
1414
});
1515

1616
config.plugins = [
@@ -20,11 +20,12 @@ module.exports = (config, env) => {
2020
process: 'process/browser',
2121
Buffer: ['buffer', 'Buffer'],
2222
}),
23-
]
23+
];
2424
if (env !== 'production') {
2525
return config;
2626
}
2727
config.output.filename = `static/js/[name].js`;
2828
config.output.chunkFilename = `static/js/[name].chunk.js`;
2929
return config;
3030
};
31+

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "davi",
3-
"version": "2.1.1",
3+
"version": "2.2.0",
44
"description": "Decentralized Autonomous Voting Interface",
55
"scripts": {
66
"dev": "./scripts/dev.sh",
@@ -64,10 +64,10 @@
6464
"copy-to-clipboard": "^3.3.1",
6565
"crypto-js": "^4.1.1",
6666
"diff": "^5.1.0",
67-
"dxdao-contracts": "https://github.com/DXgovernance/dxdao-contracts.git#develop",
67+
"dxdao-contracts": "https://github.com/DXgovernance/dxdao-contracts.git#50db3f0754b5ea1a46342857b9520fa0c5250221",
6868
"eslint-config-react-app": "^7.0.1",
6969
"eslint-plugin-cypress": "^2.12.1",
70-
"ethers": "^5.5.2",
70+
"ethers": "^5.7.2",
7171
"git-revision-webpack-plugin": "^3.0.6",
7272
"hardhat": "^2.9.1",
7373
"hardhat-dependency-compiler": "^1.1.2",
@@ -114,8 +114,8 @@
114114
"ts-node": "^10.9.1",
115115
"turndown": "^7.1.1",
116116
"typechain-target-ethers-v5": "^5.0.1",
117-
"typescript": "^4.5.5",
118-
"wagmi": "^0.5.6",
117+
"typescript": "^4.9.3",
118+
"wagmi": "^0.7.15",
119119
"webpack": "4.44.2",
120120
"webpack-manifest-plugin": "^2.2.0",
121121
"workbox-webpack-plugin": "^5.1.4"

src/Modules/Guilds/Hooks/fixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const MOCK_CONTRACT_ADDRESSES = [
1515
'0x0000000000000000000000000000000000000002',
1616
'0x0000000000000000000000000000000000000003',
1717
];
18-
export const MOCK_PROPOSAL_ID = '1';
18+
export const MOCK_PROPOSAL_ID = '0x01';
1919
export const MOCK_PROPOSAL_VOTES = 1;
2020
export const MOCK_TOTAL_LOCKED_AT = 1;
2121
export const MOCK_USER_ADDRESS = '0x0000000000000000000000000000000000000004';
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import useGuildImplementationTypeConfig from 'Modules/Guilds/Hooks/useGuildImplementationType';
2-
import SnapshotERC20Guild from 'contracts/SnapshotERC20Guild.json';
3-
import { useContractRead } from 'wagmi';
2+
import { useContractEvent, useContractRead } from 'wagmi';
3+
import { SnapshotERC20Guild } from 'contracts/ts-files/SnapshotERC20Guild';
44

55
interface useCurrentSnapshotIdProps {
66
contractAddress: string;
@@ -10,13 +10,23 @@ const useCurrentSnapshotId = ({
1010
contractAddress,
1111
}: useCurrentSnapshotIdProps) => {
1212
const { isSnapshotGuild } = useGuildImplementationTypeConfig(contractAddress);
13-
return useContractRead({
13+
const { data, refetch, ...rest } = useContractRead({
1414
enabled: isSnapshotGuild,
15-
addressOrName: contractAddress,
16-
contractInterface: SnapshotERC20Guild.abi,
15+
address: contractAddress,
16+
abi: SnapshotERC20Guild.abi,
1717
functionName: 'getCurrentSnapshotId',
18-
watch: true,
1918
});
19+
20+
useContractEvent({
21+
address: isSnapshotGuild ? contractAddress : null,
22+
abi: SnapshotERC20Guild.abi,
23+
eventName: 'ProposalStateChanged',
24+
listener(node, label, owner) {
25+
refetch();
26+
},
27+
});
28+
29+
return { data, refetch, ...rest };
2030
};
2131

2232
export default useCurrentSnapshotId;
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import BaseERC20Guild from 'contracts/BaseERC20Guild.json';
2-
import { useContractRead } from 'wagmi';
1+
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';
2+
import { useContractEvent, useContractRead } from 'wagmi';
33

44
const useActiveProposalsNow = (guildAddress: string) => {
5-
return useContractRead({
6-
addressOrName: guildAddress,
7-
contractInterface: BaseERC20Guild.abi,
5+
const { data, refetch, ...rest } = useContractRead({
6+
address: guildAddress,
7+
abi: BaseERC20Guild.abi,
88
functionName: 'getActiveProposalsNow',
9-
watch: true,
109
});
10+
11+
useContractEvent({
12+
address: guildAddress,
13+
abi: BaseERC20Guild.abi,
14+
eventName: 'ProposalStateChanged',
15+
listener() {
16+
refetch();
17+
},
18+
});
19+
20+
return { data, refetch, ...rest };
1121
};
1222

1323
export default useActiveProposalsNow;

src/Modules/Guilds/Hooks/useGuildConfig.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { BigNumber } from 'ethers';
22
import { useMemo } from 'react';
3-
import BaseERC20GuildContract from 'contracts/BaseERC20Guild.json';
43
import useGuildToken from 'Modules/Guilds/Hooks/useGuildToken';
54
import { useContractReads } from 'wagmi';
65
import { useVotingPowerForProposalExecution } from 'Modules/Guilds/Hooks/useVotingPowerForProposalExecution';
6+
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';
77

88
export type GuildConfigProps = {
9-
permissionRegistry: string;
109
name: string;
10+
token: `0x${string}`;
11+
permissionRegistry: string;
1112
proposalTime: BigNumber;
1213
timeForExecution: BigNumber;
1314
maxActiveProposals: BigNumber;
1415
votingPowerForProposalCreation: BigNumber;
15-
tokenVault: string;
16+
votingPowerForProposalExecution: BigNumber;
17+
tokenVault: `0x${string}`;
1618
lockTime: BigNumber;
1719
voteGas: BigNumber;
1820
maxGasPrice: BigNumber;
1921
votingPowerPercentageForProposalExecution: BigNumber;
2022
votingPowerPercentageForProposalCreation: BigNumber;
2123
minimumMembersForProposalCreation: BigNumber;
2224
minimumTokensLockedForProposalCreation: BigNumber;
23-
votingPowerForProposalExecution: BigNumber;
24-
token: string;
2525
};
2626

2727
const GETTER_FUNCTIONS = [
@@ -41,14 +41,18 @@ const GETTER_FUNCTIONS = [
4141
'getMinimumTokensLockedForProposalCreation',
4242
];
4343

44-
export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
44+
export const useGuildConfig = (
45+
guildAddress: string,
46+
proposalId?: `0x${string}`
47+
) => {
4548
const { data, ...rest } = useContractReads({
4649
contracts: GETTER_FUNCTIONS.map(functionName => ({
47-
addressOrName: guildAddress,
48-
contractInterface: BaseERC20GuildContract.abi,
50+
address: guildAddress,
51+
abi: BaseERC20Guild.abi,
4952
functionName,
5053
})),
5154
});
55+
5256
const { data: token } = useGuildToken(guildAddress);
5357
const { data: votingPowerForProposalExecution } =
5458
useVotingPowerForProposalExecution({
@@ -74,6 +78,13 @@ export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
7478
minimumTokensLockedForProposalCreation,
7579
] = data;
7680

81+
// Made to prevent
82+
// "Type '{} & readonly unknown[]' is not assignable to type '`0x${string}`'"
83+
// doesn't accept ternary operator
84+
let safeTokenVault;
85+
if (!tokenVault) safeTokenVault = undefined;
86+
else safeTokenVault = tokenVault;
87+
7788
return {
7889
permissionRegistry: permissionRegistry?.toString(),
7990
name: name?.toString(),
@@ -87,7 +98,7 @@ export const useGuildConfig = (guildAddress: string, proposalId?: string) => {
8798
votingPowerForProposalCreation: votingPowerForProposalCreation
8899
? BigNumber.from(votingPowerForProposalCreation)
89100
: undefined,
90-
tokenVault: tokenVault?.toString(),
101+
tokenVault: safeTokenVault,
91102
lockTime: lockTime ? BigNumber?.from(lockTime) : undefined,
92103
voteGas: voteGas ? BigNumber?.from(voteGas) : undefined,
93104
maxGasPrice: maxGasPrice ? BigNumber?.from(maxGasPrice) : undefined,

src/Modules/Guilds/Hooks/useGuildMemberTotal.test.ts

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,81 @@ import {
33
MOCK_GUILD_MEMBERS_TOTAL,
44
MOCK_GUILD_ADDRESS,
55
MOCK_TOKEN,
6-
MOCK_CONTRACT_INTERFACE,
76
} from 'Modules/Guilds/Hooks/fixtures';
8-
import wagmi, { useContractRead } from 'wagmi';
7+
import wagmi, { useContractReads } from 'wagmi';
8+
import { ERC20SnapshotRep } from 'contracts/ts-files/ERC20SnapshotRep';
9+
import { BaseERC20Guild } from 'contracts/ts-files/BaseERC20Guild';
910

1011
jest.mock('wagmi', () => ({
11-
useContractRead: () => ({
12+
useContractReads: () => ({
1213
data: MOCK_GUILD_MEMBERS_TOTAL,
13-
isLoading: false,
14-
isError: false,
1514
}),
15+
16+
useContractEvent: () => jest.fn(),
1617
}));
1718

1819
describe('useGuildMemberTotal', () => {
1920
it('should return guild member totals', () => {
20-
const { data, isError, isLoading } = useGuildMemberTotal(
21-
MOCK_GUILD_ADDRESS,
22-
MOCK_TOKEN,
23-
false
24-
);
21+
const { data } = useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, false);
2522

2623
expect(data).toMatchInlineSnapshot(`3`);
27-
expect(isError).toBe(false);
28-
expect(isLoading).toBe(false);
2924
});
3025

3126
it('should call getTotalHolders when isRepGuild is true', () => {
3227
const isRepGuild = true;
33-
3428
const mockUseContractRead = jest
35-
.spyOn(wagmi, 'useContractRead')
29+
.spyOn(wagmi, 'useContractReads')
3630
.mockImplementationOnce(() => ({
37-
...useContractRead({
38-
addressOrName: MOCK_GUILD_ADDRESS,
39-
contractInterface: MOCK_CONTRACT_INTERFACE,
40-
functionName: 'getTotalHolders',
41-
}),
42-
isLoading: false,
43-
isError: false,
31+
...(useContractReads({
32+
contracts: [
33+
{
34+
address: MOCK_TOKEN,
35+
abi: ERC20SnapshotRep.abi,
36+
functionName: 'getTotalHolders',
37+
},
38+
],
39+
}) as any),
4440
}));
4541

4642
useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, isRepGuild);
4743

48-
expect(mockUseContractRead).toBeCalledWith(
49-
expect.objectContaining({
50-
functionName: 'getTotalHolders',
51-
})
52-
);
44+
expect(mockUseContractRead).toHaveBeenCalledWith({
45+
contracts: [
46+
{
47+
address: MOCK_TOKEN,
48+
abi: ERC20SnapshotRep.abi,
49+
functionName: 'getTotalHolders',
50+
},
51+
],
52+
});
5353
});
5454

5555
it('should call getTotalMembers when isRepGuild is false', () => {
5656
const isRepGuild = false;
57-
5857
const mockUseContractRead = jest
59-
.spyOn(wagmi, 'useContractRead')
58+
.spyOn(wagmi, 'useContractReads')
6059
.mockImplementationOnce(() => ({
61-
...useContractRead({
62-
addressOrName: MOCK_GUILD_ADDRESS,
63-
contractInterface: MOCK_CONTRACT_INTERFACE,
64-
functionName: 'getTotalMembers',
65-
}),
66-
isLoading: false,
67-
isError: false,
60+
...(useContractReads({
61+
contracts: [
62+
{
63+
address: MOCK_GUILD_ADDRESS,
64+
abi: BaseERC20Guild.abi,
65+
functionName: 'getTotalMembers',
66+
},
67+
],
68+
}) as any),
6869
}));
6970

7071
useGuildMemberTotal(MOCK_GUILD_ADDRESS, MOCK_TOKEN, isRepGuild);
7172

72-
expect(mockUseContractRead).toBeCalledWith(
73-
expect.objectContaining({
74-
functionName: 'getTotalMembers',
75-
})
76-
);
73+
expect(mockUseContractRead).toHaveBeenCalledWith({
74+
contracts: [
75+
{
76+
address: MOCK_GUILD_ADDRESS,
77+
abi: BaseERC20Guild.abi,
78+
functionName: 'getTotalMembers',
79+
},
80+
],
81+
});
7782
});
7883
});

0 commit comments

Comments
 (0)