Repository navigation
feat(tron): return live data from listAccountAssets and getAccountBalances
#388
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
Changes from all commits
f63d787
1620bad
5c2c266
a1db237
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import { ListAccountAssetsResponseStruct } from '@metamask/keyring-api'; | ||
| import type { | ||
| Balance, | ||
| CreateAccountOptions as KeyringBatchCreateAccountOptions, | ||
|
|
@@ -53,11 +52,12 @@ import { | |
| GetAccounBalancesResponseStruct, | ||
| GetAccountBalancesStruct, | ||
| GetAccountStruct, | ||
| ListAccountAssetsStruct, | ||
| ListAccountTransactionsStruct, | ||
| GetAccountAssetsStruct, | ||
| GetAccountAssetsResponseStruct, | ||
| PrivateKeyHexStruct, | ||
| SignTransactionRequestStruct, | ||
| TronKeyringRequestStruct, | ||
| GetAccountTransactionsStruct, | ||
| } from '../../validation/structs'; | ||
| import type { TronWalletKeyringRequest } from '../../validation/structs'; | ||
| import { validateRequest, validateResponse } from '../../validation/validators'; | ||
|
|
@@ -181,14 +181,14 @@ export class KeyringHandler implements KeyringSnapRpc { | |
|
|
||
| async getAccountAssets(accountId: string): Promise<CaipAssetTypeOrId[]> { | ||
| try { | ||
| validateRequest({ accountId }, ListAccountAssetsStruct); | ||
| validateRequest({ accountId }, GetAccountAssetsStruct); | ||
|
|
||
| await this.#getAccountOrThrow(accountId); | ||
| const account = await this.#getAccountOrThrow(accountId); | ||
|
|
||
| this.#logger.info('Listing account assets', { accountId }); | ||
| this.#logger.info('Getting account assets', { accountId }); | ||
|
|
||
| const assetEntities = | ||
| await this.#assetsService.getAccountAssets(accountId); | ||
| await this.#assetsService.fetchAccountAssetsFromTrongrid(account); | ||
| const result = assetEntities | ||
| .filter( | ||
| (asset) => | ||
|
|
@@ -199,7 +199,7 @@ export class KeyringHandler implements KeyringSnapRpc { | |
|
|
||
| this.#logger.info('Account assets', { accountId, result }); | ||
|
|
||
| validateResponse(result, ListAccountAssetsResponseStruct); | ||
| validateResponse(result, GetAccountAssetsResponseStruct); | ||
| return result; | ||
| } catch (error: unknown) { | ||
| this.#logger.error({ error }, 'Error listing account assets'); | ||
|
|
@@ -224,9 +224,9 @@ export class KeyringHandler implements KeyringSnapRpc { | |
| next: string | null; | ||
| }> { | ||
| try { | ||
| validateRequest({ accountId, pagination }, ListAccountTransactionsStruct); | ||
| validateRequest({ accountId, pagination }, GetAccountTransactionsStruct); | ||
|
|
||
| this.#logger.info('Listing account transactions...'); | ||
| this.#logger.info('Getting account transactions...'); | ||
| const { limit, next } = pagination; | ||
|
|
||
| const keyringAccount = await this.#getAccount(accountId); | ||
|
|
@@ -275,9 +275,10 @@ export class KeyringHandler implements KeyringSnapRpc { | |
|
|
||
| this.#logger.info('Getting account balances', { accountId, assets }); | ||
|
|
||
| await this.#getAccountOrThrow(accountId); | ||
| const account = await this.#getAccountOrThrow(accountId); | ||
|
|
||
| const assetsList = await this.#assetsService.getAccountAssets(accountId); | ||
| const assetsList = | ||
| await this.#assetsService.fetchAccountAssetsFromTrongrid(account); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: shall we consider adding this.#assetsService.fetchAccountAssetsFromTrongrid with InMemoryCache as Caller do listAccountAsset first then getAccountBalances So those SNAP api method use the same tron grid API, we can have a bit optizme to reduce the network call?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would start without it. Just to make sure everything works on |
||
|
|
||
| const assetsToUse = assetsList | ||
| .filter((asset) => assets.includes(asset.assetType)) | ||
|
|
||
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.
mainhas this line duplicated