Skip to content

Conversation

@NiranjanaBinoy
Copy link
Contributor

@NiranjanaBinoy NiranjanaBinoy commented May 26, 2021

The purpose of the controller is to poll the new token detection API tokens/:chainId at regular intervals to get the list of tokens dynamically instead of getting it from @metamask/contract-metadata. The controller also calls on the /sync/:chainId API which initiates sync on the token list in the background and tokens/:chainId?address=<tokenAddress> which returns the metadata of the token whose address is provided.

This controller will be used by detect-token.js(DetectTokensController) from metamask-extension repo and AssetsDetectionController.ts from metamask/controllers repo. AssetsDetectionController.ts is updated as a part of this PR to use the TokeListcontroller as a source of the token list instead of @metamask/contract-metadata.

@NiranjanaBinoy NiranjanaBinoy self-assigned this May 26, 2021
@NiranjanaBinoy NiranjanaBinoy force-pushed the token-list-controller branch 3 times, most recently from 3805dc6 to aac1d7d Compare June 3, 2021 16:09
@NiranjanaBinoy NiranjanaBinoy force-pushed the token-list-controller branch from 86ddfb7 to 3d6e2c4 Compare June 16, 2021 20:33
@NiranjanaBinoy NiranjanaBinoy marked this pull request as ready for review June 16, 2021 21:51
@NiranjanaBinoy NiranjanaBinoy requested a review from a team as a code owner June 16, 2021 21:51
@NiranjanaBinoy NiranjanaBinoy changed the title Controller to fetch the token list from metaswaps api Adding TokenListController to fetch the token list from token services API Jun 17, 2021
@NiranjanaBinoy NiranjanaBinoy force-pushed the token-list-controller branch from 77ec776 to aeed783 Compare June 17, 2021 16:37
@mobularay
Copy link

@NiranjanaBinoy do you still need more input / feedback from Mobile? Thank you!

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

Left some comments. Great work! 👍

@adonesky1
Copy link
Contributor

Should there be a method present on the controller to update the chainId on the this.networkController.on(NETWORK_EVENTS.NETWORK_DID_CHANGE event?

@brad-decker
Copy link
Contributor

brad-decker commented Jun 25, 2021

@adonesky1 I thiknk that is setup differently in controllers repo: see these lines

https://github.com/MetaMask/controllers/pull/478/files#diff-c2ec75b01a3b2e2e1284df7c48ad4c80a26ea7f1455167cc8390d91ca865b854R121-R123

EDIT:

onNetworkStateChange: (callback) => { 
  this.networkController.on(NETWORK_EVENTS.NETWORK_DID_CHANGE, () => { 
   const chainId = this.networkController.getCurrentChainId();
   callback({ chainId });
  });
},

Alternatively we might want to think about emitting a CHAIN_CHANGED event somewhere too that gets the new chainId emitted. NETWORK_DID_CHANGE in extension only emits the network type (mainnet/rinkeby/rpc)

@adonesky1
Copy link
Contributor

@adonesky1 I thiknk that is setup differently in controllers repo: see these lines

Oh weird I had pulled down and was looking at an older version of this PR that didn't contain those lines... LGTM

Copy link
Contributor

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

One NIT that may be easily dismissed, curious about the follow up question though! Leaving this as 'request changes' but should be easy to convert me to a ✅

Copy link
Contributor

@brad-decker brad-decker left a comment

Choose a reason for hiding this comment

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

LGTM

@NiranjanaBinoy NiranjanaBinoy merged commit 84b410f into main Jun 28, 2021
@NiranjanaBinoy NiranjanaBinoy deleted the token-list-controller branch June 28, 2021 17:53
rickycodes added a commit that referenced this pull request Jun 30, 2021
…lers into draft-gasfee-controller

* 'draft-gasfee-controller' of github.com:MetaMask/controllers:
  Bump @metamask/auto-changelog from 2.3.0 to 2.4.0 (#499)
  Adding TokenListController to fetch the token list from token services API (#478)
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.

8 participants