Feature to format bitcoin addresses in 4 character chunks (#17)
Some checks failed
Xcode - Build and Analyze / Build and analyse default scheme using xcodebuild command (push) Has been cancelled
Xcode - Unit Tests / Run unit tests using xcodebuild (push) Has been cancelled
SwiftFormat Check / Check code formatting with SwiftFormat (push) Has been cancelled

* format bitcoin addresses in 4 character chunks for increased readability

* add formating to verify wallet screen
This commit is contained in:
Nick Klockenga 2026-04-06 22:44:31 -04:00 committed by GitHub
parent 55404bd848
commit 50f870faa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 32 additions and 28 deletions

View File

@ -1,4 +1,5 @@
import Foundation
import SwiftUI
// MARK: - Denomination
@ -57,6 +58,29 @@ extension String {
guard count > leading + trailing + 3 else { return self }
return "\(prefix(leading))...\(suffix(trailing))"
}
/// Build a styled Text view with space-separated 4-character chunks,
/// alternating between primary and secondary text colors.
func chunkedAddressText(font: Font = .hbMono(13)) -> Text {
var chunks: [String] = []
var current = ""
for (i, char) in enumerated() {
if i > 0, i % 4 == 0 {
chunks.append(current)
current = ""
}
current.append(char)
}
if !current.isEmpty { chunks.append(current) }
var result = Text("")
for (i, chunk) in chunks.enumerated() {
if i > 0 { result = result + Text(" ") }
let color: Color = i % 2 == 0 ? .hbTextPrimary : .hbTextSecondary
result = result + Text(chunk).font(font).foregroundColor(color)
}
return result
}
}
extension Date {

View File

@ -26,9 +26,7 @@ struct AddressDetailView: View {
.font(.hbLabel())
.foregroundStyle(Color.hbTextSecondary)
Text(address)
.font(.hbMono(13))
.foregroundStyle(Color.hbTextPrimary)
address.chunkedAddressText()
.multilineTextAlignment(.center)
.padding(.horizontal, 32)
.textSelection(.enabled)

View File

@ -37,9 +37,7 @@ struct ReceiveView: View {
.font(.hbLabel())
.foregroundStyle(Color.hbTextSecondary)
Text(viewModel.currentAddress)
.font(.hbMono(13))
.foregroundStyle(Color.hbTextPrimary)
viewModel.currentAddress.chunkedAddressText()
.multilineTextAlignment(.center)
.padding(.horizontal, 32)
.textSelection(.enabled)

View File

@ -338,17 +338,11 @@ private struct PSBTReviewCard: View {
ForEach(Array(viewModel.recipients.enumerated()), id: \.element.id) { index, recipient in
if viewModel.recipients.count > 1 {
ReviewItem(label: "Recipient \(index + 1)") {
Text(recipient.address)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
.lineLimit(2)
recipient.address.chunkedAddressText(font: .hbMono(12))
}
} else {
ReviewItem(label: "To") {
Text(recipient.address)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
.lineLimit(2)
recipient.address.chunkedAddressText(font: .hbMono(12))
}
}

View File

@ -24,17 +24,11 @@ struct SendReviewView: View {
ForEach(Array(viewModel.recipients.enumerated()), id: \.element.id) { index, recipient in
if viewModel.recipients.count > 1 {
ReviewItem(label: "Recipient \(index + 1)") {
Text(recipient.address)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
.lineLimit(2)
recipient.address.chunkedAddressText(font: .hbMono(12))
}
} else {
ReviewItem(label: "To") {
Text(recipient.address)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
.lineLimit(2)
recipient.address.chunkedAddressText(font: .hbMono(12))
}
}

View File

@ -110,9 +110,7 @@ struct UTXODetailView: View {
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
} else {
Text(address)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
address.chunkedAddressText(font: .hbMono(12))
.textSelection(.enabled)
}
}

View File

@ -162,9 +162,7 @@ struct WalletVerifyView: View {
.clipShape(RoundedRectangle(cornerRadius: 8))
.frame(maxWidth: .infinity)
Text(viewModel.firstReceiveAddress)
.font(.hbMono(12))
.foregroundStyle(Color.hbTextPrimary)
viewModel.firstReceiveAddress.chunkedAddressText(font: .hbMono(12))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.textSelection(.enabled)