Skip to content
Closed
Show file tree
Hide file tree
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 @@ -10,21 +10,6 @@ public struct TransitionDefinitions {
label: "Identity Create",
description: "Create a new identity with initial credits",
inputs: [
TransitionInput(
name: "seedPhrase",
type: "textarea",
label: "Seed Phrase",
required: true,
placeholder: "Enter seed phrase (12-24 words) or click Generate",
help: "The wallet seed phrase that will be used to derive identity keys"
),
TransitionInput(
name: "generateSeedButton",
type: "button",
label: "Generate New Seed",
required: false,
action: "generateTestSeed"
),
TransitionInput(
name: "identityIndex",
type: "number",
Expand Down
146 changes: 0 additions & 146 deletions packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,150 +253,4 @@ class AppState: ObservableObject {
return nil
}
}

// MARK: - Startup Diagnostics

@MainActor
private func runStartupDiagnostics(sdk: SDK) async {
NSLog("====== PLATFORM QUERY DIAGNOSTICS (STARTUP) ======")

// Test data based on WASM SDK examples
struct TestData {
static let testIdentityId = "6ZhrNvhzD7Qm1nJhWzvipH9cPRLqBamdnXnKjnrrKA2c"
static let testIdentityId2 = "HqyuZoKnHRdKP88Tz5L37whXHa27RuLRoQHzGgJGvCdU"
static let dpnsContractId = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"
static let testPublicKeyHash = "b7e904ce25ed97594e72f7af0e66f298031c1754"
static let testNonUniquePublicKeyHash = "518038dc858461bcee90478fd994bba8057b7531"
static let testDocumentType = "domain"
static let testUsername = "dash"
static let testTokenId = "Hqyu8WcRwXCTwbNxdga4CN5gsVEGc67wng4TFzceyLUv"
static let testContractId = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"
static let testDocumentId = "4EfA9Jrvv3nnCFdSf7fad59851iiTRZ6Wcu6YVJ4iSeF"
}

// Run a few key queries to test connectivity
let diagnosticQueries: [(name: String, test: @MainActor () async throws -> Any)] = [
("Get Platform Status", {
try await sdk.getStatus()
}),

("Get Total Credits", {
try await sdk.getTotalCreditsInPlatform()
}),

("Get Identity", {
try await sdk.identityGet(identityId: TestData.testIdentityId)
}),

("Get DPNS Contract", {
try await sdk.dataContractGet(id: TestData.dpnsContractId)
}),

("DPNS Check Availability", {
try await sdk.dpnsCheckAvailability(name: "test-name-\(Int.random(in: 1000...9999))")
})
]

var successCount = 0
var failureCount = 0

for query in diagnosticQueries {
NSLog("\n🔍 Testing: \(query.name)")

do {
let startTime = Date()
let result = try await query.test()
let duration = Date().timeIntervalSince(startTime)

successCount += 1
NSLog("✅ Success (\(String(format: "%.3fs", duration)))")

// Print a summary of the result
if let dict = result as? [String: Any] {
if let version = dict["version"] as? String {
NSLog(" Platform version: \(version)")
} else if let id = dict["id"] as? String {
NSLog(" ID: \(id)")
} else if let balance = dict["balance"] as? UInt64 {
NSLog(" Balance: \(balance)")
} else {
NSLog(" Result: \(dict.keys.prefix(3).joined(separator: ", "))...")
}
} else if let uint = result as? UInt64 {
NSLog(" Value: \(uint)")
} else if let bool = result as? Bool {
NSLog(" Available: \(bool)")
}

} catch {
failureCount += 1
NSLog("❌ Failed: \(error.localizedDescription)")
}
}

NSLog("\n====== DIAGNOSTIC SUMMARY ======")
NSLog("Total queries: \(diagnosticQueries.count)")
NSLog("Successful: \(successCount)")
NSLog("Failed: \(failureCount)")
NSLog("Success rate: \(String(format: "%.0f%%", Double(successCount) / Double(diagnosticQueries.count) * 100))")
NSLog("================================\n")
}

@MainActor
private func runSimpleDiagnostic(sdk: SDK) async {
var diagnosticReport = "====== SIMPLE DIAGNOSTIC TEST ======\n"
diagnosticReport += "Date: \(Date())\n\n"

// Test 1: Get Platform Status
do {
diagnosticReport += "Testing: Get Platform Status...\n"
let status = try await sdk.getStatus()
diagnosticReport += "✅ Platform Status Success\n"
let dict = status
diagnosticReport += " Version: \(dict["version"] ?? "unknown")\n"
diagnosticReport += " Mode: \(dict["mode"] ?? "unknown")\n"
diagnosticReport += " QuorumCount: \(dict["quorumCount"] ?? "unknown")\n"
} catch {
diagnosticReport += "❌ Platform Status Failed: \(error)\n"
}

diagnosticReport += "\n"

// Test 2: Get Total Credits
do {
diagnosticReport += "Testing: Get Total Credits...\n"
let credits = try await sdk.getTotalCreditsInPlatform()
diagnosticReport += "✅ Total Credits Success: \(credits)\n"
} catch {
diagnosticReport += "❌ Total Credits Failed: \(error)\n"
}

diagnosticReport += "\n"

// Test 3: Check DPNS availability
do {
diagnosticReport += "Testing: DPNS Check Availability...\n"
let name = "test-diagnostic-\(Int.random(in: 1000...9999))"
let available = try await sdk.dpnsCheckAvailability(name: name)
diagnosticReport += "✅ DPNS Check Success: name '\(name)' available = \(available)\n"
} catch {
diagnosticReport += "❌ DPNS Check Failed: \(error)\n"
}

diagnosticReport += "\n====== DIAGNOSTIC COMPLETE ======\n"

// Write to documents directory
if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
let diagnosticPath = documentsPath.appendingPathComponent("diagnostic_report.txt")
do {
try diagnosticReport.write(to: diagnosticPath, atomically: true, encoding: .utf8)
NSLog("Diagnostic report written to: \(diagnosticPath)")
} catch {
NSLog("Failed to write diagnostic report: \(error)")
}
}

// Also log to console
NSLog(diagnosticReport)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ struct AccountDetailView: View {
@Query private var allMasternodes: [PersistentMasternode]

@State private var errorMessage: String?
@State private var copiedText: String?
@State private var showingPrivateKey: String?
@State private var privateKeyToShow: (hex: String, wif: String)?
@State private var showingPINPrompt = false
@State private var pinInput = ""

// MARK: Provider derived-keys state
/// The #0..#19 keys derived from a provider account's extended
Expand Down Expand Up @@ -166,18 +161,6 @@ struct AccountDetailView: View {
.sheet(item: $selectedTransaction) { transaction in
TransactionDetailView(transaction: transaction)
}
.sheet(isPresented: $showingPINPrompt) {
PINPromptView(
pinInput: $pinInput,
isPresented: $showingPINPrompt,
onSubmit: {
Task {
await derivePrivateKeyWithPIN()
pinInput = ""
}
}
)
}
.onAppear { appUIState.showWalletsSyncDetails = false }
}

Expand Down Expand Up @@ -1153,59 +1136,4 @@ struct AccountDetailView: View {
}
return String(format: "%.8f DASH", dash)
}

private func derivePrivateKeyWithPIN() async {
// TODO(platform-wallet): needs new FFI for WIF derivation via
// PlatformWalletManager. For now, surface a stubbed error.
await MainActor.run {
errorMessage = "Private key derivation is not yet available through the new PlatformWalletManager."
}
}
}

// MARK: - PIN Prompt View

struct PINPromptView: View {
@Binding var pinInput: String
@Binding var isPresented: Bool
let onSubmit: () -> Void

var body: some View {
NavigationView {
VStack(spacing: 20) {
Text("Enter Wallet PIN")
.font(.title2)
.fontWeight(.semibold)

Text("Your PIN is required to access private keys")
.font(.subheadline)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)

SecureField("PIN", text: $pinInput)
.textFieldStyle(.roundedBorder)
.keyboardType(.numberPad)
.padding(.horizontal)

HStack(spacing: 20) {
Button("Cancel") {
pinInput = ""
isPresented = false
}
.buttonStyle(.bordered)

Button("Unlock") {
onSubmit()
isPresented = false
}
.buttonStyle(.borderedProminent)
.disabled(pinInput.isEmpty)
}

Spacer()
}
.padding()
.navigationBarHidden(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -969,84 +969,6 @@ struct CompactSyncRow: View {
}
}

// MARK: - Sync Progress Row (Legacy)

struct SyncProgressRow: View {
let title: String
let progress: Double
let detail: String
let icon: String
let trailingValue: String?
let onRestart: () -> Void
var navigationDestination: AnyView? = nil

// Ensure progress is always between 0 and 1
private var safeProgress: Double {
min(max(progress, 0.0), 1.0)
}

var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
// Make only the label tappable if there's a navigation destination
if let destination = navigationDestination {
NavigationLink(destination: destination) {
HStack(spacing: 6) {
Image(systemName: icon)
.font(.subheadline)
Text(title)
.font(.subheadline)
.fontWeight(.semibold)
}
.foregroundColor(.blue)
}
.buttonStyle(PlainButtonStyle())
} else {
Label(title, systemImage: icon)
.font(.subheadline)
.foregroundColor(.primary)
}

Spacer()

if let trailingValue = trailingValue {
Text(trailingValue)
.font(.caption)
.foregroundColor(.secondary)
}

Button(action: onRestart) {
Image(systemName: "arrow.clockwise")
.font(.caption)
.foregroundColor(.blue)
}
.buttonStyle(BorderlessButtonStyle())
}

VStack(alignment: .leading, spacing: 4) {
ProgressView(value: safeProgress)
.progressViewStyle(LinearProgressViewStyle())
.tint(progressColor(for: safeProgress))

Text(detail)
.font(.caption2)
.foregroundColor(.secondary)
}
}
.padding(.vertical, 4)
}

private func progressColor(for value: Double) -> Color {
if value >= 1.0 {
return .green
} else if value >= 0.5 {
return .blue
} else {
return .orange
}
}
}

// MARK: - Wallet Row View

struct WalletRowView: View {
Expand Down Expand Up @@ -1377,7 +1299,6 @@ private struct QueryCountBadge: View {
struct ProofDetailView: View {
let proofData: Data
@State private var formattedProof: String = "Decoding..."
@State private var copiedText: String?

private var proofHex: String {
proofData.map { String(format: "%02x", $0) }.joined()
Expand Down
Loading
Loading