feat: support TRC20 token balances for inactive accounts#190
feat: support TRC20 token balances for inactive accounts#190ulissesferreira wants to merge 2 commits intomainfrom
Conversation
beea8e5 to
82f12a3
Compare
| mockTrongridApiClient = { | ||
| getAccountInfoByAddress: jest.fn(), | ||
| getTrc20BalancesByAddress: jest.fn(), | ||
| } as unknown as jest.Mocked<TrongridApiClient>; | ||
| mockTronHttpClient = { | ||
| getAccountResources: jest.fn(), | ||
| } as unknown as jest.Mocked<TronHttpClient>; | ||
| mockPriceApiClient = { | ||
| getMultipleSpotPrices: jest.fn().mockResolvedValue({}), | ||
| } as unknown as jest.Mocked<PriceApiClient>; | ||
| mockTokenApiClient = { | ||
| getTokensMetadata: jest.fn().mockResolvedValue({}), | ||
| } as unknown as jest.Mocked<TokenApiClient>; |
There was a problem hiding this comment.
If we force types this way, when we'll change something in the mocked functions, we won't see any error here, and finding where the issue is will be way harder without visible type errors. Do you think we can avoid all these type casts?
There was a problem hiding this comment.
Yep yep, a little more verbose I believe but worth the effort, let's leverage typescript fully
| id: trc20AssetId, | ||
| price: 1.0, | ||
| }, | ||
| } as never); |
There was a problem hiding this comment.
same as above, is there a way to avoid this type cast?
| address: mockAccount.address, | ||
| balance: 1000000, | ||
| trc20: [], | ||
| } as never); |
There was a problem hiding this comment.
same as above, is there a way to avoid this type cast?
38156a6 to
cd1e61d
Compare
| }); | ||
|
|
||
| describe('extreme values (original bug scenarios)', () => { | ||
| describe('values out of `Number` 64-bit size', () => { |
There was a problem hiding this comment.
The nit: @mikesposito, didn't forget about it
There was a problem hiding this comment.
Particularly happy with the structure here. I am going for a method that orchestrates the whole thing, doing the data fetching at first, data parsing, enriching and finally returning. The fallbacks are handled right at the start and everything else is shared. Took some iterations to get here, feel free to suggest even more improvements
| * Get TRC20 token balances for an account address. | ||
| * This endpoint works for inactive accounts that haven't been activated yet. | ||
| * | ||
| * @see https://developers.tron.network/reference/get-trc20-token-holder-balances |
There was a problem hiding this comment.
This was the key endpoint missing for us to be able to offer this feature
| @@ -1,14 +1,15 @@ | |||
| /* eslint-disable @typescript-eslint/no-require-imports */ | |||
| /* eslint-disable no-restricted-globals */ | |||
There was a problem hiding this comment.
Followed the other PRs comment and also removed these file-wide exclusions. Bit by bit we can make them line specific. The previous team preferred avoiding the repetition hence why they are usually above
| @@ -0,0 +1,253 @@ | |||
| /* eslint-disable no-restricted-globals */ | |||
| /* eslint-disable @typescript-eslint/naming-convention */ | |||
There was a problem hiding this comment.
Followed the other PRs comment and also removed these file-wide exclusions. Bit by bit we can make them line specific. The previous team preferred avoiding the repetition hence why they are usually above
cd1e61d to
0203a95
Compare
Add fallback TRC20 balance fetching for inactive Tron accounts using the
`/v1/accounts/{address}/trc20/balance` endpoint when the main account
info endpoint returns no data (inactive accounts that haven't paid the
1 TRX activation fee).
- Add `getTrc20BalancesByAddress()` method to TrongridApiClient
- Implement fallback logic in AssetsService for inactive accounts
- Add helper methods for zero-balance native assets and TRC20 extraction
- Add comprehensive unit tests for new functionality
Use InMemoryCache in TrongridApiClient tests and drop redundant section comments in AssetsService.
0203a95 to
a3724b5
Compare
Summary
fetchAssetsAndBalancesForAccountto improve code organization and readabilityChanges
New TRC20 fallback for inactive accounts:
getTrc20BalancesByAddressclient method that works for inactive accounts (unlikegetAccountInfoByAddresswhich throws)getAccountInfoByAddressandgetAccountResourcesto document their behavior with inactive accountsAsset extraction refactor:
NormalizedAccountDatatype to provide a consistent data shape for both active and inactive accounts#buildAccountDatato normalize API responses, centralizing active/inactive branching logic#extractAssetscoordinator that calls all individual extractors uniformly#enrichAssetsWithMetadatato encapsulate metadata enrichment logic#getPriceableAssetTypeshelper for filtering assets that can be priced#createZeroBalanceNativeAsset(no longer needed after normalization)