-
Notifications
You must be signed in to change notification settings - Fork 1
feat(dao): tap-to-explain tooltip on the APC label #279
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
3 commits
Select commit
Hold shift + click to select a range
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
94 changes: 94 additions & 0 deletions
94
android/app/src/main/java/com/rjnr/pocketnode/ui/screens/dao/components/ApcLabel.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,94 @@ | ||
| package com.rjnr.pocketnode.ui.screens.dao.components | ||
|
|
||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.material3.AlertDialog | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.text.style.TextDecoration | ||
| import androidx.compose.ui.unit.dp | ||
| import com.composables.icons.lucide.Info | ||
| import com.composables.icons.lucide.Lucide | ||
|
|
||
| /** | ||
| * APC label with a tap-to-explain affordance. Reused by both the DAO | ||
| * overview header and the per-deposit cards so the explanation lives | ||
| * in one place. | ||
| * | ||
| * Why a tooltip exists: Pocket Node shows *realized* APC (the actual | ||
| * compensation accrued on this specific deposit divided by elapsed | ||
| * time), while the Neuron desktop wallet shows *theoretical* APC (a | ||
| * forward-looking projection from CKB tokenomics). Users who compare | ||
| * the two numbers will see different values and reasonably assume one | ||
| * is wrong. The tooltip explains the difference so the user can act | ||
| * on the right mental model. | ||
| */ | ||
| @Composable | ||
| fun ApcLabel( | ||
| apc: Double, | ||
| style: androidx.compose.ui.text.TextStyle = MaterialTheme.typography.bodySmall, | ||
| color: androidx.compose.ui.graphics.Color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| prefix: String = "APC", | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| var showInfo by remember { mutableStateOf(false) } | ||
|
|
||
| Row( | ||
| modifier = modifier.clickable { showInfo = true }, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
| ) { | ||
| Text( | ||
| text = "$prefix ~${"%.2f".format(apc)}%", | ||
| style = style, | ||
| color = color, | ||
| textDecoration = TextDecoration.Underline, | ||
| ) | ||
| Icon( | ||
| imageVector = Lucide.Info, | ||
| contentDescription = "What is APC?", | ||
| tint = color, | ||
| modifier = Modifier.size(12.dp), | ||
| ) | ||
| } | ||
|
|
||
| if (showInfo) { | ||
| AlertDialog( | ||
| onDismissRequest = { showInfo = false }, | ||
| title = { Text("About this APC") }, | ||
| text = { | ||
| Text( | ||
| text = "This number is the realized annual compensation rate: " + | ||
| "the actual CKB earned on this deposit divided by the time " + | ||
| "it has been deposited.\n\n" + | ||
| "It may differ from the APC shown by other CKB wallets such " + | ||
| "as Neuron. Neuron displays a theoretical APC computed from " + | ||
| "the protocol's tokenomics — a forward-looking projection " + | ||
| "assuming idealised conditions. Realized APC tracks what " + | ||
| "your specific deposit has earned, which fluctuates with " + | ||
| "actual on-chain participation.\n\n" + | ||
| "Both numbers are valid. The realized number is the truth " + | ||
| "about your deposit; the theoretical number is an estimate " + | ||
| "of what a new deposit might earn.", | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| ) | ||
| }, | ||
| confirmButton = { | ||
| TextButton(onClick = { showInfo = false }) { | ||
| Text("Got it") | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
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.
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.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Extract hard-coded strings to string resources.
The dialog title, explanation text, and button label are hard-coded in English, while the rest of the codebase uses
stringResource(R.string.*)for i18n. This breaks localization and violates the DRY principle established elsewhere in the project.♻️ Suggested extraction to res/values/strings.xml
Add to
res/values/strings.xml:Then update the code:
🤖 Prompt for AI Agents