-
Notifications
You must be signed in to change notification settings - Fork 28
feat: fetch TON balances #341
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes introduce support for retrieving token balances from the TON blockchain. This includes updating the balance-fetching logic to accept and process TON addresses, extending the command-line interface to accept a TON address, and implementing a utility function to fetch and convert TON balances from relevant APIs. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI (balancesCommand)
participant Client (getBalances)
participant Utils (getTonBalances)
participant TON API
User->>CLI (balancesCommand): Run balances command with --ton <address>
CLI (balancesCommand)->>Client (getBalances): Call with tonAddress
alt If tonAddress is provided
Client (getBalances)->>Utils (getTonBalances): Fetch TON balances
Utils (getTonBalances)->>TON API: Request balance for each TON token
TON API-->>Utils (getTonBalances): Return balances
Utils (getTonBalances)-->>Client (getBalances): Return processed balances
end
Client (getBalances)-->>CLI (balancesCommand): Return all balances
CLI (balancesCommand)-->>User: Output balances
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
packages/commands/src/query/balances.ts (1)
130-135
: 🛠️ Refactor suggestionAdd TON address to the formatted output.
The
formatAddresses
function should include the TON address to be consistent with other address types.const addressesInfo = formatAddresses({ bitcoin: btcAddress, evm: evmAddress, solana: solanaAddress, sui: suiAddress, + ton: tonAddress, });
🧹 Nitpick comments (1)
packages/commands/src/query/balances.ts (1)
95-95
: Consider adding TON address resolution from account names.Unlike other address types (EVM, Solana, Bitcoin, Sui) which have resolver functions that can derive addresses from account names, TON addresses can only be provided directly via the
--ton
option. This creates an inconsistent user experience.Would you like me to help implement a
resolveTonAddress
function to maintain consistency with other address types?
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/client/src/getBalances.ts
(4 hunks)packages/commands/src/query/balances.ts
(4 hunks)utils/balances.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/client/src/getBalances.ts (1)
utils/balances.ts (1)
getTonBalances
(805-858)
utils/balances.ts (1)
types/balances.types.ts (2)
Token
(18-27)TokenBalance
(5-16)
🔇 Additional comments (3)
utils/balances.ts (1)
21-22
: LGTM!The TON API endpoint constants are correctly defined.
packages/client/src/getBalances.ts (1)
14-14
: LGTM!The TON balance fetching is correctly integrated following the same pattern as other chains.
Also applies to: 27-27, 37-37, 43-43, 147-152
packages/commands/src/query/balances.ts (1)
39-39
: LGTM!The TON address support is correctly added to the CLI command.
Also applies to: 95-95, 97-103, 120-120, 162-162
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
utils/balances.ts (1)
859-859
: Optimize axios import for better performance.Consider importing
isAxiosError
directly instead of accessing it from the axios object.Apply this optimization:
-import axios from "axios"; +import axios, { isAxiosError } from "axios";Then update the usage:
- if (axios.isAxiosError(error)) { + if (isAxiosError(error)) {🧰 Tools
🪛 GitHub Check: build
[warning] 859-859:
Caution:axios
also has a named exportisAxiosError
. Check if you meant to writeimport {isAxiosError} from 'axios'
instead
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
utils/balances.ts
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
utils/balances.ts (1)
types/balances.types.ts (2)
Token
(18-27)TokenBalance
(5-16)
🪛 GitHub Check: build
utils/balances.ts
[warning] 859-859:
Caution: axios
also has a named export isAxiosError
. Check if you meant to write import {isAxiosError} from 'axios'
instead
🔇 Additional comments (4)
utils/balances.ts (4)
21-22
: LGTM! API endpoints are correctly defined.The TON mainnet and testnet API endpoints are properly defined and follow the expected pattern for the TON API v2.
798-806
: Interface looks comprehensive and well-typed.The
TonApiResponse
interface now includes all the essential fields from the TON API v2 accounts endpoint. The balance field is correctly typed asstring | number
to handle both response formats.
828-828
: API endpoint assignment is now correct.The ternary condition correctly assigns
TON_MAINNET_API
when network is "mainnet" andTON_TESTNET_API
otherwise. This resolves the previously reported issue.
811-872
: Excellent implementation with robust error handling.The
getTonBalances
function is well-structured with:
- Proper token filtering for TON Gas tokens
- Correct API endpoint selection
- Thorough response validation
- Accurate balance conversion from nanoTON to TON (9 decimals)
- Comprehensive error handling for both Axios and general errors
The logic flow is sound and follows the established patterns in the codebase.
🧰 Tools
🪛 GitHub Check: build
[warning] 859-859:
Caution:axios
also has a named exportisAxiosError
. Check if you meant to writeimport {isAxiosError} from 'axios'
instead
Summary by CodeRabbit
--ton <address>
).