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

Add optional img url to dao #138

Merged
merged 20 commits into from
Jan 17, 2022
Merged

Add optional img url to dao #138

merged 20 commits into from
Jan 17, 2022

Conversation

0xjame5
Copy link
Contributor

@0xjame5 0xjame5 commented Jan 16, 2022

No description provided.

@0xjame5
Copy link
Contributor Author

0xjame5 commented Jan 16, 2022

Will Squash and Merge.

@@ -40,6 +41,11 @@ const DEFAULT_LIMIT: u32 = 10;
const INSTANTIATE_GOV_TOKEN_REPLY_ID: u64 = 0;
const INSTANTIATE_STAKING_CONTRACT_REPLY_ID: u64 = 1;

pub fn validate_image_url(url: &String) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public to make it easier to test and maybe re-use later

@@ -51,13 +57,25 @@ pub fn instantiate(

msg.threshold.validate()?;

match &msg.image_url {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since this is done twice we can pull this out into a function, tho maybe too much rn

Copy link
Contributor

Choose a reason for hiding this comment

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

Rust's Option has a map method for making this sort of stuff easier. Here's an example using it. If you modify validate_image_url to return Result<(), ContractError> something like this will do:

msg.img_url.map(validate_image_url)?;

Comment on lines 354 to 358
fn test_validate_image_url() {
assert_eq!(
validate_image_url(&"https://fefeqfq.com/imgur.jpg".to_string()),
true
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pulled this out here, otherwise we'd have a lot of code to test each individual type of string + all the other code for msg

@0xjame5
Copy link
Contributor Author

0xjame5 commented Jan 16, 2022

Will fix clippy once overall code logic gets approved!

@0xjame5 0xjame5 requested a review from JakeHartnell January 16, 2022 06:43
Copy link
Contributor

@0xekez 0xekez left a comment

Choose a reason for hiding this comment

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

Nice work!

@@ -51,13 +57,25 @@ pub fn instantiate(

msg.threshold.validate()?;

match &msg.image_url {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rust's Option has a map method for making this sort of stuff easier. Here's an example using it. If you modify validate_image_url to return Result<(), ContractError> something like this will do:

msg.img_url.map(validate_image_url)?;

@@ -40,6 +41,11 @@ const DEFAULT_LIMIT: u32 = 10;
const INSTANTIATE_GOV_TOKEN_REPLY_ID: u64 = 0;
const INSTANTIATE_STAKING_CONTRACT_REPLY_ID: u64 = 1;

pub fn validate_image_url(url: &String) -> bool {
let re = Regex::new(r"(https:)([/|.|\w|\s|-])*\.(?:jpg|gif|png)").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Compiling a regex here makes me a little nervous as this is reasonably computationally expensive. I almost wonder if we should do validation here at all? Seems possible that frontends should be charged with determining if this is an image they can display.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, the frontend could have additional validation for uploading (making sure link is valid IMG) and then when the link if being grabbed.

@0xjame5
Copy link
Contributor Author

0xjame5 commented Jan 17, 2022

@ezekiiel Updated code (no longer doing regex).

Copy link
Member

@JakeHartnell JakeHartnell left a comment

Choose a reason for hiding this comment

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

LGTM

@0xjame5 0xjame5 requested a review from 0xekez January 17, 2022 01:57
Copy link
Member

@JakeHartnell JakeHartnell left a comment

Choose a reason for hiding this comment

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

Can you add this the multisig too? Trying to make them as similar as possible with regards to metadata.

@0xjame5
Copy link
Contributor Author

0xjame5 commented Jan 17, 2022

ACK, will update

@0xjame5
Copy link
Contributor Author

0xjame5 commented Jan 17, 2022

@JakeHartnell added changes 🙏

@JakeHartnell
Copy link
Member

@JakeHartnell added changes

Amazing! Can you squash these commits into some meaningful messages? Then we're good to go. 🚀

Thanks for this.

@0xjame5 0xjame5 merged commit c1ed4cc into main Jan 17, 2022
@JakeHartnell
Copy link
Member

Ughhhhh, annoying not having branch protection rules. 😦

@JakeHartnell JakeHartnell deleted the add-optional-img-url-to-dao branch January 17, 2022 05:06
0xjame5 added a commit that referenced this pull request Jan 17, 2022
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