-
Notifications
You must be signed in to change notification settings - Fork 13
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
feature: Geo blocking with 451 #382
base: main
Are you sure you want to change the base?
Conversation
gbarkhatov
commented
Jul 25, 2024
- general health check error: https://i.imgur.com/ozubBzB.png
- geo 451 error: https://i.imgur.com/qQOScR4.png
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 need to have a separation between the internal representation of the API being available and the fact that we are using the health check endpoint to accomplish that.
src/app/api/getHealthCheck.ts
Outdated
(error.response?.status === 451 || error.request.status === 451) | ||
) { | ||
return { | ||
status: "geoBlocked", |
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.
status: "geoBlocked", | |
status: "geoblocked", |
Weird for a status to have camel case
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.
Done
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.
common syntax for such constant usually using upper case letter with _
Is this something we can agree on as a team and adopt for all future changes?
for example, axios use this pattern https://www.npmjs.com/package/axios#error-type
@@ -35,6 +40,26 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({ | |||
|
|||
const { coinName, networkName } = getNetworkConfig(); | |||
|
|||
const renderHealthCheckTooltip = () => { |
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 tooltip is not about healthcheck
, it's about showing whether someone is geo-blocked or not.
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.
It is health check indeeed, if we get anything besides the normal response we will render an error text OR geo blocking text
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.
Done
<span | ||
className="cursor-pointer text-xs" | ||
data-tooltip-id={`tooltip-connect-${healthCheck.status}`} | ||
data-tooltip-content={healthCheck.message} |
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 are we getting the content for a tooltip directly out of the error returned from an API response? The API response should not specify the content, the API response should specify what went wrong, and based on what went wrong we construct the content in the content component.
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.
Ok
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.
Done
src/app/types/healthCheck.ts
Outdated
@@ -0,0 +1,4 @@ | |||
export type HealthCheckResult = | |||
| { status: "normal"; message: string } |
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.
normal
, geoblocked
and error
should be constants.
Otherwise, we could also have an enum, but I understand that's difficult in js.
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.
Done
messages={[ | ||
"The Bitcoin Staking functionality is not available at the moment.", | ||
]} | ||
icon={healthCheckFailed} |
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 icon has nothing to do with health check. Health check is the endpoint that we use to check whether the API is available. The icon name should be something along the lines of apiNotAvailable
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.
Done
@@ -83,6 +87,7 @@ export const Staking: React.FC<StakingProps> = ({ | |||
setDelegationsLocalStorage, | |||
btcWalletBalanceSat, | |||
availableUTXOs, | |||
healthCheck, |
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.
healthCheck, | |
apiAvailable, |
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.
@vitsalis you want it only in Staking? Or do you want me to change the healthCheck
completely to apiAvailable
?
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.
Done
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.
Ideally, I would like an extra layer between healthcheck and the rest of the application, but this might be overengineering, so lgtm.
@@ -17,13 +25,15 @@ interface ConnectSmallProps { | |||
address: string; | |||
btcWalletBalanceSat?: number; | |||
onDisconnect: () => void; | |||
apiAvailable?: HealthCheckResult; |
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 is this ?
?
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.
It is undefined before we fetch and get into one of the normal - geoblocking - error
state
@@ -35,6 +45,31 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({ | |||
|
|||
const { coinName, networkName } = getNetworkConfig(); | |||
|
|||
const renderApiAvailableTooltip = () => { |
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.
const renderApiAvailableTooltip = () => { | |
const renderApiNotAvailableTooltip = () => { |
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.
Let's also have a comment describing what this function's purpose is.
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.
Done
<button | ||
className="btn-primary btn h-[2.5rem] min-h-[2.5rem] rounded-full px-2 text-white md:rounded-lg" | ||
onClick={onConnect} | ||
disabled={!!address || !isApiNormal} |
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.
Let's add a comment denoting that we disable the button if the API is not healthy.
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.
Done
@jrwbabylonchain @jeremy-babylonchain waiting for the 2nd pair of eyes |
Dumping my thoughts about the PR.
For the health check case, I feel this is quite confusing using the healthcheck result type outside of the api client. why would react component need to have knowledge of "backend healthcheck"? The more i think about it, the more i think it's due to the fact that our current
To summarise, I think we shall take this healthcheck as a good opportunity to standandarise the layers and avoid involving API specific types across the repo. i.e this shall not appear https://github.com/babylonchain/simple-staking/pull/382/files#diff-8be97df2c2968a8d06ade0ed70c78ddde9ff115505d6335ecff9119d47b47dbfR28 it shall be replaced with more domain specific things such as Dependency We are injecting the |
|