Commit c7d0024989

c7d00249893589fdc69bfe9d7f76b76f67088996

parent: 258cdf51cd

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-23 04:51 UTC

Map history and subdomain lookups through one result helper

Layout: unified · split

DomainDig/DomainViewModel.swift +15 −33
@@ -1298,17 +1298,7 @@ final class DomainViewModel {
1298 historyEntries: history 1298 historyEntries: history
1299 ) 1299 )
1300 1300
1301 switch outcome.value { 1301 (ownershipHistory, ownershipHistoryError) = found(outcome.value, fallback: "Ownership history unavailable")
1302 case let .success(events):
1303 ownershipHistory = events
1304 ownershipHistoryError = nil
1305 case let .empty(message):
1306 ownershipHistory = []
1307 ownershipHistoryError = message
1308 case let .error(message):
1309 ownershipHistory = []
1310 ownershipHistoryError = conciseExternalMessage(message, fallback: "Ownership history unavailable")
1311 }
1312 1302
1313 ownershipHistoryLoading = false 1303 ownershipHistoryLoading = false
1314 _ = saveHistoryEntry(replaceLatest: true) 1304 _ = saveHistoryEntry(replaceLatest: true)
@@ -1331,17 +1321,7 @@ final class DomainViewModel {
1331 historyEntries: history 1321 historyEntries: history
1332 ) 1322 )
1333 1323
1334 switch outcome.value { 1324 (dnsHistory, dnsHistoryError) = found(outcome.value, fallback: "DNS history unavailable")
1335 case let .success(events):
1336 dnsHistory = events
1337 dnsHistoryError = nil
1338 case let .empty(message):
1339 dnsHistory = []
1340 dnsHistoryError = message
1341 case let .error(message):
1342 dnsHistory = []
1343 dnsHistoryError = conciseExternalMessage(message, fallback: "DNS history unavailable")
1344 }
1345 1325
1346 dnsHistoryLoading = false 1326 dnsHistoryLoading = false
1347 _ = saveHistoryEntry(replaceLatest: true) 1327 _ = saveHistoryEntry(replaceLatest: true)
@@ -1363,22 +1343,24 @@ final class DomainViewModel {
1363 existing: subdomains 1343 existing: subdomains
1364 ) 1344 )
1365 1345
1366 switch outcome.value { 1346 (extendedSubdomains, extendedSubdomainsError) = found(outcome.value, fallback: "Extended subdomains unavailable")
1367 case let .success(results):
1368 extendedSubdomains = results
1369 extendedSubdomainsError = nil
1370 case let .empty(message):
1371 extendedSubdomains = []
1372 extendedSubdomainsError = message
1373 case let .error(message):
1374 extendedSubdomains = []
1375 extendedSubdomainsError = conciseExternalMessage(message, fallback: "Extended subdomains unavailable")
1376 }
1377 1347
1378 extendedSubdomainsLoading = false 1348 extendedSubdomainsLoading = false
1379 _ = saveHistoryEntry(replaceLatest: true) 1349 _ = saveHistoryEntry(replaceLatest: true)
1380 } 1350 }
1381 1351
1352 /// What a lookup found, and the message to show when it found nothing or failed.
1353 private func found<Item>(_ result: ServiceResult<[Item]>, fallback: String) -> ([Item], String?) {
1354 switch result {
1355 case let .success(items):
1356 return (items, nil)
1357 case let .empty(message):
1358 return ([], message)
1359 case let .error(message):
1360 return ([], conciseExternalMessage(message, fallback: fallback))
1361 }
1362 }
1363
1382 func refreshUsageCredits() async { 1364 func refreshUsageCredits() async {
1383 let statuses = await UsageCreditService.shared.allStatuses() 1365 let statuses = await UsageCreditService.shared.allStatuses()
1384 usageCredits = Dictionary(uniqueKeysWithValues: statuses.map { ($0.feature, $0) }) 1366 usageCredits = Dictionary(uniqueKeysWithValues: statuses.map { ($0.feature, $0) })