Skip to content
Open
Changes from 2 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 @@ -1273,19 +1268,46 @@ struct CreateIdentityView: View {
case 14:
let balance = accountBalance(account)
if balance == 0 { return "" }
let dash = Double(balance) / Double(Self.creditsPerDash)
return String(format: "%g", dash)
return Self.amountString(
smallestUnits: balance,
decimalsPerWhole: 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)
return Self.amountString(
smallestUnits: defaultDuffs,
decimalsPerWhole: Self.duffsPerDash
)
default:
return ""
}
}

private static func amountString(
smallestUnits: UInt64,
decimalsPerWhole: UInt64
) -> String {
let whole = smallestUnits / decimalsPerWhole
let fractional = smallestUnits % decimalsPerWhole
if fractional == 0 {
return "\(whole)"
}
let decimalPlaces = String(decimalsPerWhole).count - 1
var fractionalStr = String(fractional)
if fractionalStr.count < decimalPlaces {
fractionalStr = String(
repeating: "0",
count: decimalPlaces - fractionalStr.count
) + fractionalStr
}
while fractionalStr.last == "0" {
fractionalStr.removeLast()
}
return fractionalStr.isEmpty ? "\(whole)" : "\(whole).\(fractionalStr)"
}

/// Parse the amount text back into credits. Returns `nil` on
/// invalid / negative / overflow input.
private var parsedAmountCredits: UInt64? {
Expand Down
Loading