Skip to content
Open
Changes from 3 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 @@ -146,10 +146,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 @@ -892,8 +888,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 @@ -990,7 +986,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 @@ -1014,7 +1010,6 @@ struct CreateIdentityView: View {
identityIndex: identityIndex
)
try modelContext.save()
self.createdIdentityId = identityId
} catch {
self.submitError = .init(
message: error.localizedDescription
Expand Down Expand Up @@ -1269,21 +1264,25 @@ 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 truncated = (dash * 10_000).rounded(.down) / 10_000
Comment thread
llbartekll marked this conversation as resolved.
Outdated
var s = String(format: "%.4f", 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