Skip to content

Conversation

jeetparikh
Copy link
Contributor

  • Add validation to blockscout response to observe change in fields for future
  • Report errors if the validation fails
  • Continue to return the same response as we don't know how to deal with the change exactly

Further, use the error reporting to alert us of the change in fields so we can proactively figure it out.

@jeetparikh jeetparikh requested review from a team as code owners August 22, 2025 02:02
Copy link

nx-cloud bot commented Aug 22, 2025

View your CI Pipeline Execution ↗ for commit 77e954f

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 3s View ↗
nx affected -t build,lint,test ✅ Succeeded 50s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-25 02:32:24 UTC

@@ -1,6 +1,6 @@
{
"root": true,
"extends": [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was a conflicting jsx-ally rule being loaded from both these inherits so had to remove one. I tried adding the one from the root and remove next/ but it resulted in a lot of linting errors that need to be addressed on its own. Currently no lint is really applied as the package.json is linting only *.ts files inside src/ which is ignored by the ignorePatterns from the root eslint rule since it is missing root: true which is added above.

Copy link
Contributor

@keithbro-imx keithbro-imx left a comment

Choose a reason for hiding this comment

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

Had some comments... did you test it with the widget sample app? Or by calling the real api?

if (params.nextPage) url += `&${new URLSearchParams(params.nextPage as Record<string, string>)}`;

// Use the generic httpGet method with schema validation
const response = await this.httpGet<BlockscoutERC20Response>(url, BlockscoutERC20ResponseSchema);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to pass the type parameter given you're passing the schema? The return type should be inferrable from that


export const BlockscoutTokenPaginationSchema = z.record(
z.string(),
z.union([z.string(), z.number(), z.null()]),
Copy link
Contributor

Choose a reason for hiding this comment

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

why like this? and not declaring the specific keys?

// Only validate response structure for successful responses (2xx)
if (response.status >= 200 && response.status < 300) {
try {
const validatedData = schema.parse(response.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

slightly preferable would be to use safeParse to handle the error case- not a blocker though

}

// For non-2xx responses, return data without validation
return Promise.resolve(response.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem quite right - if the response is 400, the return type should probably be unknown

Or it should reject... what does this.httpClient.get currently do if it gets a >= 300 response?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants