frames_core/validators/
button.rs

1use crate::types::{
2    button::FrameButton,
3    errors::{Error, ErrorCode, FrameErrors},
4};
5
6impl FrameButton {
7    const VALID_ACTIONS: [&'static str; 4] = ["post_redirect", "post", "mint", "link"];
8
9    pub fn validate(&self) -> Result<(), FrameErrors> {
10        let mut errors = FrameErrors::new();
11
12        match &self.action {
13            Some(action) if !Self::VALID_ACTIONS.contains(&action.as_str()) => {
14                let error = Error {
15                    code: ErrorCode::InvalidButtonAction,
16                    description: "Invalid button action specified".to_string(),
17                    key: Some(format!("fc:frame:button:{}:action", self.id)),
18                };
19                errors.add_error(error);
20            }
21            _ => {}
22        }
23
24        if !errors.is_empty() {
25            return Err(errors);
26        }
27
28        Ok(())
29    }
30}