-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor(ConnectWalletForm): preserve key in errors #641
Conversation
Extension builds preview
|
setAutoKeyShareFailed(false); | ||
}, [clearConnectState]); | ||
|
||
const toErrorInfo = React.useCallback( | ||
(err?: string | ErrorWithKeyLike | null): ErrorInfo | null => { |
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 do we have the error as string as well? Can't we pass the whole error directly? For example here:
web-monetization-extension/src/popup/components/ConnectWalletForm.tsx
Lines 114 to 124 in a012ce4
try { | |
setIsValidating((_) => ({ ..._, walletAddressUrl: true })); | |
const url = new URL(toWalletAddressUrl(walletAddressUrl)); | |
const walletAddress = await getWalletInfo(url.toString()); | |
setWalletAddressInfo(walletAddress); | |
} catch (error) { | |
setErrors((_) => ({ | |
..._, | |
walletAddressUrl: toErrorInfo(error.message), | |
})); | |
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.
If we allow passing { message: string }
(which matches Error
), we've to always add a check for isErrorWithKey
, which is more expensive then typeof err === 'string'
.
I'll look into rationalizing error types as a follow-up. I basically want only Error
({ messsage: string }
) and ErrorWithKeyLike
, with failure
or ErrorResponse
allowing returning serialization of either.
walletAddressUrl: toErrorInfo(errWalletAddressUrl), | ||
amount: toErrorInfo(errAmount), |
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 are mixing errors as exceptions and errors as value with the validateWalletAddressUrl
and validateAmount
. Not a big fan, but I understand why this approach.
It might be worth looking into neverthrow later on.
Earlier, we stored only localized message in
errors[foo]
. Now we preserve thekey
and original error under{info}
; and add the localized message under{message}
.This will help with error handling based on key, and paves way to support retry add-key on retry-able errors (such as timed out waiting for login, wrong account was logged in, key-add consent accidentally declined etc.)
Part of #613