-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
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.
fancy
required, | ||
}: { required?: boolean } = {}): | ||
| { address: Address; role: UserRole } | ||
| { address?: Address; role?: UserRole } { |
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 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.
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.
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) { |
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.
why we don't do anything if the acc.address is undefined? Shouldn't the cookie be clear?
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 can do that, but it shouldn't affect app behaviour.
Update: severely improved role changer, with zod validation and correctly deleting cookies.
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.
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 |
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.
This can be removed :)
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 should definitely add a CI that searches for FIXMEs 🙄
required, | ||
}: { required?: boolean } = {}): | ||
| { address: Address; role: UserRole } | ||
| { address?: Address; role?: UserRole } { |
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.
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) { |
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 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 |
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 should definitely add a CI that searches for FIXMEs 🙄
No description provided.