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

TokenService improvements #541

Merged
merged 11 commits into from
Jul 28, 2021
Merged

TokenService improvements #541

merged 11 commits into from
Jul 28, 2021

Conversation

kumavis
Copy link
Member

@kumavis kumavis commented Jul 27, 2021

  1. should throw if api returns a json error. api returns a 200 ok but with json error obj
    we should check for that an elevate to an error
  2. token lookup uri is wrong. fixed. (nice catch @NiranjanaBinoy !)
  3. return types were wrong, fixed.
  4. added fallback value for safelyExecute usage
  5. removed unsound safelyExecute usage

i guess this is a breaking change bc types?

@kumavis kumavis requested a review from a team as a code owner July 27, 2021 23:19
NiranjanaBinoy
NiranjanaBinoy previously approved these changes Jul 27, 2021
Copy link
Contributor

@NiranjanaBinoy NiranjanaBinoy left a comment

Choose a reason for hiding this comment

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

LGTM

@kumavis
Copy link
Member Author

kumavis commented Jul 27, 2021

we need this for every api endpoint, eh?

@kumavis kumavis marked this pull request as draft July 27, 2021 23:53
@kumavis kumavis marked this pull request as ready for review July 27, 2021 23:54
@kumavis kumavis changed the title TokenService should throw if api returns an error TokenService improvements Jul 28, 2021
@kumavis
Copy link
Member Author

kumavis commented Jul 28, 2021

please verify my changes are sound around safelyExecute

async function parseJsonResponse(apiResponse: Response): Promise<unknown> {
const responseObj = await apiResponse.json();
// api may return errors as json without setting an error http status code
if (responseObj?.error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is the ? necessary given we are checking for the props existence in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

responseObj could be null, thats valid json
unlikely tho

Copy link
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

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

LGTM

@kumavis kumavis merged commit 77e6bbf into main Jul 28, 2021
@kumavis kumavis deleted the kumavis-patch-1 branch July 28, 2021 18:09
@rickycodes rickycodes mentioned this pull request Jul 28, 2021
rickycodes added a commit that referenced this pull request Aug 3, 2021
…to dynamic-speed-up

* 'dynamic-speed-up' of github.com:MetaMask/controllers:
  Bump @metamask/auto-changelog from 2.4.0 to 2.5.0 (#549)
  Update Changelog (#548)
  14.0.2 (#547)
  Fix `resetPolling` functionality (#546)
  TokenService improvements (#541)
  Release/14.0.1 (#545)
  Make gweiDecToWEIBN util resilient against params with too many decimals (#544)
  Bump @metamask/contract-metadata from 1.27.0 to 1.28.0 (#540)
  14.0.0 (#539)
  Bug: Mainnet NFT Autodetect API  (#536)
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Update token-service.ts

* Update token-service.ts

* Update token-service.ts

* lint fix

* token-service - break out parsing of response to only those that have a response

* TokenListController - fallback to empty array

* TokenListController - remove unsound safety wrapper

* TokenListController - fix endpoint for token lookup

* lint fix
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* Update token-service.ts

* Update token-service.ts

* Update token-service.ts

* lint fix

* token-service - break out parsing of response to only those that have a response

* TokenListController - fallback to empty array

* TokenListController - remove unsound safety wrapper

* TokenListController - fix endpoint for token lookup

* lint fix
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.

None yet

4 participants