-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Assets detection and tokens balances controllers #19
Conversation
…ntract has tokenOfOwnerByIndex method
Codecov Report
@@ Coverage Diff @@
## master #19 +/- ##
======================================
Coverage 100% 100%
======================================
Files 15 18 +3
Lines 694 956 +262
Branches 76 109 +33
======================================
+ Hits 694 956 +262
Continue to review full report at Codecov.
|
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.
Two minor suggestions, but looks great and should be ready to land.
} | ||
try { | ||
const contract = this.web3.eth.contract(abiERC20).at(address); | ||
return await new Promise<typeof BN>((resolve, reject) => { |
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.
Same comment here re: returning the Promise directly.
return await new Promise<typeof BN>((resolve, reject) => { | |
return new Promise<typeof BN>((resolve, reject) => { |
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.
@bitpshr yeah this is weird, I did this as a workaround for web3/web3.js#1119 since the workaround mentioned there wasn't working. The issue is still open, let me know what you think.
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.
Ah, ok, I see. Good catch 👍
* Improve types and type validation * Fix JsonRpcSuccess type * Add functions to check if a value is a JsonRpcResponse * Fix error message * Add test vectors * Move test.data to fixtures folder * Improve error messages
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](gulpjs/glob-parent@v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
v1.0.1 contains two changes that should have been considered semver-major: - Type-interface incompatability with previous version (MetaMask/json-rpc-engine#139) - Introduced dependency `@metamask/json-rpc-engine` indicates a minimum supported Node.js version of 16. This prevents the module from installing on some package manager configurations, like default yarn classic. This will be re-released as v2.0.0.
* assets controller tokens * Update PreferencesController no more tokens responsability * Update AssetsController handling collectibles * Update tests according to new AssetsController * Fix some lines on AssetsController * AssetsController using preferences selected address and assets getter * AssetsController tokens object with selected address as keys * AssetsController test tokens per account * AssetsController tokens by selected address respective test * AssetsController update new tokens when adding token * AssetsController add and remove collectibles per account * AssetsController assets per account and network * AssetsDetectionController basic structure and web3 * AssetsDetectionControllers methods for token detection and collectibles placeholders * update AssetsDetectionController test * web3 changes * AssetsDetectionController detecting tokens * AssetsDetectionController handle web3 unset * AssetsDetectionController correctly detecting tokens * AssetsDetection collectibles first approach * AssetsDetectionCOntroller correctly detecting new collectibles, if contract has tokenOfOwnerByIndex method * AssetsDetection handle ERC721 standard tokens * Collectibles following standard autodetection * AssetsDetection fully api based collectibles * AssetdDetection clean up * AssetsDetection improve documentation * AssetsDetection tests WIP * AssetsDetectionController improve documentation * AssetsDetection bignumber/web3 addition and full line jest coverage * AssetDetection hide private methods and add BigNumber type * AssetdDetection handle web3 send async issue * new AssetsContractController for interaction with asset contracts * AssetsDetection full coverage * fix web3 bignumber dependency * expose AssetsContractController to API * detecting new assets only when account changes or polling period * add fetch-mock where it is possible * restore script test * add TokenBalancesController * expose TokenBalancesController to API * add collectible image util * add missing documentation
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](gulpjs/glob-parent@v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* assets controller tokens * Update PreferencesController no more tokens responsability * Update AssetsController handling collectibles * Update tests according to new AssetsController * Fix some lines on AssetsController * AssetsController using preferences selected address and assets getter * AssetsController tokens object with selected address as keys * AssetsController test tokens per account * AssetsController tokens by selected address respective test * AssetsController update new tokens when adding token * AssetsController add and remove collectibles per account * AssetsController assets per account and network * AssetsDetectionController basic structure and web3 * AssetsDetectionControllers methods for token detection and collectibles placeholders * update AssetsDetectionController test * web3 changes * AssetsDetectionController detecting tokens * AssetsDetectionController handle web3 unset * AssetsDetectionController correctly detecting tokens * AssetsDetection collectibles first approach * AssetsDetectionCOntroller correctly detecting new collectibles, if contract has tokenOfOwnerByIndex method * AssetsDetection handle ERC721 standard tokens * Collectibles following standard autodetection * AssetsDetection fully api based collectibles * AssetdDetection clean up * AssetsDetection improve documentation * AssetsDetection tests WIP * AssetsDetectionController improve documentation * AssetsDetection bignumber/web3 addition and full line jest coverage * AssetDetection hide private methods and add BigNumber type * AssetdDetection handle web3 send async issue * new AssetsContractController for interaction with asset contracts * AssetsDetection full coverage * fix web3 bignumber dependency * expose AssetsContractController to API * detecting new assets only when account changes or polling period * add fetch-mock where it is possible * restore script test * add TokenBalancesController * expose TokenBalancesController to API * add collectible image util * add missing documentation
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](gulpjs/glob-parent@v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.1.1 to 5.1.2. - [Release notes](https://github.com/gulpjs/glob-parent/releases) - [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md) - [Commits](gulpjs/glob-parent@v5.1.1...v5.1.2) --- updated-dependencies: - dependency-name: glob-parent dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR adds the ability to support auto detection of assets and also add token balances.
For the second purpose a new
TokenBalancesController
was created to poll for balances.Auto detection was achieved adding two new controllers.
AssetsContractController
: Only responsibility to interact with contracts of assets through provider. (Probably needs a better name)AssetsDetectionController
: Responsible to auto detect new tokens and collectibles. Auto detection is being triggered when user change account or a period of 3 minutes is finished, while user is on mainnet.Assets that are detected are the assets with their respective information in https://github.com/metamask/eth-contract-metadata.
The proposed structure for collectible to be auto detected from eth-contract-metadata,
{ name: string; address: string; symbol?: string; api?: string; collectibles_api?: string; owner_api?: string; collectibles_entry?: string; erc721?: boolean; }
name
: Asset namesymbol
: Asset symbolerc721
: Whether it ERC721 assetapi
: API URIcollectibles_api
: API specific endpoint to get collectibles information, as custom informationowner_api
: API specific endpoint to get owner information, as quantity of assets ownedcollectibles_entry
: API parameter to get collectibles of owner fromowner_api
URIThe objective of this structure was to provide both compability for new assets and to support current ERC721 standard. There is support for three "types" of collectibles:
Collectibles with API defined on contract-metadata, as Cryptokitties, which only interaction is through its API. In this case, collectibles are being added with custom name and image for each collectible.
Collectibles with ERC721Enumerable interface support, but no support of ERC721Metadata interface. Link to EIP. In this case, if
api
andcollectibles_api
are defined, collectibles are being added with custom information as name and collectible specific image. If not, collectible is being added only with Collectible Identifier.Collectibles with ERC721Enumerable interface and no support of ERC721Metadata interface. Link to EIP. In this case, collectibles are being added with custom name and image for each collectible.