Skip to content
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

Merged
merged 20 commits into from
Aug 9, 2021

Conversation

fmtabbara
Copy link
Contributor

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

  • Utility functions (utils.ts)
  • State management (useBondForm.ts)
  • UI (BondNodeForm.tsx)

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.

@fmtabbara fmtabbara self-assigned this Aug 3, 2021
}

if (value.endsWith('.')) {
value = value.slice(0, value.length - 1)
Copy link
Contributor

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 .?

}

export const isValidHostname = (value) => {
if (typeof value !== 'string') return false
Copy link
Contributor

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 : )

return false
}

const labels = value.split('.')
Copy link
Contributor

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

@fmtabbara fmtabbara marked this pull request as ready for review August 6, 2021 11:04
return port >= 1 && port <= 65535
}
export const validateRawPort = (rawPort: number): boolean =>
typeof rawPort === 'number' &&
Copy link
Contributor

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

@fmtabbara fmtabbara merged commit 132d550 into develop Aug 9, 2021
@fmtabbara fmtabbara deleted the update/bond-form-state-management branch August 9, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants