Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ struct CreateIdentityView: View {
/// processing fee is deducted.
private static let defaultCoreFundingDuffs: UInt64 = 250_000

/// Decimal places the amount prefill is truncated to. Capping
/// the prefilled value at `floor(balance, 0.0001 DASH)` keeps
/// the parsed-back credits at or below the actual balance so
/// `canSubmit` doesn't trip on a `%g`-style rounding overflow.
private static let prefillDecimalPlaces: Int = 4

/// All locally-persisted wallets. Drives the Source Wallet
/// picker along with the synthetic "no wallet" sentinel.
@Query(sort: \PersistentWallet.createdAt) private var wallets: [PersistentWallet]
Expand Down Expand Up @@ -225,10 +231,6 @@ struct CreateIdentityView: View {
/// User-facing error surfaced via the `.alert` modifier.
@State private var submitError: SubmitError? = nil

/// Success payload. Populated after the identity is persisted;
/// the submit section swaps to a success banner and auto-dismiss.
@State private var createdIdentityId: Data? = nil

/// Active registration controller for the Core-funded path.
/// Stored only so `submitCoreFunded` has a local reference
/// after spawning it; the canonical lifetime owner is
Expand Down Expand Up @@ -1032,8 +1034,8 @@ struct CreateIdentityView: View {
identityIndex: identityIndex
)
try modelContext.save()
self.createdIdentityId = created.identityId
self.isCreating = false
dismiss()
}
} catch {
await MainActor.run {
Expand Down Expand Up @@ -1130,7 +1132,7 @@ struct CreateIdentityView: View {
}

/// Bridge a controller's phase transitions to this view's
/// `createdIdentityId` / `submitError` / `isCreating` state.
/// `submitError` / `isCreating` state.
/// The observer task auto-cancels when this view deallocates
/// (Swift task lifecycle on the captured `self`), but the
/// controller itself outlives the view.
Expand All @@ -1154,7 +1156,6 @@ struct CreateIdentityView: View {
identityIndex: identityIndex
)
try modelContext.save()
self.createdIdentityId = identityId
} catch {
self.submitError = .init(
message: error.localizedDescription
Expand Down Expand Up @@ -1515,21 +1516,26 @@ struct CreateIdentityView: View {
else {
return ""
}
let dash: Double
switch account.accountType {
case 14:
let balance = accountBalance(account)
if balance == 0 { return "" }
let dash = Double(balance) / Double(Self.creditsPerDash)
return String(format: "%g", dash)
dash = Double(balance) / Double(Self.creditsPerDash)
case 0, 1:
let available = coreAccountBalanceDuffs(account)
let defaultDuffs = min(available, Self.defaultCoreFundingDuffs)
if defaultDuffs == 0 { return "" }
let dash = Double(defaultDuffs) / Double(Self.duffsPerDash)
return String(format: "%g", dash)
dash = Double(defaultDuffs) / Double(Self.duffsPerDash)
default:
return ""
}
let scale = pow(10.0, Double(Self.prefillDecimalPlaces))
let truncated = (dash * scale).rounded(.down) / scale
var s = String(format: "%.\(Self.prefillDecimalPlaces)f", truncated)
while s.last == "0" { s.removeLast() }
if s.last == "." { s.removeLast() }
return s
Comment on lines +1533 to +1538

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: Sub-0.0001 DASH balances still collapse the prefill to an unparseable "0"

The truncation logic fixes the original rounding-up regression but introduces the same submit-button-disappears failure mode at the low end. When the selected Platform Payment balance is below 10_000_000 credits (0.0001 DASH), or the Core/CoinJoin default min(available, 250_000) is below 10_000 duffs, (dash * 10000).rounded(.down) is 0.0. String(format: "%.4f", 0.0) produces "0.0000"; the trailing-zero strip reduces it to "0.", then the trailing-dot strip leaves the literal "0". parsedAmountCredits / parsedAmountDuffs both require dash > 0, so they return nil, canSubmit is false, and the submit button silently disappears even though the account has spendable funds. The existing balance == 0 guard at the top of the switch should be mirrored after truncation so the field renders the placeholder ("") rather than an unparseable "0". The Core path is the more reachable case in practice because min(available, 250_000) caps the default into a range where this is hit easily.

Suggested change
let scale = pow(10.0, Double(Self.prefillDecimalPlaces))
let truncated = (dash * scale).rounded(.down) / scale
var s = String(format: "%.\(Self.prefillDecimalPlaces)f", truncated)
while s.last == "0" { s.removeLast() }
if s.last == "." { s.removeLast() }
return s
let scale = pow(10.0, Double(Self.prefillDecimalPlaces))
let truncated = (dash * scale).rounded(.down) / scale
if truncated <= 0 { return "" }
var s = String(format: "%.\(Self.prefillDecimalPlaces)f", truncated)
while s.last == "0" { s.removeLast() }
if s.last == "." { s.removeLast() }
return s

source: ['claude', 'codex']

}

/// Parse the amount text back into credits. Returns `nil` on
Expand Down
Loading