Skip to content

Commit

Permalink
Merge pull request steemit#2506 from steemit/2387-form-validate-debou…
Browse files Browse the repository at this point in the history
…nce-regression

fix form validate debounce regression
  • Loading branch information
bnchdrff authored Feb 12, 2018
2 parents 85b91d9 + 9567a9a commit 83656b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
31 changes: 17 additions & 14 deletions src/app/utils/ChainValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ export function validate_memo_field(value, username, memokey) {
let suffix;
value = value.split(' ').filter(v => v != '');
for (var w in value) {
if (PrivateKey.isWif(value[w])) {
return (suffix = 'Do not use private keys in memos. ');
}
if (
memokey ===
PrivateKey.fromSeed(username + 'memo' + value[w])
.toPublicKey()
.toString()
) {
return (suffix = 'Do not use passwords in memos. ');
}
if (/5[HJK]\w{40,45}/i.test(value[w])) {
return (suffix =
'Please do not include what appears to be a private key or password. ');
// Only perform key tests if it might be a key, i.e. it is a long string.
if (value[w].length >= 39) {
if (/5[HJK]\w{40,45}/i.test(value[w])) {
return (suffix =
'Please do not include what appears to be a private key or password. ');
}
if (PrivateKey.isWif(value[w])) {
return (suffix = 'Do not use private keys in memos. ');
}
if (
memokey ===
PrivateKey.fromSeed(username + 'memo' + value[w])
.toPublicKey()
.toString()
) {
return (suffix = 'Do not use passwords in memos. ');
}
}
}
return null;
Expand Down
18 changes: 1 addition & 17 deletions src/app/utils/ReactForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
@arg {object} initialValues required for checkboxes {save: false, ...}
@arg {function} validation - values => ({ username: ! values.username ? 'Required' : null, ... })
*/
const USER_INPUT_DEBOUNCE_MS = 400;

export default function reactForm({
name,
instance,
fields,
initialValues,
validation = () => {},
}) {
let debounce = { timeout: null };
if (typeof instance !== 'object')
throw new TypeError('instance is a required object');
if (!Array.isArray(fields))
Expand Down Expand Up @@ -124,13 +121,7 @@ export default function reactForm({
}

instance.setState({ [fieldName]: v }, () => {
setFormStateDebounce(
name,
instance,
fields,
validation,
debounce
);
setFormState(name, instance, fields, validation);
});
};

Expand All @@ -143,13 +134,6 @@ export default function reactForm({
}
}

function setFormStateDebounce(name, instance, fields, validation, debounce) {
clearTimeout(debounce.timeout);
debounce.timeout = setTimeout(function() {
setFormState(name, instance, fields, validation);
}, USER_INPUT_DEBOUNCE_MS);
}

function setFormState(name, instance, fields, validation) {
let formValid = true;
let formTouched = false;
Expand Down

0 comments on commit 83656b7

Please sign in to comment.