From 2f4f1a49a869ebd19c08718ade319ffdf59e6da1 Mon Sep 17 00:00:00 2001 From: Matthew Ramsden <6657488+reez@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:01:36 -0500 Subject: [PATCH] chore: refactor previews and utilities --- Sources/BitcoinUI/AddressFormattedView.swift | 22 ++---- Sources/BitcoinUI/ButtonStyles.swift | 11 ++- Sources/BitcoinUI/Colors.swift | 12 ++- Sources/BitcoinUI/Images.swift | 11 ++- Sources/BitcoinUI/SeedPhraseView.swift | 83 +++----------------- Sources/BitcoinUI/TextStyles.swift | 11 ++- Sources/BitcoinUI/Utilities.swift | 18 +++++ 7 files changed, 57 insertions(+), 111 deletions(-) diff --git a/Sources/BitcoinUI/AddressFormattedView.swift b/Sources/BitcoinUI/AddressFormattedView.swift index cc1d035..fad6262 100644 --- a/Sources/BitcoinUI/AddressFormattedView.swift +++ b/Sources/BitcoinUI/AddressFormattedView.swift @@ -36,7 +36,7 @@ public struct AddressFormattedView: View { ), spacing: spacing ) { - let chunks = chunkedAddress() + let chunks = address.chunked(into: 4) ForEach(chunks.indices, id: \.self) { index in Text(chunks[index]) .font(.system(size: 20, weight: .medium, design: .monospaced)) @@ -46,27 +46,17 @@ public struct AddressFormattedView: View { } } -extension AddressFormattedView { - private func chunkedAddress() -> [String] { - let chunkSize = 4 - return stride(from: 0, to: address.count, by: chunkSize).map { - let start = address.index(address.startIndex, offsetBy: $0) - let end = - address.index(start, offsetBy: chunkSize, limitedBy: address.endIndex) - ?? address.endIndex - return String(address[start.. [[Element]] { - stride(from: 0, to: count, by: size).map { - Array(self[$0.. [[Element]] { + stride(from: 0, to: count, by: size).map { + Array(self[$0.. [String] { + return stride(from: 0, to: self.count, by: size).map { + let start = self.index(self.startIndex, offsetBy: $0) + let end = self.index(start, offsetBy: size, limitedBy: self.endIndex) ?? self.endIndex + return String(self[start..) -> some View { self