-
Notifications
You must be signed in to change notification settings - Fork 233
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
update state management and validation #721
Conversation
wallet-web/components/bond/utils.ts
Outdated
} | ||
|
||
if (value.endsWith('.')) { | ||
value = value.slice(0, value.length - 1) |
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.
I'm not entirely sure I understand that, why are we removing the last character if it's a .
?
wallet-web/components/bond/utils.ts
Outdated
} | ||
|
||
export const isValidHostname = (value) => { | ||
if (typeof value !== 'string') return false |
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.
We have the niceness of typescript, so change your function definition to export const isValidHostname = (value: string)
and the check will be done at compile time : )
wallet-web/components/bond/utils.ts
Outdated
return false | ||
} | ||
|
||
const labels = value.split('.') |
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.
What if we are faced with an ipv6 address that is separated by :
(and has bunch of edge cases)?
Also remember that a hostname like nymtech.net
should also be valid
wallet-web/common/helpers.ts
Outdated
return port >= 1 && port <= 65535 | ||
} | ||
export const validateRawPort = (rawPort: number): boolean => | ||
typeof rawPort === 'number' && |
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.
the typeof rawPort === 'number'
check is redundant, we know for sure it's a number since typescript wouldn't allow anything else here
I appreciate these some of these files might be tricky to compare due to the changes that I've made. I'm happy to talk through the changes if that's preferred.
In a nutshell I have split the original bond form component out into three parts
The biggest change is running validation checks in real-time instead of on submission. The 'Bond' button will be disabled until all fields are valid. Validation functions remain the same apart from the validateHost function which I've updated.
I'll keep this as a draft PR until I've finished testing.