feat(tron-wallet-snap): route assets through Core AssetsController - #127
Conversation
bfa488d to
327dfab
Compare
6587ae2 to
9428a52
Compare
6769ec9 to
4d766ab
Compare
9428a52 to
489bab0
Compare
|
@cursoragent rebase with latest main |
|
Rebased What happened during rebase:
Result: 8 commits ahead of |
4d766ab to
af82730
Compare
dbfa825 to
703eabc
Compare
|
@cursoragent make sure the CI is green |
There was a problem hiding this comment.
This is how simple fetching assets will be. All calls are basically direct AssetsController calls and then, for now, we map the structure of it to minimize the amount of changes in the repository. In a future PR we will want to remove the mapping and use the structure from the AssetsController. One of the methods also returns a dictionary, purposefully, which we will refactor the existing codebase to use as well because that is the idiomatic way to do things, if you fetch by a collection of IDs it only makes sense you get them back in an easy to access way.
| SNAPS_ASSETS_MIGRATION_FLAG_KEYS.tron, | ||
| ); | ||
| return parseSnapsAssetsMigrationStage(flagValue); | ||
| } |
There was a problem hiding this comment.
We use the function from AssetsController to see which stage of the migration we are on and we simply read the feature flags from the shared RemoteFeatureFlagsProvider
5fdb1d9 to
703eabc
Compare
| "AssetsController:getAccountAssetsByIDs", | ||
| "AssetsController:getAccountAssetsByScope" | ||
| "AssetsController:getAccountAssetsByScope", | ||
| "RemoteFeatureFlagController:getState" |
There was a problem hiding this comment.
Just a formatting fix
| rawAmount: amount, | ||
| uiAmount: toUiAmount(amount, decimals).toString(), | ||
| iconUrl, | ||
| } as AssetEntity; |
There was a problem hiding this comment.
For now this is needed because we haven't aligned all assetType from all different places
There was a problem hiding this comment.
On this file you can see the advantage of using the different adapters. Either we route operations to one or the other.
d163e9c to
0bdab3a
Compare
There was a problem hiding this comment.
Only a rename
9c70ee3 to
a793675
Compare
a793675 to
99fa147
Compare
There was a problem hiding this comment.
We were importing the configProvider directly from context.ts, which is possible to do, but we want to use dependency injection for more organized code and easier testing
99fa147 to
00333d9
Compare
| this.cacheTtlsMilliseconds = this.#snapAdapter.cacheTtlsMilliseconds; | ||
| } | ||
|
|
||
| async #getAssetsMigrationStage(): Promise<SnapsAssetsMigrationStage> { |
There was a problem hiding this comment.
nit: but might simplify a bit if we return a boolean from this method, instead of checking every time if (migrationStage === SnapsAssetsMigrationStage.Off)
| }) { | ||
| this.#remoteFeatureFlagsProvider = remoteFeatureFlagsProvider; | ||
|
|
||
| this.#snapAdapter = new SnapAssetsAdapter({ |
There was a problem hiding this comment.
it seems like we pass all the dependencies just to instantiate SnapAssetsAdapter, maybe better to instantiate SnapAssetsAdapter outside of AssetsService and simplify this class wdyt?
There was a problem hiding this comment.
Very good point and that is the correct way to implement the Adapter pattern. What is done there is not right. Will change it ✏️
| snapClient, | ||
| configProvider, | ||
| }); | ||
| this.#coreAdapter = new CoreAssetsAdapter({ |
8d32e80 to
b472e36
Compare
193e031 to
cfae0a7
Compare
cfae0a7 to
18c7bfd
Compare
… is on Route fungible reads and snap-owned asset sync through CoreAssetsAdapter when the Tron assets migration flag is active. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
…etsByScope Scope-scoped reads are only needed internally by CoreAssetsAdapter when aggregating account assets from Core. Co-authored-by: Ulisses Ferreira <ulisses@hey.com>
18c7bfd to
c61d9b8
Compare


Summary
getAccountAssetByID,getAccountAssetsByIDs,getAccountAssetsByScope,getAccountAssets) when migration is activeAccountAssetListUpdated/AccountBalancesUpdatedwithout local persistenceJira
Test plan
yarn workspace @metamask/tron-wallet-snap run jest --no-coverage src/services/assets/AssetsService.test.tsyarn workspace @metamask/tron-wallet-snap run jest --no-coverage src/services/assets/snapOwnedAssets.test.ts