Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ea3ee63
include approval action in asset transfer permissions
MiltonTulli Sep 19, 2022
25ebace
change edit mode
MiltonTulli Sep 19, 2022
d0bc569
refactor actionsmodal to acept decodedactions array as submit value
MiltonTulli Sep 19, 2022
f3e1706
Merge branch 'develop' into feature/approve-asset-transfer
MiltonTulli Nov 9, 2022
bb0fb70
use baseCall to spread
MiltonTulli Nov 9, 2022
f03fbaf
feat(useProposal): removed watch:true and added event listeners
dcrescimbeni Nov 14, 2022
692e6de
refactor: moved getProposalIdFromEvent to utils folder
dcrescimbeni Nov 14, 2022
79a5ddd
test(event): added tests
dcrescimbeni Nov 14, 2022
5faa0e6
refactor(useProposalVotesOfVoter): removed watch flag and added event…
dcrescimbeni Nov 14, 2022
13db20b
feat(event): added getProposalStateFromEvent method
dcrescimbeni Nov 14, 2022
ba2e404
refactor: removed watch flag and replaced with event listeners
dcrescimbeni Nov 14, 2022
c22bb47
refactor(useProposalVotes): removed watch flag and replaced with even…
dcrescimbeni Nov 15, 2022
46016cd
refactor(ERC20-contract-reads): removed watch flag and replaced with …
dcrescimbeni Nov 15, 2022
7666fe1
feat(event): added getVoterFromEvent method
dcrescimbeni Nov 15, 2022
0479e3b
refactor: removed watch flag and replaced with event listeners
dcrescimbeni Nov 15, 2022
00bf8c9
refactor: replaced watch flag with event listener
dcrescimbeni Nov 16, 2022
9d9121d
Merge branch 'develop' into refactor/watch-flags
dcrescimbeni Nov 16, 2022
f641e79
feat: upgraded to wagmi 0.8
dcrescimbeni Nov 17, 2022
3c41cf3
Add conditional flag to NumericalInput to display or not the X icon t…
MiltonTulli Nov 21, 2022
894d818
Fix guildconfig action validation to display proper error labels for …
MiltonTulli Nov 21, 2022
a082dfc
Merge pull request #435 from rossneilson/feature/increment-version-2.1.1
rossneilson Nov 23, 2022
806f765
Use specific dxdao-contracts commit hash instead of develop branch
MiltonTulli Nov 25, 2022
b795a92
Merge pull request #437 from MiltonTulli/fix-contracts-pkg
MiltonTulli Nov 25, 2022
eade04f
feat: upgraded wagmi to 0.8
dcrescimbeni Nov 25, 2022
0fecba3
fix: merge
dcrescimbeni Nov 25, 2022
50b4610
fix(useGuildConfig): tokenVault typescript error
dcrescimbeni Nov 25, 2022
a6a3c24
Merge branch 'develop' into feature/approve-asset-transfer
MiltonTulli Nov 29, 2022
659d0d3
perf: upgraded wagmi to latest version
dcrescimbeni Dec 1, 2022
7a3546a
perf: reduced refetch() calls
dcrescimbeni Dec 1, 2022
c52c883
fix: removed debuggers
dcrescimbeni Dec 2, 2022
871e7f7
feat: downgraded to wagmi 0.7.15
dcrescimbeni Dec 2, 2022
b6fb035
Merge pull request #325 from MiltonTulli/feature/approve-asset-transfer
rossneilson Dec 2, 2022
2434e54
Fix translation typo
MiltonTulli Dec 4, 2022
4c44bdc
Merge pull request #424 from dcrescimbeni/refactor/watch-flags
rossneilson Dec 6, 2022
cf560dd
Merge pull request #429 from MiltonTulli/fix/setGuildConfig-validatio…
rossneilson Dec 6, 2022
7ee1ff6
docs(package.json): increased version number to 2.2.0
dcrescimbeni Dec 6, 2022
f8a539c
Merge pull request #453 from dcrescimbeni/deploy/increase-version-2-2-0
dcrescimbeni Dec 6, 2022
0a7f9b7
Merge branch 'master' into release/v2.2.0
dcrescimbeni Dec 6, 2022
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
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