-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/ton 1653 update demo visuals #113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a92b655
chore: change background to white
nikdim03 7ff7686
refactor: update jetton balance formatting to use TONTokenAmountForma…
nikdim03 ed13708
feat: implement animated count-up for wallet balance and asset amounts
nikdim03 3730555
fix: preserve sign when parsing amounts like "-0.5"
TrueCarry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...main/java/io/ton/walletkit/demo/presentation/ui/components/wallet/home/AnimatedBalance.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) 2025 TonTech | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| package io.ton.walletkit.demo.presentation.ui.components.wallet.home | ||
|
|
||
| import androidx.compose.animation.core.Animatable | ||
| import androidx.compose.animation.core.Easing | ||
| import androidx.compose.animation.core.tween | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import java.math.BigDecimal | ||
| import java.math.RoundingMode | ||
|
|
||
| private const val COUNT_UP_DURATION_MS = 500 | ||
|
|
||
| // Ease-out cubic — fast start, smooth deceleration into the target (mirrors the TS demo wallet). | ||
| private val EaseOutCubic = Easing { t -> 1f - (1f - t) * (1f - t) * (1f - t) } | ||
|
|
||
| /** | ||
| * "Casino" count-up: returns a value that eases from the previously-shown number to [target] | ||
| * whenever [target] changes (e.g. a balance update). Double-precise, so large jetton amounts | ||
| * keep their value. The initial value is shown immediately — only later updates animate. | ||
| */ | ||
| @Composable | ||
| fun rememberCountUp(target: Double, durationMillis: Int = COUNT_UP_DURATION_MS): Double { | ||
| val progress = remember { Animatable(1f) } | ||
| var start by remember { mutableStateOf(target) } | ||
| var end by remember { mutableStateOf(target) } | ||
|
|
||
| LaunchedEffect(target) { | ||
| if (target != end) { | ||
| start = start + (end - start) * progress.value // capture the currently-shown value | ||
| end = target | ||
| progress.snapTo(0f) | ||
| progress.animateTo(1f, tween(durationMillis, easing = EaseOutCubic)) | ||
| } | ||
| } | ||
| return start + (end - start) * progress.value | ||
| } | ||
|
|
||
| /** Formats a count-up value, trailing zeros stripped and capped at [maxFractionDigits]. */ | ||
| fun formatCountUp(value: Double, maxFractionDigits: Int): String = BigDecimal.valueOf(value) | ||
| .setScale(maxFractionDigits, RoundingMode.DOWN) | ||
| .stripTrailingZeros() | ||
| .toPlainString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| <resources> | ||
| <style name="Theme.WalletKitDemo" parent="Theme.Material3.DayNight.NoActionBar"> | ||
| <item name="android:statusBarColor">@android:color/transparent</item> | ||
| <item name="android:navigationBarColor">@android:color/black</item> | ||
| <style name="Theme.WalletKitDemo" parent="Theme.Material3.Light.NoActionBar"> | ||
| <item name="android:windowBackground">@android:color/white</item> | ||
| <item name="android:statusBarColor">@android:color/white</item> | ||
| <item name="android:navigationBarColor">@android:color/white</item> | ||
| <item name="android:windowLightStatusBar">true</item> | ||
| <item name="android:windowLightNavigationBar">true</item> | ||
| </style> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: ton-org/kit-android
Length of output: 8898
🏁 Script executed:
Repository: ton-org/kit-android
Length of output: 3069
🏁 Script executed:
Repository: ton-org/kit-android
Length of output: 15274
Avoid converting balance strings to
Doublewith lossy precision and silent0.0fallback.WalletScreen.ktsetsWalletHomeAssetItem.amountValuefromrawBalance?.toDoubleOrNull() ?: 0.0(and jettonamount.toDoubleOrNull() ?: 0.0), and setstotalBalancefromactiveWallet?.balance?.toDoubleOrNull() ?: 0.0. ThoseDoublevalues drive the count-up display (rememberCountUp(target: Double)), and final formatting usesformatCountUp(value: Double)→BigDecimal.valueOf(value); so any precision loss (and any parse failure becoming0.0) directly produces incorrect shown amounts. Keep balances asBigDecimal(or smallest-units integer) as the source of truth, and only derive an animated/display numeric value in a way that doesn’t drop precision (or gate/limit the conversion to safe ranges).🤖 Prompt for AI Agents