Skip to content

Feature/ton 1790 polish sdk#120

Open
nikdim03 wants to merge 2 commits into
mainfrom
feature/ton-1790-polish-sdk
Open

Feature/ton 1790 polish sdk#120
nikdim03 wants to merge 2 commits into
mainfrom
feature/ton-1790-polish-sdk

Conversation

@nikdim03

@nikdim03 nikdim03 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features

    • Added jettons API for fetching wallet jettons and streaming updates
    • Added reverse DNS wallet resolution capability
  • Documentation

    • Updated SDK rebuild instructions with clearer five-step breakdown
    • Enhanced wallet API quick-start examples with revised usage patterns
    • Added comprehensive documentation to wallet interfaces and operations
  • API Improvements

    • Manager accessors (staking(), streaming()) now support async operations
    • Refactored external signer interface for improved type safety
    • Approval operations now return explicit response types
    • Wallet removal now uses unique identifier instead of address
  • Tests

    • Added comprehensive test suites for model classes and bridge operations
    • Enhanced test coverage for wallet operations and gasless functionality
  • Refactor

    • Mnemonic objects now support value-based equality and hashing

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds typed return values to TonConnect approval operations (transaction, sign-data, sign-message) by switching from fire-and-forget send to callTyped in TonConnectOperations and propagating explicit return types up through engine implementations and public request types. It also adds jettons streaming to ITONStreamingProvider, backResolveDnsWallet to TONAPIClient, a jettons(limit) extension on ITONWallet, makes staking()/streaming() suspending, implements value-based equality on TONMnemonic, and adds new unit tests for TONHex, TONMnemonic, TONTokenAmount, GaslessOperations, and updates the approveTransaction test. Both READMEs are updated to reflect current API signatures.

Changes

TonConnect Typed Approval Responses

Layer / File(s) Summary
Approval method return types: public API and RequestHandler contracts
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/RequestHandler.kt, ...TONWalletTransactionRequest.kt, ...TONWalletSignDataRequest.kt, ...TONWalletSignMessageRequest.kt, ...TONWalletConnectionRequest.kt
approve methods on the three request types gain explicit return types (TONSendTransactionApprovalResponse, TONSignDataApprovalResponse, TONSignMessageApprovalResponse) and expression bodies. RequestHandler formatting is adjusted to match.
Approval method return types: engine implementations
TONWalletKit-Android/impl/src/main/java/io/ton/walletkit/engine/WalletKitEngine.kt, ...WebViewWalletKitEngine.kt, ...operations/TonConnectOperations.kt
WalletKitEngine and WebViewWalletKitEngine override signatures gain explicit response return types. TonConnectOperations switches from send to callTyped, returning typed approval response objects.
Approval and gasless operations tests
TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/TonConnectOperationsTest.kt, ...GaslessOperationsTest.kt
approveTransaction test asserts the returned signedBoc value. New GaslessOperationsTest validates bridge method names and JSON encoding/decoding for gasless provider operations.

New API Members: jettons streaming, backResolveDnsWallet, staking/streaming suspend

Layer / File(s) Summary
New API: suspend staking/streaming, jettons stream, backResolveDnsWallet, jettons wallet extension
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/ITONWalletKit.kt, ...streaming/ITONStreamingProvider.kt, ...client/TONAPIClient.kt, ...ITONWallet.kt, ...impl/.../core/TONWalletKit.kt
ITONWalletKit.staking() and streaming() become suspend. ITONStreamingProvider gains jettons(address). TONAPIClient gains backResolveDnsWallet. ITONWallet gains jettons(limit) extension.
KDoc updates for TONAPIClient, ITONWallet, ITONStreamingManager, ITONStreamingProvider, ITONWalletAdapter
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/client/TONAPIClient.kt, ...ITONWallet.kt, ...streaming/ITONStreamingManager.kt, ...streaming/ITONStreamingProvider.kt, ...model/ITONWalletAdapter.kt
KDoc comments are added or expanded for existing members without changing method signatures.

TONMnemonic equality and model unit tests

Layer / File(s) Summary
TONMnemonic equals/hashCode and tests
TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/TONMnemonic.kt, ...test/.../model/TONMnemonicTest.kt
TONMnemonic overrides equals and hashCode based on the words list. TONMnemonicTest covers initialization, mutation, equality, and TONMnemonicLength mapping.
TONHex and TONTokenAmount unit tests
TONWalletKit-Android/api/src/test/java/io/ton/walletkit/model/TONHexTest.kt, ...TONTokenAmountTest.kt
New test suites cover TONHex parsing/encoding/equality and TONTokenAmount constructors, ZERO, large values, negatives, parseOrNull, and value-based equality.

README and Android quick-start documentation updates

Layer / File(s) Summary
Updated README docs: rebuild script steps and quick-start API examples
README.md, TONWalletKit-Android/README.md
Root README enumerates five rebuild-SDK script phases and documents --install-demo/--regen-models flags. Android README updates addWallet, address, balance, WalletSigner, and removeWallet examples to match current API.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ton-org/kit-android#90: Directly overlaps with the addition of backResolveDnsWallet(address: TONUserFriendlyAddress): String? to the TONAPIClient interface.

Suggested reviewers

  • ProudOfZiggy

Poem

🐇 Hop hop, the types now flow back home,
No more Unit left alone to roam.
callTyped returns the signed BOC right,
And jettons stream into the night.
equals and hashCode words compare—
A tidier SDK beyond compare! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title "Feature/ton 1790 polish sdk" is vague and uses generic terms like "polish" without clearly conveying the specific scope of changes, which include API refinements, documentation updates, new methods, explicit return types, and test additions across multiple modules. Use a more descriptive title that highlights the primary changes, such as "Add explicit return types and jettons API, improve documentation" or "Refactor approval methods with explicit types and add jettons support".
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ton-1790-polish-sdk

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/TonConnectOperationsTest.kt (1)

265-276: ⚡ Quick win

Add parity tests for typed sign-data/sign-message approvals.

This update asserts typed decoding for approveTransaction, but the same contract shift happened for approveSignData and approveSignMessage. Please add equivalent response-shape assertions for those two paths to guard against callTyped decoding regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/TonConnectOperationsTest.kt`
around lines 265 - 276, Add two new test methods in the TonConnectOperationsTest
class that mirror the structure and assertions of
approveTransaction_returnsApprovalResponse, but for the approveSignData and
approveSignMessage methods respectively. Each test should use givenBridgeReturns
to mock the bridge response, create the appropriate request event (using
createSignDataRequestEvent or createSignMessageRequestEvent), call the
corresponding rpcClient method (approveSignData or approveSignMessage), and
assert that the response shape is correctly decoded through callTyped by
verifying the expected fields are properly populated in the returned response
object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/ITONWalletAdapter.kt`:
- Around line 80-81: The new interface method supportedFeatures() in
ITONWalletAdapter has a default implementation body, which requires JVM
default-method compatibility configuration. Add the `-Xjvm-default=all` compiler
flag to the compilerOptions.freeCompilerArgs in
TONWalletKit-Android/api/build.gradle.kts, or alternatively annotate the
supportedFeatures() method with `@JvmDefault` to ensure existing custom
implementations of this interface remain binary compatible at runtime.

In
`@TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/TONMnemonic.kt`:
- Around line 119-125: The TONMnemonic class overrides equals and hashCode based
on mutable state (the words field), which violates the contract for use in
hash-based collections like HashSet or HashMap since the object can be mutated
via the updateWord method. Either remove the equals and hashCode method
overrides entirely to rely on reference equality for this mutable class, or add
a KDoc warning on the TONMnemonic class that clearly documents that instances
must never be used as keys in HashMap/HashSet and should not be mutated after
creation. Choose the approach that best fits your design intent for this class.

---

Nitpick comments:
In
`@TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/TonConnectOperationsTest.kt`:
- Around line 265-276: Add two new test methods in the TonConnectOperationsTest
class that mirror the structure and assertions of
approveTransaction_returnsApprovalResponse, but for the approveSignData and
approveSignMessage methods respectively. Each test should use givenBridgeReturns
to mock the bridge response, create the appropriate request event (using
createSignDataRequestEvent or createSignMessageRequestEvent), call the
corresponding rpcClient method (approveSignData or approveSignMessage), and
assert that the response shape is correctly decoded through callTyped by
verifying the expected fields are properly populated in the returned response
object.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 62651f1a-f17f-4a86-a602-6315650fccc6

📥 Commits

Reviewing files that changed from the base of the PR and between c4f94a1 and 52913f7.

📒 Files selected for processing (23)
  • README.md
  • TONWalletKit-Android/README.md
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/ITONWallet.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/ITONWalletKit.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/client/TONAPIClient.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/ITONWalletAdapter.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/TONMnemonic.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/RequestHandler.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/TONWalletConnectionRequest.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/TONWalletSignDataRequest.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/TONWalletSignMessageRequest.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/request/TONWalletTransactionRequest.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/streaming/ITONStreamingManager.kt
  • TONWalletKit-Android/api/src/main/java/io/ton/walletkit/streaming/ITONStreamingProvider.kt
  • TONWalletKit-Android/api/src/test/java/io/ton/walletkit/model/TONHexTest.kt
  • TONWalletKit-Android/api/src/test/java/io/ton/walletkit/model/TONMnemonicTest.kt
  • TONWalletKit-Android/api/src/test/java/io/ton/walletkit/model/TONTokenAmountTest.kt
  • TONWalletKit-Android/impl/src/main/java/io/ton/walletkit/core/TONWalletKit.kt
  • TONWalletKit-Android/impl/src/main/java/io/ton/walletkit/engine/WalletKitEngine.kt
  • TONWalletKit-Android/impl/src/main/java/io/ton/walletkit/engine/WebViewWalletKitEngine.kt
  • TONWalletKit-Android/impl/src/main/java/io/ton/walletkit/engine/operations/TonConnectOperations.kt
  • TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/GaslessOperationsTest.kt
  • TONWalletKit-Android/impl/src/test/java/io/ton/walletkit/engine/operations/TonConnectOperationsTest.kt

Comment on lines +80 to 81
/** The wallet features this adapter supports, or null for SDK defaults. */
fun supportedFeatures(): List<TONWalletKitConfiguration.Feature>? = null

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Gradle/Kotlin files =="
fd -H -t f 'build.gradle.kts|build.gradle|gradle.properties|settings.gradle.kts|settings.gradle'

echo
echo "== Kotlin JVM default-method/compiler settings =="
rg -n --iglob '*gradle*' --iglob 'gradle.properties' \
  'jvmDefault|-Xjvm-default|freeCompilerArgs|kotlinOptions|compilerOptions|JvmDefault'

echo
echo "== API/binary compatibility tooling (if any) =="
rg -n --iglob '*gradle*' 'binary-compatibility-validator|apiValidation|explicitApi'

Repository: ton-org/kit-android

Length of output: 1517


🏁 Script executed:

# Read the full API module build.gradle.kts
cat -n TONWalletKit-Android/api/build.gradle.kts | head -80

Repository: ton-org/kit-android

Length of output: 2793


🏁 Script executed:

# Examine the ITONWalletAdapter.kt interface file
cat -n TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/ITONWalletAdapter.kt

Repository: ton-org/kit-android

Length of output: 4012


🏁 Script executed:

# Search for `@JvmDefault` annotations in the codebase
rg -n '`@JvmDefault`' --type kotlin

Repository: ton-org/kit-android

Length of output: 45


Add JVM default-method compatibility configuration for the new interface member.

Line 81 adds a new interface method with a default body, but the API module's build.gradle.kts lacks the -Xjvm-default compiler flag. Existing precompiled custom ITONWalletAdapter implementations will face binary compatibility issues at runtime. Either:

  • Add -Xjvm-default=all to compilerOptions.freeCompilerArgs in TONWalletKit-Android/api/build.gradle.kts, or
  • Annotate the supportedFeatures() method with @JvmDefault
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/ITONWalletAdapter.kt`
around lines 80 - 81, The new interface method supportedFeatures() in
ITONWalletAdapter has a default implementation body, which requires JVM
default-method compatibility configuration. Add the `-Xjvm-default=all` compiler
flag to the compilerOptions.freeCompilerArgs in
TONWalletKit-Android/api/build.gradle.kts, or alternatively annotate the
supportedFeatures() method with `@JvmDefault` to ensure existing custom
implementations of this interface remain binary compatible at runtime.

Comment on lines +119 to +125
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is TONMnemonic) return false
return words == other.words
}

override fun hashCode(): Int = words.hashCode()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Search for TONMnemonic usage in HashSet, HashMap, or as map keys

# Search for HashSet/HashMap usage with TONMnemonic
rg -n --type=kotlin -C3 'HashSet.*TONMnemonic|HashMap.*TONMnemonic|mutableSetOf.*TONMnemonic|mutableMapOf.*TONMnemonic'

# Search for TONMnemonic.updateWord calls to confirm mutability usage
rg -n --type=kotlin -C2 '\.updateWord\('

Repository: ton-org/kit-android

Length of output: 1786


🏁 Script executed:

cat -n TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/TONMnemonic.kt | head -140

Repository: ton-org/kit-android

Length of output: 5675


🏁 Script executed:

rg -n "class TONHex" --type=kotlin -A 20

Repository: ton-org/kit-android

Length of output: 4579


Overriding equals/hashCode on a mutable class is an anti-pattern.

TONMnemonic is intentionally mutable (via updateWord) for UI input handling, but overrides equals and hashCode based on mutable internal state. If an instance is added to a HashSet or used as a HashMap key and then mutated via updateWord, the collection contracts will be violated, leading to silent bugs where the object can no longer be found or removed.

While no current usage in hash-based collections was found, the codebase exposes this as a public API, so external callers could encounter this issue.

Consider one of the following approaches:

  1. Make TONMnemonic immutable by removing updateWord and making words immutable. (Conflicts with documented UI input handling use case.)
  2. Remove the equals/hashCode overrides and rely on reference equality for a mutable object.
  3. Document the constraint with a KDoc warning that instances must not be used in hash-based collections and should not be mutated after creation.

Note: Other model classes like TONHex are immutable data classes, suggesting that value-based equality should align with immutability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@TONWalletKit-Android/api/src/main/java/io/ton/walletkit/model/TONMnemonic.kt`
around lines 119 - 125, The TONMnemonic class overrides equals and hashCode
based on mutable state (the words field), which violates the contract for use in
hash-based collections like HashSet or HashMap since the object can be mutated
via the updateWord method. Either remove the equals and hashCode method
overrides entirely to rely on reference equality for this mutable class, or add
a KDoc warning on the TONMnemonic class that clearly documents that instances
must never be used as keys in HashMap/HashSet and should not be mutated after
creation. Choose the approach that best fits your design intent for this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant