-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
…d make sure write tests that make sure updating still works
… need to work on updating config to do the same. finally add tests for both criterias
Will Squash and Merge. |
contracts/cw3-dao/src/contract.rs
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
contracts/cw3-dao/src/contract.rs
Outdated
@@ -51,13 +57,25 @@ pub fn instantiate( | |||
|
|||
msg.threshold.validate()?; | |||
|
|||
match &msg.image_url { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)?;
contracts/cw3-dao/src/tests.rs
Outdated
fn test_validate_image_url() { | ||
assert_eq!( | ||
validate_image_url(&"https://fefeqfq.com/imgur.jpg".to_string()), | ||
true | ||
); |
There was a problem hiding this comment.
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
Will fix clippy once overall code logic gets approved! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
contracts/cw3-dao/src/contract.rs
Outdated
@@ -51,13 +57,25 @@ pub fn instantiate( | |||
|
|||
msg.threshold.validate()?; | |||
|
|||
match &msg.image_url { |
There was a problem hiding this comment.
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)?;
contracts/cw3-dao/src/contract.rs
Outdated
@@ -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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@ezekiiel Updated code (no longer doing regex). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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.
ACK, will update |
@JakeHartnell added changes 🙏 |
Amazing! Can you squash these commits into some meaningful messages? Then we're good to go. 🚀 Thanks for this. |
Ughhhhh, annoying not having branch protection rules. 😦 |
No description provided.