Repository navigation
feat(dashpay): finish topup feature (ui, backend) - #1338
Merged
Merged
Conversation
HashEngineering
added a commit
that referenced
this pull request
Aug 4, 2026
Four on-device findings from the testnet round: - The credits explainer re-appeared on every visit: its "seen" flag was written from the sheet's own lifecycle scope, so dismissing it immediately cancelled the write. It now persists from the ViewModel scope with NonCancellable, which outlives both the sheet and the screen. (Day-one bug from PR #1338 — the write only ever ran on the button path, never on swipe/back/outside-tap.) - The Send button's spinner was gated on the worker's "handed to the SDK" marker, which fires ~20ms after the tap while the purchase takes seconds, so it flashed invisibly. It now holds for the whole purchase, the button is disabled while busy (standard disabled styling), the balance observer can no longer re-enable it mid-flight, and on success it stays disabled through to the screen closing. - Whole-balance ("Max") top-ups are refused with an explanation instead of approximated: the SDK's top-up call takes an exact amount and its send-all mode is not reachable through the FFI yet (rust-dashcore #915 + the key-wallet flag, MO-998). Tapping MAX explains immediately — before the PIN prompt and without changing the amount, via a new opt-in EnterAmountFragment.onMaxVetoed hook — typing the full balance shows the same text inline, and the purchase path refuses as a backstop. - The pre-existing silent minimum now explains itself: below 0.0005 DASH the Continue button greyed out with no message. One constant drives both the button rule and the text so they cannot drift. Also keeps the null-fee guard on the confirmation screen: post-cutover the dry run does not complete the tx, so tx.fee is null and Max crashed after the PIN prompt. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]>
HashEngineering
added a commit
that referenced
this pull request
Aug 7, 2026
Four on-device findings from the testnet round: - The credits explainer re-appeared on every visit: its "seen" flag was written from the sheet's own lifecycle scope, so dismissing it immediately cancelled the write. It now persists from the ViewModel scope with NonCancellable, which outlives both the sheet and the screen. (Day-one bug from PR #1338 — the write only ever ran on the button path, never on swipe/back/outside-tap.) - The Send button's spinner was gated on the worker's "handed to the SDK" marker, which fires ~20ms after the tap while the purchase takes seconds, so it flashed invisibly. It now holds for the whole purchase, the button is disabled while busy (standard disabled styling), the balance observer can no longer re-enable it mid-flight, and on success it stays disabled through to the screen closing. - Whole-balance ("Max") top-ups are refused with an explanation instead of approximated: the SDK's top-up call takes an exact amount and its send-all mode is not reachable through the FFI yet (rust-dashcore #915 + the key-wallet flag, MO-998). Tapping MAX explains immediately — before the PIN prompt and without changing the amount, via a new opt-in EnterAmountFragment.onMaxVetoed hook — typing the full balance shows the same text inline, and the purchase path refuses as a backstop. - The pre-existing silent minimum now explains itself: below 0.0005 DASH the Continue button greyed out with no message. One constant drives both the button rule and the text so they cannot drift. Also keeps the null-fee guard on the confirmation screen: post-cutover the dry run does not complete the tx, so tx.fee is null and Max crashed after the PIN prompt. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]>
HashEngineering
added a commit
that referenced
this pull request
Aug 10, 2026
Four on-device findings from the testnet round: - The credits explainer re-appeared on every visit: its "seen" flag was written from the sheet's own lifecycle scope, so dismissing it immediately cancelled the write. It now persists from the ViewModel scope with NonCancellable, which outlives both the sheet and the screen. (Day-one bug from PR #1338 — the write only ever ran on the button path, never on swipe/back/outside-tap.) - The Send button's spinner was gated on the worker's "handed to the SDK" marker, which fires ~20ms after the tap while the purchase takes seconds, so it flashed invisibly. It now holds for the whole purchase, the button is disabled while busy (standard disabled styling), the balance observer can no longer re-enable it mid-flight, and on success it stays disabled through to the screen closing. - Whole-balance ("Max") top-ups are refused with an explanation instead of approximated: the SDK's top-up call takes an exact amount and its send-all mode is not reachable through the FFI yet (rust-dashcore #915 + the key-wallet flag, MO-998). Tapping MAX explains immediately — before the PIN prompt and without changing the amount, via a new opt-in EnterAmountFragment.onMaxVetoed hook — typing the full balance shows the same text inline, and the purchase path refuses as a backstop. - The pre-existing silent minimum now explains itself: below 0.0005 DASH the Continue button greyed out with no message. One constant drives both the button rule and the text so they cannot drift. Also keeps the null-fee guard on the confirmation screen: post-cutover the dry run does not complete the tx, so tx.fee is null and Max crashed after the PIN prompt. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]>
HashEngineering
added a commit
that referenced
this pull request
Aug 17, 2026
Four on-device findings from the testnet round: - The credits explainer re-appeared on every visit: its "seen" flag was written from the sheet's own lifecycle scope, so dismissing it immediately cancelled the write. It now persists from the ViewModel scope with NonCancellable, which outlives both the sheet and the screen. (Day-one bug from PR #1338 — the write only ever ran on the button path, never on swipe/back/outside-tap.) - The Send button's spinner was gated on the worker's "handed to the SDK" marker, which fires ~20ms after the tap while the purchase takes seconds, so it flashed invisibly. It now holds for the whole purchase, the button is disabled while busy (standard disabled styling), the balance observer can no longer re-enable it mid-flight, and on success it stays disabled through to the screen closing. - Whole-balance ("Max") top-ups are refused with an explanation instead of approximated: the SDK's top-up call takes an exact amount and its send-all mode is not reachable through the FFI yet (rust-dashcore #915 + the key-wallet flag, MO-998). Tapping MAX explains immediately — before the PIN prompt and without changing the amount, via a new opt-in EnterAmountFragment.onMaxVetoed hook — typing the full balance shows the same text inline, and the purchase path refuses as a backstop. - The pre-existing silent minimum now explains itself: below 0.0005 DASH the Continue button greyed out with no message. One constant drives both the button rule and the text so they cannot drift. Also keeps the null-fee guard on the confirmation screen: post-cutover the dry run does not complete the tx, so tx.fee is null and Max crashed after the PIN prompt. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]>
HashEngineering
added a commit
that referenced
this pull request
Aug 17, 2026
…erything MAX (#1536) * feat: background completion of interrupted SDK top-ups + stuck legacy top-up rescue The SDK top-up (SdkTransparentTopUp, post-cutover Buy Credits) is a fused build+credit call whose in-process resume gate only helps if the user re-enters the flow. This adds the restart-surviving half: - SdkTopUpRecoveryService: one pass lists the SDK's tracked top-up locks (the two resumable funding types) and resumes each from its persisted outpoint via resumeTopUpWithExistingAssetLock — Rust owns rebroadcast/proof/consumption, so a pass is idempotent and a crash mid-run or duplicate enqueue is harmless. Includes a no-boot pending check for the sync sweep (never starts the SDK just to probe). - ResumeTopUpsWorker/Operation: payload-free WorkManager job — no txid, no identity, and no wallet password in WorkManager's database (the legacy TopupIdentityWorker stores one); unique KEEP work, network constraint, exponential backoff. Enqueued when SdkTransparentTopUp reports an Ambiguous outcome and from the checkTopUps sweep whenever tracked locks are pending. - checkTopUps: documents the scoping invariant (the legacy scan only ever sees dashj-created top-ups — the SDK derives keys the dashj chain never watches; this body retires with the dashj engine), and re-announces legacy top-up txs that provably never reached the network (SELF + PENDING + zero broadcast peers — the port-9999 field failure) while dashj still owns the peer group. An unconfirmed lock also blocks the auto-cutover, so rescuing these directly shortens the dual-running period. - signAndSendAssetLock stays the pre-cutover dashj builder; its top-up key is now issued inside the dashj branch only, so no key index is burned when the flow does not reach the dashj build. Restore recovery is deliberately absent: it requires the SDK to record the top-up locks its chain scan already recognizes (platform ask on MO-998); once that lands, this worker completes rediscovered locks with no further wallet changes. 16 host tests. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * feat: credited state for SDK top-ups in transaction details SDK top-ups have no topups-table row, so the detail screens now derive credited state from the SDK itself: a lock still in the recovery queue is pending, gone is credited (SdkTopUpRecoveryService.isTopUpPending + TransactionResultViewModel.sdkTopUpCredited). The OP_RETURN output row of an SDK top-up is labeled 'Platform credits (…)' like the dashj path always did, instead of the raw script name. The legacy TopupIdentityWorker status observers (log-only plus one error flag) are dropped from both screens — that worker is deleted in a follow-up commit. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: run the Buy Credits purchase as unique background work A lock screen cancelled a purchase mid-flow in testing: the fragment ran the SDK top-up in its own lifecycle scope. PerformTopUpWorker now owns the purchase — input is the amount only (no wallet password, no txid in WorkManager's database; the SDK signs internally), one unique KEEP work name so double-taps attach instead of buying twice, and the screen just observes WorkInfo (spinner/success/failure/unconfirmed). A rerun after process death cannot double-pay: SdkTransparentTopUp's resume gate matches the already-broadcast lock first, and an unconfirmed outcome hands off to ResumeTopUpsWorker. Buy Credits is SDK-only from the go handler down (dashj branch removed from the fragment). Co-Authored-By: Claude Fable 5 <[email protected]> * refactor!: delete the dashj Buy Credits purchase path (Phase 2/3) Management rule: a replaced function loses its dashj implementation in the same PR. Deleted: signAndSendAssetLock + the isAssetLock dry-run arm (SendCoinsViewModel), createAssetLockSendRequest (SendCoinsTaskRunner), getNextKey (topup-chain key issuance), and TopupIdentityWorker/Operation (the legacy per-txid retry job that stored the wallet password in WorkManager). Pre-cutover Buy Credits now refuses cleanly via SdkTransparentTopUp's fail-closed gate instead of building with dashj. checkTopUps recovery and the topups table STAY — they credit legacy top-ups and can only retire once the SDK can adopt locks it did not create (MO-998 upstream ask). MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * fix: persist the credits explainer's shown flag when displayed, not on dismissal The write lived only in the dismiss() override, so any close that bypasses it (swipe-down, tap outside, back) never saved the flag and the explainer re-appeared on every Buy Credits tap; even the button path wrote during teardown, racing the dialog's destruction. Mark it shown the moment it is displayed instead. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: inline button progress for Buy Credits instead of a blocking dialog The Send button shows a progress circle (taps swallowed) only until the purchase worker reports it has handed the buy to the SDK (a progress marker set just before the SDK call) — from that point the outcome no longer needs the screen: success still auto-closes, failures still dialog, and the recovery worker owns anything interrupted. The shared enter-amount component gains an optional setContinueLoading(loading) overlay. Co-Authored-By: Claude Fable 5 <[email protected]> * refactor!: delete the legacy dashj top-up retry loops (Phase 2/3 item 5) checkTopUps now does one thing: wake the SDK recovery worker when tracked locks are pending. The two dashj-era loops — the unused-rows retry and the once-per-start key-chain scan (with the never-broadcast re-announce) — are deleted, along with their tests. Uncredited dashj-era top-ups are no longer retried by the app; they become recoverable again when the SDK gains chain rediscovery of asset locks (pending platform change), surfacing on the same recovery queue. Funds are never lost in the interim: the locks sit on chain, claimable by this wallet's keys. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * chore: sweep 17 dead imports left by the deleted dashj purchase path BuyCreditsFragment now imports no legacy platform-library classes and no dashj machinery beyond Coin arithmetic and the shared fee-preview types (Phase 3 neutral-money-type material). Co-Authored-By: Claude Fable 5 <[email protected]> * fix: treat a Platform already-used rejection as terminal, not retryable Platform's own rejection of a consumed asset lock does NOT arrive as the SDK's typed AssetLockAlreadyConsumed error — it is a Generic protocol error reading "output N already completely used" (the wording the legacy dashj path matched on). Two live consequences on testnet: - the recovery worker classified it as a retryable failure, so WorkManager backed off forever on a lock whose credits had landed; - the purchase resume gate classified it as Ambiguous, so once a stale consumed lock sat in the SDK's tracked list EVERY Buy Credits attempt failed with "outcome unconfirmed" and no new top-up was possible. isAlreadyConsumed() now matches both shapes (down the cause chain, since the JNI wraps it). The recovery worker reports it terminal; the resume gate drops that specific lock and retries once, taking the fresh-build branch. Safe by construction: the rejection proves the lock's outputs are spent, so no double-pay is possible, and the skip is keyed to that one outpoint so it cannot loop. Root cause is upstream: nothing marks a lock consumed locally when Platform reports it used (MO-998 ask). These are the client-side mitigations. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: Buy Credits UI — explainer, button busy state, and Max refusal Four on-device findings from the testnet round: - The credits explainer re-appeared on every visit: its "seen" flag was written from the sheet's own lifecycle scope, so dismissing it immediately cancelled the write. It now persists from the ViewModel scope with NonCancellable, which outlives both the sheet and the screen. (Day-one bug from PR #1338 — the write only ever ran on the button path, never on swipe/back/outside-tap.) - The Send button's spinner was gated on the worker's "handed to the SDK" marker, which fires ~20ms after the tap while the purchase takes seconds, so it flashed invisibly. It now holds for the whole purchase, the button is disabled while busy (standard disabled styling), the balance observer can no longer re-enable it mid-flight, and on success it stays disabled through to the screen closing. - Whole-balance ("Max") top-ups are refused with an explanation instead of approximated: the SDK's top-up call takes an exact amount and its send-all mode is not reachable through the FFI yet (rust-dashcore #915 + the key-wallet flag, MO-998). Tapping MAX explains immediately — before the PIN prompt and without changing the amount, via a new opt-in EnterAmountFragment.onMaxVetoed hook — typing the full balance shows the same text inline, and the purchase path refuses as a backstop. - The pre-existing silent minimum now explains itself: below 0.0005 DASH the Continue button greyed out with no message. One constant drives both the button rule and the text so they cannot drift. Also keeps the null-fee guard on the confirmation screen: post-cutover the dry run does not complete the tx, so tx.fee is null and Max crashed after the PIN prompt. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * refactor: remove the last dashj references from BuyCreditsFragment The screen is SDK-only now, so nothing here needs bitcoinj: - money types switch to org.dash.wallet.common.money.Coin, dropping the toDashjCoin() round-trips; the one conversion left reads the base ViewModel's still-dashj maxOutputAmount via toNeutralCoin(); - the dry-run block in showPaymentConfirmation is deleted outright. Every value it computed (amount, total, exchangeRate, amountStr, fee) was assigned and never read — ConfirmTopUpDialogFragment takes no arguments and reads currentAmount from the shared ViewModel — so this removes the null tx.fee crash site rather than guarding it. The caller already checks dryrunSendRequest != null, so the local guard went too; - the InsufficientMoneyException check becomes a plain SendCoinsViewModel.isInsufficientFunds boolean, keeping the dashj exception type inside the ViewModel for Phase 3 to deal with. Compile-checked only; not yet exercised on device. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * feat: Buy Credits MAX via the Internal Transfer pattern — full balance + one fee-adjusted retry Replaces the MAX refusal with the same design the shielded Internal Transfer screen already ships (ShieldedTransferExecutor.submit): MAX fills the FULL spendable balance, the worker submits it as-is, and when the asset-lock coin selection comes up short pre-broadcast (nothing spent, selection released) it retries ONCE with an estimated fee reserve withheld. Over-reserve is lossless — the builder returns the excess as change. The exact L1 fee is unknowable app-side, which is why the retry converges where any precomputed amount cannot. Differences from the shielded original, each forced by a live testnet failure or a top-up-specific constraint: - The retry matches the CLASSIFIER's verdict, not an engine message. The top-up build surfaces its shortfall as key-wallet's builder text ("Coin selection error: Insufficient funds…"), not the shielded path's "asset lock coin selection is short" — matching the latter alone made the first live MAX fail without ever retrying. The two provably-pre-broadcast retryable reasons in classifyBroadcastFailure are now named constants and the worker keys on them. - The fee reserve is sized from the SDK's OWN eligible-UTXO count — a COUNT twin of the preflight's eligibility SQL (shared predicate, so they cannot drift) — not dashj's spendableUtxoCount(), which counts coins the asset lock can never select and can be stale post-cutover. - The adjusted retry is refused below Platform's 50,500-duff top-up floor rather than broadcasting a lock Platform deterministically rejects (which would strand the whole balance). - The funding preflight is MAX-aware: it demands fee headroom ON TOP of the amount, which a full balance can never satisfy — and the withheld reserve IS the fee allowance, so a MAX preflights the fee-adjusted figure with the headroom absorbed (live failure two: reserve and headroom stacked, rejecting every MAX under ~33 UTXOs). The screen keeps its spinner until the work reaches a terminal state so every failure still shows a dialog HERE — closing at the SDK hand-off was tried and reverted (it silenced all post-hand-off failure dialogs); the comment records that so it is not reintroduced casually. A MAX purchase waiting on a chain-locked block legitimately spins for minutes; the purchase survives the screen either way (unique work + recovery worker). Verified end-to-end on testnet: MAX over a 1,000,737-duff balance — first attempt refused pre-broadcast, auto-adjusted to 999,545 (reserve 1,192 duffs from a 2-UTXO count), broadcast, chain-locked next block, credited, lock consumed. Also confirmed en route: an InstantSend-locked deposit is spendable by MAX immediately while unconfirmed — the SDK's require_final_inputs is not a wait-for-confirmation rule. The success log now names the amount actually sent, not the requested one. The dead EnterAmountFragment.onMaxVetoed hook and the buy_credits_max_not_supported string are removed with the refusal. MO-998 / #1520 Co-Authored-By: Claude Fable 5 <[email protected]> * fix: review round 1 — scoped stale-work handling, inclusive floor, single observer Three fixes from PR review: - Replace the app-global WorkManager.pruneWork() with an observer-side gate: terminal work states delivered before this view has seen the purchase active are leftovers from a previous visit and are ignored. A global prune erased finished work states other features observe by tag (e.g. the username-vote broadcast status readers). - Align the Buy Credits screen minimum with the FFI's INCLUSIVE 50,500-duff floor (was 50,000, which let 50,001-50,500 through to a guaranteed refusal), and accept a MAX retry of exactly the floor (>= not >). The error message now names the real minimum. - Register the top-up work observer once in onViewCreated instead of per purchase: re-observing stacked observers (two failure dialogs on a second failed purchase), and observing only after Continue hid the in-flight spinner from a user re-entering mid-purchase. Co-Authored-By: Claude Fable 5 <[email protected]> * docs+chore: review round 2 — restore caveat on credited state, lifecycle idiom, imports - Document on isTopUpPending/sdkTopUpCredited that a phrase restore empties the tracked-lock table, so "no pending lock" also matches an unclaimed top-up: the signal is display-only until chain rediscovery of tracked locks lands. Never gate a spend or retry on it. - setContinueLoading: replace deprecated launchWhenStarted with withStarted on the view lifecycle. - Import AssetLockKind instead of fully qualifying it three times. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: typed shortfall arms in classifyBroadcastFailure — retry survives the typed-error AAR line CoreInsufficientFunds (FFI 22, atomic Core selection) and AssetLockInsufficientFunds (FFI 29, asset-lock coin selection — the top-up build's shape) now classify by TYPE to the same named retryable reasons the MAX top-up's fee-adjusted retry keys off. The message arms stay as fallback for AAR lines that surface these as WalletOperation strings. Both types are raised while building, strictly pre-broadcast: the asset-lock builder promotes every shortfall shape (including the zero-candidate NoUtxosAvailable) to the typed error via map_builder_error. The new test pins the reason mapping and includes deliberately unrecognizable message texts, so classification holds on type alone if engine wording drifts. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: post-rebase reconciliation with the phase1 tip + review nit Rebasing onto the current feat/kotlin-sdk-phase1 (identity-balance display, updateView re-entry crash fix, evidence-based preflight): - The eligible-UTXO COUNT is rebuilt over the base's shared join spine with the SAME lockCount-parameterized finality term and the SAME persisted-IS-lock evidence as the eligibility sum (eligibleAssetLockUtxoCountSql), so the MAX fee reserve is sized from exactly the population the sum (and the engine's selection) sees. - Drop the base's `viewModel.isAssetLock = true` dashj tripwire: the dashj purchase path it guarded is deleted; handleGo is overridden to the SDK worker and can never reach signAndSendPayment. - Remove a duplicate flat ELIGIBLE_ASSET_LOCK_DUFFS_SQL that the replay reintroduced beside the base's parameterized one. - Review nit: retryableShortfall already proves NotBroadcast — drop the redundant re-test in the MAX retry condition. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue being fixed or feature implemented
Related PR's and Dependencies
Screenshots / Videos
How Has This Been Tested?
Checklist: