Skip to content

feat(dashpay): make username voting real - #923

Merged
QuantumExplorer merged 5 commits into
developfrom
claude/voting-section-plan-e42ebe
Aug 7, 2026
Merged

QuantumExplorer merged 5 commits into
developfrom
claude/voting-section-plan-e42ebe

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

The problem

Menu → Voting (DASHPAY builds, on by default) was a self-contained mock. It made zero SDK calls and zero network calls.

  • Voting keys were validated against three hardcoded strings, and the "Masternode IP address" shown to the user was fabricated:
    // VotingViewModel.swift:34-38, :71
    private var validKeys: [String] = ["kn2GwaSZ…", "n6YtJ7pd…", "maEiRZeK…"]  // TODO: temp
    masternodeKeys.append(MasternodeKey(key: key, ip: "182.151.12.\(masternodeKeys.count)"))
  • "Votes" were integer arithmetic on a local SQLite row — no state transition, no signing, no broadcast.
  • The only writer to username_requests was addMockRequest(), wired to a tap gesture on the screen's title label and shipped in release. The production writer was deleted in 97398f7ca, so on a real install the list was permanently empty and the Quick Voting button permanently hidden.
  • Deadlines were invented as createdAt + 14 days — wrong by ~2 weeks on testnet, where contests run 90 minutes.

Meanwhile every piece needed to do this properly already existed and was unused: SDK.castContestedResourceVote, PlatformWalletManager.masternodes(for:), and the wallet's own ProviderVotingKeys derivation.

What this does

Modeled on Dash Evo Tool's DPNS contested-names screen (src/backend_task/contested_names/*).

Browse real contests. ContestedNamesService lists every open DPNS contest from Platform with contenders, tallies and the authoritative deadline. Nothing is estimated — an unknown end time renders "Deadline unknown", not a guess.

Vote with the wallet's own nodes. MasternodeVoterRegistry joins the on-chain masternode aggregation against the wallet's derived voting-key pool, so a node is offered only when this wallet actually holds the key Platform will check the signature against. Filtered to active, non-revoked registrations. No key is ever pasted or stored — EnterVotingKeyViewController is gone.

Real broadcast. MasternodeVoteCaster pre-flights that the poll is open (turning a ~70 s opaque retry into an instant, actionable error), gates on AuthenticationGate before deriving key material, then calls SDK.castContestedResourceVote per node. Serial per node: the SDK fetches an identity nonce per voter identity, so concurrent votes from one node would race.

Honest reporting. One node failing never abandons the rest — the result sheet reads "3 of 4 masternodes voted" and shows Platform's own message per failure (already voted, too many vote changes) verbatim.

Honest capability. Evonodes count as 4 votes and masternodes as 1, matching drive-abci's server-side weighting (MasternodeType::Evo => 4). A wallet with no votable node browses fine and says so; the vote controls are disabled, not faked.

Search normalizes homographs before matching — Platform stores alice as a11ce, so a raw substring match finds nothing. (Dash Evo Tool's own filter misses i; this one doesn't.)

Removed

Rebuilt in SwiftUI + ViewModel per CLAUDE.md. The storyboard/UIKit stack is deleted — including its app-wide extension UITableView { override var intrinsicContentSize / contentSize } (UsernameVotingViewController.swift:324), which affected every table view in the dashpay target. ⚠️ This is the one change that can regress unrelated screens — please smoke the Tx list, menus and Explore.

Also removed as unreachable dead code:

  • username_requests, its DAO, and UsernameRequest / MasternodeKey / VotingFiltersModel
  • RequestDetailsViewController + UsernameRequests.storyboard and its only trigger — reached solely via a JoinDashPayState.voting branch keyed on UsernamePrefs.requestedUsernameId, which nothing in the repo ever assigns
  • VotingConstants.maxVotes, whose comment called it a vote cap when Platform's 5 is a limit on vote changes per masternode per contest
  • VoteButton.swift (never referenced), kVotingPanelClosed, the title-tap mock generator, and the stray print(dto) / print("VOTING: votesLeft:")

MasternodeKeyUsage.indexByAddress(family:targets:) is promoted out of MasternodesScreen's private copy so the ownership labels and the voting registry share one address→key-index join instead of two.

Depends on

dashpay/platform#4328 — the typed DPNS contest read layer. ✅ Merged (96af88d2b8 on v4.2-dev), so this is no longer blocking. Verified: with the local ../platform checkout moved to merged v4.2-dev, the dashpay scheme builds clean and the SDK's 19 DPNSContestDecoderTests pass.

Testing

Clean dashpay build (ARCHS=arm64, iOS Simulator); installs and launches on the QA-iPhone16 simulator. The unit-test target is broken on this branch (pre-existing), so the remaining verification is a testnet smoke — testnet's 90-minute contests make a full lifecycle observable in one sitting:

  1. Menu → Voting lists real contested names with live tallies and a countdown matching the 90-minute testnet window (not 14 days).
  2. A wallet with no masternodes browses fine; vote controls disabled with the explanatory state.
  3. With a testnet masternode: header shows the right node count and weight (evonode = 4).
  4. Cast → PIN → success; re-query shows the tally up by the node's weight. Watch the proTxHash byte orientation here — PlatformMasternode.proTxHash is raw wire bytes and MasternodesScreen reverses it only for display; a wrong orientation surfaces immediately as MasternodeNotFoundError.
  5. Re-cast the same choice → Platform's MasternodeVoteAlreadyPresentError is surfaced verbatim, not swallowed.
  6. Multi-node with the network killed mid-run → partial success is reported per node.

Logs: xcrun simctl spawn <udid> log show --last 15m --predicate 'eventMessage CONTAINS "VOTING ::"'

Not in this PR

Past contests, a My-usernames tab, bulk voting and scheduled votes were scoped in the plan and are follow-ups; this PR is the browse + cast core. Worth knowing for the Past tab: Platform prunes resolved polls from the contested tree, so past contests can only ever be local history — Dash Evo Tool has the same constraint.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a redesigned username voting experience for browsing, searching, sorting, and refreshing active contests.
    • Added contest details with contender tallies, deadlines, and contender, lock, or abstain choices.
    • Added masternode selection, weighted voting, and bulk voting across multiple contests.
    • Added username request status tracking with deadlines, vote totals, and refresh support.
    • Added clear success, failure, partial-success, and unavailable-voting states.
  • Improvements

    • Updated username setup and voting flows to use current contest information.
    • Added messaging for voting eligibility, authentication, synchronization, and key-related errors.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@QuantumExplorer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 920e2981-2d34-46eb-8c7b-416e4434158a

📥 Commits

Reviewing files that changed from the base of the PR and between aeff28d and ca488a9.

📒 Files selected for processing (11)
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/ContestedNamesService.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoteCaster.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoterRegistry.swift
  • DashWallet/Sources/UI/DashPay/Usernames/UsernameRequestStatusScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVotingScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/DerivationPathKeys/Models/DerivationPathKeysModel.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift
  • DashWallet/en.lproj/Localizable.strings
  • DashWallet/en.lproj/Localizable.stringsdict
📝 Walkthrough

Walkthrough

The PR replaces legacy username-request voting with Platform contest services, wallet-derived masternode voting, weighted vote casting, and SwiftUI contest screens. It removes obsolete persistence, UIKit voting screens, resources, and project references.

Changes

Platform voting migration

Layer / File(s) Summary
Voting services and vote casting
DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/*
Adds contest retrieval, eligible masternode discovery, voting-key derivation, serial vote broadcasting, and aggregate vote reports.
Contest state and SwiftUI voting flow
DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift, DashWallet/Sources/UI/DashPay/Voting/UsernameVotingScreen.swift, DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift, DashWallet/Sources/UI/DashPay/Voting/CastVoteSheet.swift, DashWallet/Sources/UI/DashPay/Voting/BulkVoteSheet.swift
Replaces mock username-request state with Platform contests, search and sorting, contest details, node selection, weighted submission, bulk voting, and result states.
Username request status flow
DashWallet/Sources/UI/DashPay/Usernames/UsernameRequestStatusScreen.swift
Adds contested-name status loading and display for contender status, vote totals, deadlines, and refresh states.
Navigation and wallet key matching
DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift, DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift, DashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift
Hosts the SwiftUI voting screens and centralizes wallet address-to-index matching.
Legacy flow removal and project registration
DashWallet.xcodeproj/project.pbxproj, DashWallet/Sources/Application/App.swift, DashWallet/Sources/UI/DashPay/Setup/CreateUsername/*, DashWallet/Sources/Models/Voting/VotingPrefs.swift, DashWallet/en.lproj/Localizable.strings
Removes obsolete DAOs, models, UIKit controllers, cells, storyboards, XIBs, cleanup logic, and project entries. Registers replacement files and adds voting localization strings.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change from mock username voting to real DPNS-backed voting.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/voting-section-plan-e42ebe

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

Menu → Voting was a self-contained mock: it made zero SDK and zero network
calls, validated masternode voting keys against three hardcoded strings
(`VotingViewModel.validKeys`), fabricated the "masternode IP address" it showed
the user (`"182.151.12.\(count)"`), and recorded "votes" as integer arithmetic
on a local SQLite row. The only writer to `username_requests` was
`addMockRequest()`, wired to a tap gesture on the screen's title label and
shipped in release — the production writer was removed in 97398f7, so on a
real install the list was permanently empty. Section headers dated contests at
`createdAt + 14 days`, which is wrong by roughly two weeks on testnet, where
contests run 90 minutes.

Everything needed to do this properly already existed and was unused. Now:

- **Browse real contests.** `ContestedNamesService` lists every open DPNS
  contest from Platform with its contenders, vote tallies, and the authoritative
  deadline. No estimated dates: an unknown end time renders as "Deadline
  unknown" rather than a guess.
- **Vote with the wallet's own nodes.** `MasternodeVoterRegistry` joins the
  on-chain masternode aggregation (`PlatformWalletManager.masternodes(for:)`)
  against the wallet's derived `ProviderVotingKeys` pool, so a node is offered
  only when this wallet actually holds the key Platform checks the signature
  against. No key is ever pasted or stored — `EnterVotingKeyViewController` is
  gone.
- **Real broadcast.** `MasternodeVoteCaster` pre-flights that the poll is open,
  gates on `AuthenticationGate` (reused, not copied) before deriving key
  material, then calls `SDK.castContestedResourceVote` per node. Nodes are cast
  serially because the SDK fetches an identity nonce per voter identity and
  concurrent votes from one node would race.
- **Honest reporting.** One node failing never abandons the rest; the result
  sheet says "3 of 4 masternodes voted" and shows Platform's own error for each
  failure ("already voted", "too many vote changes") verbatim.
- **Honest capability.** Evonodes are shown as 4 votes and masternodes as 1,
  matching drive-abci's server-side weighting. A wallet with no votable node
  browses fine and says so — the vote controls are disabled, not faked.

Search normalizes homographs before matching, since Platform stores "alice" as
"a11ce" and a raw substring match finds nothing.

Rebuilt in SwiftUI + ViewModel per CLAUDE.md; the storyboard/UIKit stack is
deleted, including its app-wide `extension UITableView { override var
intrinsicContentSize / contentSize }`, which affected every table view in the
dashpay target.

Also removed as unreachable dead code: `username_requests` and its DAO, the
`RequestDetailsViewController` screen and its only trigger (reached solely via a
`JoinDashPayState.voting` branch keyed on `UsernamePrefs.requestedUsernameId`,
which nothing in the repo assigns), and `VotingConstants.maxVotes`, whose
comment described it as a vote cap when Platform's 5 is a limit on vote
*changes* per masternode per contest.

`MasternodeKeyUsage.indexByAddress(family:targets:)` is promoted out of
`MasternodesScreen`'s private copy so the ownership labels and the voting
registry share one address→key-index join.

Requires dashpay/platform "feat(swift-sdk): typed DPNS contested-name browsing
for voters".

Co-Authored-By: Claude Opus 5 <[email protected]>
@QuantumExplorer
QuantumExplorer force-pushed the claude/voting-section-plan-e42ebe branch from 2908795 to 420ab7a Compare August 7, 2026 11:57

@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: 5

🧹 Nitpick comments (1)
DashWallet.xcodeproj/project.pbxproj (1)

6027-6028: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate the duplicate "SwiftDashSDK" groups.

This change adds two new groups both named "SwiftDashSDK" (64CE06816C51B58845E767AA and 59B3BC2E57C568600BDD78F5) as children of the Infrastructure group. An existing "SwiftDashSDK" group (7E31813A79237F4E037063AA) already exists as a sibling in the same Infrastructure group and holds the other SwiftDashSDK sources. Each new group has its own "Voting" subgroup: one holds MasternodeVoterRegistry.swift and ContestedNamesService.swift, the other holds MasternodeVoteCaster.swift.

This creates three sibling groups with the identical name "SwiftDashSDK" in the Xcode navigator, and it splits three closely related voting files across two separate subgroups. Move all three files into a single "Voting" subgroup inside the existing 7E31813A79237F4E037063AA "SwiftDashSDK" group, and remove the two new duplicate groups.

♻️ Proposed group consolidation
-		64CE06816C51B58845E767AA /* SwiftDashSDK */ = {
-			isa = PBXGroup;
-			children = (
-				2A85F872C9D04B3BF9C2FFF3 /* Voting */,
-			);
-			path = SwiftDashSDK;
-			sourceTree = "<group>";
-		};
-		2A85F872C9D04B3BF9C2FFF3 /* Voting */ = {
-			isa = PBXGroup;
-			children = (
-				15D89828EC913714251D0B58 /* MasternodeVoterRegistry.swift */,
-				FC1426BD13E794C788646055 /* ContestedNamesService.swift */,
-			);
-			path = Voting;
-			sourceTree = "<group>";
-		};
-		59B3BC2E57C568600BDD78F5 /* SwiftDashSDK */ = {
-			isa = PBXGroup;
-			children = (
-				F1884BF21637694C37C972D4 /* Voting */,
-			);
-			path = SwiftDashSDK;
-			sourceTree = "<group>";
-		};
-		F1884BF21637694C37C972D4 /* Voting */ = {
-			isa = PBXGroup;
-			children = (
-				23AEFB2398EDA01C69E5A8F1 /* MasternodeVoteCaster.swift */,
-			);
-			path = Voting;
-			sourceTree = "<group>";
-		};

Then add a single "Voting" subgroup (containing all three files) as a child of the existing 7E31813A79237F4E037063AA /* SwiftDashSDK */ group, and remove 59B3BC2E57C568600BDD78F5 and 64CE06816C51B58845E767AA from the Infrastructure group's children list.

Also applies to: 8552-8584

🤖 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 `@DashWallet.xcodeproj/project.pbxproj` around lines 6027 - 6028, Consolidate
the duplicate SwiftDashSDK groups in the Xcode project: move
MasternodeVoterRegistry.swift, ContestedNamesService.swift, and
MasternodeVoteCaster.swift into one Voting subgroup under the existing
7E31813A79237F4E037063AA SwiftDashSDK group, then remove the
59B3BC2E57C568600BDD78F5 and 64CE06816C51B58845E767AA groups and their
Infrastructure child references.
🤖 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 `@DashWallet.xcodeproj/project.pbxproj`:
- Around line 1899-1904: Update the dashwallet target’s Xcode project
configuration to include all six voting files—MainMenuViewController.swift,
UsernameVotingScreen.swift, VotingViewModel, and the three voting services—in
both PBXBuildFile declarations and the target’s Sources build phase. Ensure each
file is compiled by dashwallet without changing unrelated target settings.

In `@DashWallet/en.lproj/Localizable.strings`:
- Around line 4724-4772: Convert the Localizable.strings file from UTF-8 to
UTF-16LE while preserving all existing localization keys and values. Use
BartyCrouch or Xcode-aware localization tooling to perform the update, then
verify the saved file retains UTF-16LE encoding.

In `@DashWallet/Sources/UI/DashPay/Voting/CastVoteSheet.swift`:
- Line 32: Format the dismiss environment property in CastVoteSheet so the
`@Environment`(\.dismiss) wrapper and its declaration each occupy separate lines,
satisfying the SwiftLint attributes rule while preserving the existing behavior.

In `@DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift`:
- Around line 155-168: Update refreshContest(normalizedLabel:) so a resolved
state removes the matching contest from contests instead of updating it; also
remove the contest when voteState returns nil for an item previously in the
active list. Ensure the detail screen observes that removal and dismisses or
disables voting, preserving the active-contest-only contract.

In `@DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift`:
- Around line 490-493: Update showVoting() to push a dedicated thin
hosting-controller wrapper for UsernameVotingScreen instead of a bare
UIHostingController. Make the wrapper conform to the navigation display protocol
required by BaseNavigationController.willShow, while preserving the existing
bottom-bar and push behavior.

---

Nitpick comments:
In `@DashWallet.xcodeproj/project.pbxproj`:
- Around line 6027-6028: Consolidate the duplicate SwiftDashSDK groups in the
Xcode project: move MasternodeVoterRegistry.swift, ContestedNamesService.swift,
and MasternodeVoteCaster.swift into one Voting subgroup under the existing
7E31813A79237F4E037063AA SwiftDashSDK group, then remove the
59B3BC2E57C568600BDD78F5 and 64CE06816C51B58845E767AA groups and their
Infrastructure child references.
🪄 Autofix

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 Plus

Run ID: b8d49a25-c0a4-4153-91db-ebb9ed018b8a

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3b0e4 and 2908795.

📒 Files selected for processing (38)
  • DashWallet.xcodeproj/project.pbxproj
  • DashWallet/Sources/Application/App.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/ContestedNamesService.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoteCaster.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoterRegistry.swift
  • DashWallet/Sources/Models/Voting/DAO/UsernameRequestsDAO.swift
  • DashWallet/Sources/Models/Voting/MasternodeKey.swift
  • DashWallet/Sources/Models/Voting/UsernameRequest.swift
  • DashWallet/Sources/Models/Voting/VotingConstants.swift
  • DashWallet/Sources/Models/Voting/VotingFiltersModel.swift
  • DashWallet/Sources/Models/Voting/VotingPrefs.swift
  • DashWallet/Sources/UI/DashPay/Setup/CreateUsername/CreateUsernameViewModel.swift
  • DashWallet/Sources/UI/DashPay/Setup/CreateUsername/JoinDashPayViewModel.swift
  • DashWallet/Sources/UI/DashPay/Usernames/IconAttributedText.swift
  • DashWallet/Sources/UI/DashPay/Usernames/RequestDetailsViewController.swift
  • DashWallet/Sources/UI/DashPay/Usernames/UsernameRequests.storyboard
  • DashWallet/Sources/UI/DashPay/Voting/CastVoteSheet.swift
  • DashWallet/Sources/UI/DashPay/Voting/CastVoteViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/GroupedRequestCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/MasternodeIPCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/UsernameRequestCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/VoteButton.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/VotingFilterItemSelectableCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/EnterVotingKeyViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/QuickVoteViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameRequestDetailsViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVoting.storyboard
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVotingScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVotingViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingFiltersViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingHeaderView.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingHeaderView.xib
  • DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift
  • DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift
  • DashWallet/Sources/UI/Menu/Tools/MasternodesScreen.swift
  • DashWallet/en.lproj/Localizable.strings
💤 Files with no reviewable changes (24)
  • DashWallet/Sources/UI/DashPay/Voting/Cells/MasternodeIPCell.swift
  • DashWallet/Sources/Models/Voting/MasternodeKey.swift
  • DashWallet/Sources/Application/App.swift
  • DashWallet/Sources/Models/Voting/VotingConstants.swift
  • DashWallet/Sources/UI/DashPay/Usernames/RequestDetailsViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVoting.storyboard
  • DashWallet/Sources/UI/DashPay/Voting/VotingHeaderView.swift
  • DashWallet/Sources/UI/DashPay/Usernames/IconAttributedText.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/UsernameRequestCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/CastVoteViewController.swift
  • DashWallet/Sources/Models/Voting/VotingFiltersModel.swift
  • DashWallet/Sources/Models/Voting/DAO/UsernameRequestsDAO.swift
  • DashWallet/Sources/UI/DashPay/Usernames/UsernameRequests.storyboard
  • DashWallet/Sources/UI/DashPay/Voting/Cells/VotingFilterItemSelectableCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/GroupedRequestCell.swift
  • DashWallet/Sources/UI/DashPay/Voting/QuickVoteViewController.swift
  • DashWallet/Sources/UI/DashPay/Setup/CreateUsername/CreateUsernameViewModel.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVotingViewController.swift
  • DashWallet/Sources/Models/Voting/UsernameRequest.swift
  • DashWallet/Sources/UI/DashPay/Voting/EnterVotingKeyViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameRequestDetailsViewController.swift
  • DashWallet/Sources/UI/DashPay/Voting/Cells/VoteButton.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingHeaderView.xib
  • DashWallet/Sources/UI/DashPay/Voting/VotingFiltersViewController.swift

Comment thread DashWallet.xcodeproj/project.pbxproj Resolved
Comment thread DashWallet/en.lproj/Localizable.strings Resolved
QuantumExplorer and others added 3 commits August 7, 2026 19:07
Follows the SDK change making `dpnsNormalizeLabel(_:)` throw: homograph
normalization is protocol behavior owned by Rust, so the app no longer accepts
a locally-guessed spelling.

`ContestedNamesService.normalizedLabel(for:)` now returns `String?`. The search
filter needs the SDK handle, and so does the contest list it filters — a
non-empty list means the handle is up, so a `nil` here only happens when there
is nothing to filter. In that case the list is left unfiltered rather than
matched against a substitute spelling that could hide real rows.

Co-Authored-By: Claude Opus 5 <[email protected]>
Review follow-up on #923.

**Resolved contests leave the active list.** `refreshContest` updated a
contest's tallies but kept it in `contests` even when Platform reported it
settled, so the list could offer a Vote button whose only possible outcome was
the caster's closed-poll rejection. `contests` is the *open* contest list, so a
resolved contest — or one Platform no longer holds contenders for — is now
removed and recorded in `closedLabels`. A detail screen already open on that
contest swaps its vote controls for a "voting has closed" notice rather than
showing a stale snapshot with live-looking buttons.

The nil case is now distinguished from the error case: a *successful* query
returning no contenders means the poll was pruned, while a thrown query taught
us nothing and leaves the cached row untouched. Previously `try?` collapsed
both, which would have let a network blip evict a live contest.

**`dashwallet` target membership.** The `dashwallet` target's Debug
configuration defines `DASHPAY` (`SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG
PIGGYCARDS_ENABLED DASHPAY"`, plus `-DDASHPAY`), and `MainMenuViewController`
is a member of both targets, so its `#if DASHPAY showVoting()` compiles there
and references `UsernameVotingScreen`. The seven voting files are now in both
Sources phases, matching every dependency they touch
(`MasternodeProviderKeyDeriver`, `MasternodeKeyUsage`, `AuthenticationGate`,
`SwiftDashSDKHost`), all of which were already dual-target. The legacy
storyboard stack this replaces was dashpay-only, so that build was already
broken this way.

**Project structure.** Consolidated the three sibling `SwiftDashSDK` groups the
file had grown into one, with a single `Voting` subgroup holding all three
services instead of splitting them across two same-named groups.

**SwiftLint.** `@Environment(\.dismiss)` moved to its own line — `attributes`
is an opt-in rule enabled in `.swiftlint.yml`, and it fires on attributes
carrying arguments.

Co-Authored-By: Claude Opus 5 <[email protected]>
Audit of what this PR removed turned up one genuine regression and one
capability that had not been carried over.

**Regression: the DashPay row stopped navigating.** I had removed
`RequestDetailsViewController` on the basis that its only entry point —
`handleJoinDashPayTap(state: .voting)` — was unreachable. That was wrong.
`.voting` is set from `DWContestedNameStatusService.pendingLabel`
(`JoinDashPayViewModel:33`), which is live: the registration coordinator writes
it on every contested submission. Only the *other* two states in that method
(`.approved` / `.blocked`) were dead, because they came from the DAO branch
keyed on `UsernamePrefs.requestedUsernameId`, which nothing in the repo assigns.
So a user with a name out for vote tapped the row and got nothing.

Rather than restore the old screen, which displayed a real voting deadline
beside three fields that never populated (`currentUsernameRequest` was always
nil) and a "Cancel Request" button that cancelled nothing,
`UsernameRequestStatusScreen` shows what the new service can actually answer:
the deadline, plus the live contest — every contender with their tally, our own
row marked "You", who is currently leading, and the lock/abstain counts. The
status line distinguishes voting-in-progress, you-are-ahead, lock-is-ahead,
won, went-to-someone-else, locked, and not-yet-indexed. This is the
user-facing contest view `DWContestedNameStatusService` documents as future
work.

"Cancel Request" is deliberately not reimplemented: a submitted contested DPNS
name cannot be withdrawn on Platform, and clearing the local bookmark would
only make the app lose track of a live contest.

**Bulk voting, replacing "Quick Voting".** The old screen offered "Vote for
All" across filtered usernames. Multi-select now lives on the contest list
(overflow menu → "Vote on several"), with a bottom bar showing the count and
the combined weight, and a sheet that applies one choice with the chosen nodes.
`MasternodeVoteCaster.castBulk` authenticates once for the whole run and
reports per contest; a contest that closed since the list was fetched comes
back as a failed row instead of aborting the batch.

Only Abstain and Lock are offered in bulk. Approving names a specific
contender, and the legacy "whoever submitted first" rule is not reproducible:
contender submission time lives inside the serialized `domain` document that
the FFI returns as opaque hex. Guessing an order would be worse than scoping
the bulk action to the two choices that generalize honestly.

Verified: the remaining deletions really were unreachable —
`IconAttributedText` had no referent outside the deleted storyboard, and
`requestedUsernameId` is never assigned anywhere at the merge base.

Co-Authored-By: Claude Opus 5 <[email protected]>

@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: 5

🧹 Nitpick comments (2)
DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift (1)

165-168: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

shortIdentity is duplicated.

The same truncation logic exists in ContestantStatusRow.shortIdentity in DashWallet/Sources/UI/DashPay/Usernames/UsernameRequestStatusScreen.swift at lines 259-262. Extract one helper, for example an extension on DPNSContender or a shared formatting function, and use it in both rows.

🤖 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 `@DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift` around lines
165 - 168, The shortIdentity truncation logic is duplicated between the current
row and ContestantStatusRow.shortIdentity. Extract the shared formatting into
one reusable DPNSContender extension or formatting helper, then update both
shortIdentity properties to use it while preserving the existing 16-character
threshold and prefix/suffix output.
DashWallet/Sources/UI/DashPay/Voting/BulkVoteSheet.swift (1)

102-104: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Replace NavigationView with NavigationStack. The project targets iOS 17.0 or later, and NavigationView is deprecated from iOS 16.

🤖 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 `@DashWallet/Sources/UI/DashPay/Voting/BulkVoteSheet.swift` around lines 102 -
104, Update the navigation container in the body property of BulkVoteSheet from
NavigationView to NavigationStack, preserving the existing Group content and
navigation behavior.
🤖 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
`@DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoteCaster.swift`:
- Around line 213-214: Update the voting log in MasternodeVoteCaster to avoid
String(describing: choice), which exposes the identity ID publicly. Add or reuse
a non-identifying VoteChoice descriptor such as logDescription that reports only
the choice kind, and use it in the logger call while keeping the existing node
and label logging unchanged.
- Around line 271-281: Update the contest-open check in the vote-casting loop
around contests.contestIsOpen to distinguish thrown query errors from a valid
false result. Report the underlying network/query failure with a retryable error
message when the check fails, and continue using CastError.contestClosed(label)
only when contestIsOpen successfully returns false.

In `@DashWallet/Sources/UI/DashPay/Usernames/UsernameRequestStatusScreen.swift`:
- Around line 88-93: Update the guard handling
ContestedNamesService.normalizedLabel(for:) in UsernameRequestStatusScreen so
its nil result does not always report a connectivity/syncing error. Distinguish
the missing-SDK case from normalization failure, either by exposing separate
service outcomes or by using a distinct user-facing message for labels that
cannot be normalized.

In `@DashWallet/Sources/UI/DashPay/Voting/UsernameVotingScreen.swift`:
- Around line 180-199: Add pluralization rules in the localization strings
dictionary for every count-based key used by the voting UI, while preserving the
existing format specifiers. In UsernameVotingScreen.swift (lines 180-199), cover
“%d evonodes”, “%d masternodes”, “%u votes per contest — evonodes count as 4,
masternodes as 1”, plus the “%d requests” and “%u votes” strings near lines 218
and 228; in BulkVoteSheet.swift (lines 36-43), cover “%d selected”, “%u votes in
total”, “%u votes”, “Vote on %d usernames”, and “%d of %d usernames voted on”
near lines 184, 204, and 241.

In `@DashWallet/Sources/UI/Menu/Tools/Masternode`
Keys/Overview/Model/WalletKeysOverviewModel.swift:
- Around line 162-173: The indexByAddress flow must not derive a complete match
from the derivation wallet’s five-entry fallback pool. Require a complete live
pool before iterating highestAddressIndex, or return an explicit incomplete
result when it is unavailable, and ensure votableNodes() does not silently
undercount deeper voting indexes.

---

Nitpick comments:
In `@DashWallet/Sources/UI/DashPay/Voting/BulkVoteSheet.swift`:
- Around line 102-104: Update the navigation container in the body property of
BulkVoteSheet from NavigationView to NavigationStack, preserving the existing
Group content and navigation behavior.

In `@DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift`:
- Around line 165-168: The shortIdentity truncation logic is duplicated between
the current row and ContestantStatusRow.shortIdentity. Extract the shared
formatting into one reusable DPNSContender extension or formatting helper, then
update both shortIdentity properties to use it while preserving the existing
16-character threshold and prefix/suffix output.
🪄 Autofix

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 Plus

Run ID: 8f85c942-d9de-4532-abd3-3c66edb58219

📥 Commits

Reviewing files that changed from the base of the PR and between 2908795 and aeff28d.

📒 Files selected for processing (12)
  • DashWallet.xcodeproj/project.pbxproj
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/ContestedNamesService.swift
  • DashWallet/Sources/Infrastructure/SwiftDashSDK/Voting/MasternodeVoteCaster.swift
  • DashWallet/Sources/UI/DashPay/Usernames/UsernameRequestStatusScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/BulkVoteSheet.swift
  • DashWallet/Sources/UI/DashPay/Voting/CastVoteSheet.swift
  • DashWallet/Sources/UI/DashPay/Voting/ContestDetailScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/UsernameVotingScreen.swift
  • DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift
  • DashWallet/Sources/UI/Menu/Main/MainMenuViewController.swift
  • DashWallet/Sources/UI/Menu/Tools/Masternode Keys/Overview/Model/WalletKeysOverviewModel.swift
  • DashWallet/en.lproj/Localizable.strings
🚧 Files skipped from review as they are similar to previous changes (3)
  • DashWallet/Sources/UI/DashPay/Voting/CastVoteSheet.swift
  • DashWallet/en.lproj/Localizable.strings
  • DashWallet/Sources/UI/DashPay/Voting/VotingViewModel.swift

**Never log a contender identity id.** The cast log line interpolated
`String(describing: choice)` at `.public`, which expands `.towards` to include
the base58 identity — writing a specific voter node's choice of candidate into
the device log in clear text. `VoteChoice.logDescription` emits the kind only.

**A failed open-check no longer reads as "closed".** `castBulk` mapped any
thrown `contestIsOpen` error to `false` via `try?`, so a network blip told the
user "voting has already closed" for a live contest. The two are now
distinguished, same as `refreshContest` already does.

**A degraded key pool no longer silently undercounts voting power.**
`MasternodeProviderKeyDeriver` falls back to the derivation wallet's pool when
the live one can't be read, and that pool is only gap-limit deep. Enumerating
it — which the owner/voting address join does — can therefore miss a masternode
whose voting key sits at a deeper index, so `votableNodes()` could omit a node
the user can really vote with, with no explanation. The deriver now exposes
`poolIsLive`, `MasternodeKeyUsage.resolveAddressIndexes` passes it through, and
the registry returns a `Resolution` flagging the case where the pool was
degraded *and* an active registration went unmatched. The voting header shows a
caution when that happens instead of presenting a short list as the full
picture.

**Normalization failure is no longer reported as a connectivity problem.**
`normalizedLabel(for:)` returned `nil` both when the SDK was absent and when
Rust refused the label; the status screen called both "Platform is not
connected yet — wait for syncing". `requireNormalizedLabel` throws the two
cases separately.

**Plurals.** Every count string in the voting flow was a fixed English phrase,
so any count of 1 rendered "1 evonodes" / "1 votes" / "Vote on 1 usernames".
Added `en.lproj/Localizable.stringsdict` rules for all 12, including the three
two-number strings via positional specifiers, and removed the now-superseded
entries from `Localizable.strings` so the two files cannot disagree.

Also: extracted the duplicated identity truncation into
`DPNSContender.shortIdentityId`, shared by the contest-detail and
request-status rows; and renamed a local `masternodes` binding to
`regularNodes` so this PR does not add a new SwiftLint `inclusive_language`
warning.

Co-Authored-By: Claude Opus 5 <[email protected]>
@QuantumExplorer
QuantumExplorer merged commit 86301f0 into develop Aug 7, 2026
1 check passed
QuantumExplorer added a commit that referenced this pull request Aug 7, 2026
develop does not compile: #923 and #924 collided after both merged
green independently.

#923 replaced UsernameVotingViewController with the SwiftUI
UsernameVotingScreen and updated the showVoting() that lived in
MainMenuViewController when that PR was written. #924 had since moved
the Voting entry point into GovernanceMenuScreen, which #923 never saw.

On the merged tip the live entry point (Governance) still called the
deleted controller — a hard build error — while the updated copy in
MainMenuViewController was orphaned, since #924 removed its caller.

Points Governance at UsernameVotingScreen (exactly what #923 wrote, in
the location that is actually reachable) and deletes the dead copy.

Co-authored-by: Claude Fable 5 <[email protected]>
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