-
Notifications
You must be signed in to change notification settings - Fork 58
feat(platform-wallet)!: support DashPay shielded tips with dedicated accounts #4616
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
Open
PastaPastaPasta
wants to merge
3
commits into
dashpay:v4.2-dev
Choose a base branch
from
PastaPastaPasta:feat/dashpay-shielded-tips
base: v4.2-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4290e2b
feat(dashpay)!: support shielded tips with dedicated wallet accounts
PastaPastaPasta 4956dfa
fix(swift-example-app): expose shielded tip address storage
PastaPastaPasta 75e1592
fix(platform-wallet): harden shielded tip recovery and mobile error h…
PastaPastaPasta 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
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
24 changes: 24 additions & 0 deletions
24
...nExampleApp/app/src/main/java/org/dashfoundation/example/ui/dashpay/ShieldedTipFailure.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,24 @@ | ||
| package org.dashfoundation.example.ui.dashpay | ||
|
|
||
| import org.dashfoundation.dashsdk.errors.DashSdkError | ||
|
|
||
| /** | ||
| * Permit a fresh user review only for failures known not to have executed a tip. | ||
| * On the tip path, Rust maps selection/build/recipient-check failures to | ||
| * WalletOperation. Broadcast ambiguity maps to ShieldedSpendUnconfirmed, and | ||
| * successful post-broadcast bookkeeping is best-effort (never WalletOperation). | ||
| * Unknown exceptions, including JNI failures and cancellation, remain locked. | ||
| */ | ||
| internal fun canReviewShieldedTipAfterFailure(error: Exception): Boolean = when (error) { | ||
| is IllegalArgumentException, | ||
| is DashSdkError.InvalidParameter, | ||
| is DashSdkError.PlatformWallet.InvalidHandle, | ||
| is DashSdkError.PlatformWallet.NotFound, | ||
| is DashSdkError.PlatformWallet.SigningKeyUnavailable, | ||
| is DashSdkError.PlatformWallet.WalletOperation, | ||
| is DashSdkError.PlatformWallet.ShieldedNoRecordedAnchor, | ||
| is DashSdkError.PlatformWallet.ShieldedBroadcastFailed -> true | ||
| // ErrorInvalidParameter is a preflight-only FFI failure on this call path. | ||
| is DashSdkError.PlatformWallet.Generic -> error.nativeCode == 2 | ||
| else -> false | ||
| } |
117 changes: 117 additions & 0 deletions
117
...linExampleApp/app/src/main/java/org/dashfoundation/example/ui/dashpay/ShieldedTipSheet.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,117 @@ | ||
| package org.dashfoundation.example.ui.dashpay | ||
|
|
||
| import android.content.Context | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.text.selection.SelectionContainer | ||
| import androidx.compose.material3.AlertDialog | ||
| import androidx.compose.material3.Checkbox | ||
| import androidx.compose.material3.OutlinedTextField | ||
| 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.rememberCoroutineScope | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.unit.dp | ||
| import java.math.BigDecimal | ||
| import kotlinx.coroutines.launch | ||
| import org.dashfoundation.dashsdk.tokens.ShieldedTipRecipient | ||
| import org.dashfoundation.dashsdk.tokens.ShieldedTipRecipientHistory | ||
| import org.dashfoundation.dashsdk.wallet.ManagedPlatformWallet | ||
| import org.dashfoundation.dashsdk.wallet.PlatformWalletManager | ||
| import org.dashfoundation.example.ui.components.SubmitButton | ||
| import org.dashfoundation.example.util.Base58 | ||
| import org.dashfoundation.example.util.DashAddress | ||
|
|
||
| /** Username tipping uses the same verified recipient and confirmation boundary as Swift. */ | ||
| @Composable | ||
| fun ShieldedTipSheet(manager: PlatformWalletManager, wallet: ManagedPlatformWallet, walletId: ByteArray, tipAccount: Int) { | ||
| val scope = rememberCoroutineScope() | ||
| val context = LocalContext.current | ||
| val history = remember(context) { | ||
| ShieldedTipRecipientHistory(context.getSharedPreferences("dashpay.tipRecipients", Context.MODE_PRIVATE)) | ||
| } | ||
| var changedRecipient by remember { mutableStateOf<ShieldedTipRecipient?>(null) } | ||
| var username by remember { mutableStateOf("") } | ||
| var amount by remember { mutableStateOf("") } | ||
| var recipient by remember { mutableStateOf<ShieldedTipRecipient?>(null) } | ||
| var confirmedAmount by remember { mutableStateOf<Long?>(null) } | ||
| var busy by remember { mutableStateOf(false) } | ||
| var submitted by remember { mutableStateOf(false) } | ||
| var spendTips by remember { mutableStateOf(false) } | ||
| var message by remember { mutableStateOf<String?>(null) } | ||
|
|
||
| changedRecipient?.let { changed -> | ||
| AlertDialog( | ||
| onDismissRequest = { changedRecipient = null }, | ||
| title = { Text("Tip recipient changed") }, | ||
| text = { Text("The identity or shielded address for this username differs from your previous confirmation. Verify the change with the recipient before continuing.") }, | ||
| confirmButton = { | ||
| TextButton(onClick = { recipient = changed; changedRecipient = null }) { Text("Review new recipient") } | ||
| }, | ||
| dismissButton = { | ||
| TextButton(onClick = { changedRecipient = null }) { Text("Cancel") } | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| Column(Modifier.padding(20.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) { | ||
| Text("Send a shielded tip") | ||
| OutlinedTextField(username, { username = it; recipient = null }, label = { Text("Username") }, enabled = !busy && !submitted) | ||
| OutlinedTextField(amount, { amount = it; recipient = null }, label = { Text("Amount (DASH)") }, enabled = !busy && !submitted) | ||
| Row { | ||
| Checkbox(checked = spendTips, enabled = !busy && !submitted, | ||
| onCheckedChange = { spendTips = it; recipient = null }) | ||
| Text("Spend from my dedicated tip account") | ||
| } | ||
| recipient?.let { | ||
| Text("Recipient: ${Base58.encode(it.identityId)}") | ||
| DashAddress.encodeOrchard(it.address, manager.network)?.let { address -> | ||
| SelectionContainer { Text(address) } | ||
| } | ||
| Text("Send $amount DASH from your ${if (spendTips) "tip" else "main shielded"} account to $username?") | ||
| } | ||
| message?.let { Text(it) } | ||
| SubmitButton( | ||
| text = if (recipient == null) "Review tip" else "Confirm and send", | ||
| isLoading = busy, enabled = !busy && !submitted && changedRecipient == null, modifier = Modifier.fillMaxWidth(), | ||
| ) { | ||
| busy = true | ||
| message = null | ||
| scope.launch { | ||
| try { | ||
| val selected = recipient | ||
| if (selected == null) { | ||
| val credits = BigDecimal(amount.trim()).movePointRight(11).longValueExact() | ||
| require(credits > 0) { "Enter a positive amount" } | ||
| confirmedAmount = credits | ||
| val resolved = wallet.dashpay.resolveShieldedTip(username.trim()) | ||
| if (history.hasChanged(manager.network, walletId, username, resolved)) { | ||
| changedRecipient = resolved | ||
| } else { | ||
| recipient = resolved | ||
| } | ||
| } else { | ||
| // Ambiguous or unclassified outcomes remain locked; definitive failures permit a fresh review. | ||
| history.confirm(manager.network, walletId, username, selected) | ||
| submitted = true | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| manager.sendShieldedTip(walletId, username.trim(), selected, requireNotNull(confirmedAmount), account = if (spendTips) tipAccount else 0) | ||
| message = "Shielded tip sent." | ||
| } | ||
| } catch (e: Exception) { | ||
| message = e.message ?: "Unable to send tip" | ||
| if (canReviewShieldedTipAfterFailure(e)) submitted = false | ||
| recipient = null | ||
| } finally { busy = false } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
🟡 Suggestion: Preserve the submission guard when dismissing an in-flight tip
ModalBottomSheet can be dismissed while a tip is being sent, and its dismissal removes ShieldedTipSheet from composition. That discards the remember-backed submitted flag and cancels the sheet's coroutine scope. PlatformWalletManager.sendShieldedTip runs the blocking JNI call through TeardownGate on Dispatchers.IO; cancellation does not stop an already-running native call from proving and broadcasting. Reopening the sheet therefore creates submitted=false and allows another payment without knowing the first payment's outcome. Note reservations prevent reuse of the same inputs, not a second payment funded by other available notes. Hoist the in-flight and uncertain-outcome state outside the dismissible composable, and prevent dismissal during the native send, including gesture-driven sheet hiding.
source: ['claude']