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

[ENG-210] ERC-721 Whitelisting; Voting section not showing #2722

Merged
merged 5 commits into from
Feb 10, 2025

Conversation

Da-Colon
Copy link
Contributor

@Da-Colon Da-Colon commented Feb 8, 2025

Close ENG-210

Changes

  • (Main fix) Ensure linearVotingErc721WithHatsWhitelistingAddress contract address is checked for loading erc721 tokens
  • extracted logic for readibility
  • refactored nested promises with a flatmap

@Da-Colon Da-Colon self-assigned this Feb 8, 2025
Copy link

linear bot commented Feb 8, 2025

Copy link

cloudflare-workers-and-pages bot commented Feb 8, 2025

Deploying decent-interface with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2c858c9
Status: ✅  Deploy successful!
Preview URL: https://4b4fb0c4.decent-interface.pages.dev
Branch Preview URL: https://eng-210-erc-721-whitelist-no.decent-interface.pages.dev

View logs

Comment on lines +42 to +45
governanceContracts: {
linearVotingErc721Address,
linearVotingErc721WithHatsWhitelistingAddress,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main thing was we weren't account for the second type of contract


const globalContextSafeAddress = safe?.address;
// Means getting these for any safe, primary use case - calculating user voting weight for freeze voting
const getUserVotingTokenData = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extracted out some code for readability into own callback

}),
const globalContextSafeAddress = safe?.address;

const getUserERC721VotingTokens = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main function is a little easier to follow

Comment on lines +197 to +204
if (_safeAddress && globalContextSafeAddress !== _safeAddress) {
const userVotingTokenData = await getUserVotingTokenData(_safeAddress);
if (userVotingTokenData) {
governanceTokens = userVotingTokenData.governanceTokens;
votingType = userVotingTokenData.votingType;
linearVotingAddress = userVotingTokenData.linear721VotingAddress;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF being used outside the context of viewing safe these variables are updated.

Comment on lines +218 to 232
const tokenDataPromises = Array.from(userERC721Tokens.entries()).flatMap(
([tokenAddress, tokenIdsSet]) => {
return Array.from(tokenIdsSet).map(async tokenId => {
let hasVoted = false;
if (_proposalId !== null) {
hasVoted = await votingContract.read.hasVoted([
_proposalId,
tokenAddress,
BigInt(tokenId),
]);
}
return { tokenAddress, tokenId, hasVoted };
});
},
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the nested promises to a flatmap of promises to optimise this section

Comment on lines -237 to +277
if (loadOnMount && linearVotingErc721Address) {
if (loadOnMount) {
loadUserERC721VotingTokens();
}
}, [loadUserERC721VotingTokens, loadOnMount, linearVotingErc721Address]);
}, [loadUserERC721VotingTokens, loadOnMount]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't believe we need to hold this one back. if there is no contract it will just set defaults

@Da-Colon Da-Colon marked this pull request as ready for review February 8, 2025 17:41
@Da-Colon Da-Colon merged commit 50eeafd into develop Feb 10, 2025
4 checks passed
@Da-Colon Da-Colon deleted the ENG-210-erc-721-whitelist-no-voting branch February 10, 2025 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants