fix validator issue on hotp count

This commit is contained in:
bunnie 2022-09-20 23:13:18 +08:00
parent 9225cbaba3
commit ba45fc2685
2 changed files with 14 additions and 1 deletions

View file

@ -239,6 +239,12 @@
"zh": "请输入 1-128 之间的数字",
"en-tts": "Please enter a number from 1-128"
},
"vault.illegal_count": {
"en": "Please enter an integer number",
"ja": "整数を入力してください。",
"zh": "请输入一个整数。",
"en-tts": "Please enter an integer number"
},
"vault.illegal_totp": {
"en": "Shared secret is not valid Base32",
"ja": "共有秘密は無効ですBase32",

View file

@ -396,7 +396,7 @@ impl ActionManager {
self.tt.sleep_ms(SWAP_DELAY_MS).unwrap();
match self.modals
.alert_builder(t!("vault.hotp.count", xous::LANG))
.field(Some("0".to_string()), Some(length_validator))
.field(Some("0".to_string()), Some(count_validator))
.build()
{
Ok(entry) => entry.content()[0].content.as_str().unwrap().parse::<u64>().unwrap(),
@ -1209,3 +1209,10 @@ fn length_validator(input: TextEntryPayload) -> Option<xous_ipc::String<256>> {
_ => Some(xous_ipc::String::<256>::from_str(t!("vault.illegal_number", xous::LANG))),
}
}
fn count_validator(input: TextEntryPayload) -> Option<xous_ipc::String<256>> {
let text_str = input.as_str();
match text_str.parse::<u64>() {
Ok(_input_int) => None,
_ => Some(xous_ipc::String::<256>::from_str(t!("vault.illegal_count", xous::LANG))),
}
}