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

feat: improve role detection #159

Merged
merged 12 commits into from
Sep 9, 2024
Merged

feat: improve role detection #159

merged 12 commits into from
Sep 9, 2024

Conversation

aon
Copy link
Collaborator

@aon aon commented Sep 6, 2024

No description provided.

@aon aon marked this pull request as draft September 6, 2024 15:57
@aon aon requested a review from calvogenerico September 6, 2024 19:11
@aon aon marked this pull request as ready for review September 6, 2024 19:11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fancy

required,
}: { required?: boolean } = {}):
| { address: Address; role: UserRole }
| { address?: Address; role?: UserRole } {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love how this function works. When using something like this I would expect it to return null instead an object with undefined inside.

There could even be 2 hooks, one that returns { address: Address; role: UserRole }| null dependeng on if the users is logged in or not, and another one that returns { address: Address; role: UserRole } or fails.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly how it works! If required is false, then all parameters are optional. I agree we could make it or | null the entire object instead of each value but it's the same behaviour.

useEffect(() => {
return watchAccount(config, {
onChange(account, prevAccount) {
if (account.address !== prevAccount.address && account.address !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't do anything if the acc.address is undefined? Shouldn't the cookie be clear?

Copy link
Collaborator Author

@aon aon Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that, but it shouldn't affect app behaviour.

Update: severely improved role changer, with zod validation and correctly deleting cookies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't, I would love a comment explaining why it's not needed. I feel that it's not obvious.


export async function action({ request }: ActionFunctionArgs) {
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
await sleep(5000); //FIXME remove
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely add a CI that searches for FIXMEs 🙄

required,
}: { required?: boolean } = {}):
| { address: Address; role: UserRole }
| { address?: Address; role?: UserRole } {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly how it works! If required is false, then all parameters are optional. I agree we could make it or | null the entire object instead of each value but it's the same behaviour.

useEffect(() => {
return watchAccount(config, {
onChange(account, prevAccount) {
if (account.address !== prevAccount.address && account.address !== undefined) {
Copy link
Collaborator Author

@aon aon Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that, but it shouldn't affect app behaviour.

Update: severely improved role changer, with zod validation and correctly deleting cookies.


export async function action({ request }: ActionFunctionArgs) {
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
await sleep(5000); //FIXME remove
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely add a CI that searches for FIXMEs 🙄

@aon aon requested a review from calvogenerico September 9, 2024 15:15
@aon aon merged commit 0ad36af into develop Sep 9, 2024
11 checks passed
@aon aon deleted the feat/improve-role-detection branch September 9, 2024 18:32
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