Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
61db06c
feat: port price widgets related screens to figma V61
jvsena42 May 6, 2026
28a550f
fix: spacing and alignment
jvsena42 May 6, 2026
10be29e
feat: hide menu button from nabigation bar
jvsena42 May 6, 2026
90680fe
fix: padding
jvsena42 May 6, 2026
4dfd9a8
fix: remove systemLarge widget option
jvsena42 May 6, 2026
15dc374
fix: collect results in input order instead of completion order
jvsena42 May 6, 2026
fc2aaa6
Merge remote-tracking branch 'origin/feat/os-widgets' into feat/price…
jvsena42 May 6, 2026
600b422
fix: pr comments
jvsena42 May 6, 2026
027da41
fix: pr comments
jvsena42 May 6, 2026
a172129
refactor: simplify doc
jvsena42 May 6, 2026
73eba60
refactor: replace onApper with task
jvsena42 May 6, 2026
d07317f
refactor: replace onChange with task id
jvsena42 May 6, 2026
8b2ec97
refactor: simplify comments
jvsena42 May 6, 2026
6586143
refactor: simplyfy comments
jvsena42 May 6, 2026
fc0dc8e
refactor: simplify comments
jvsena42 May 6, 2026
d01c196
refactor: simplify comments
jvsena42 May 6, 2026
770511e
refactor: simplify comments
jvsena42 May 6, 2026
5f0841f
refactor: remove multi-pair legacy code
jvsena42 May 6, 2026
51c2f41
fix: fallback to os widget options after remove in-app
jvsena42 May 6, 2026
afb421a
fix: make chart height adaptable
jvsena42 May 6, 2026
fdafc5b
Merge branch 'feat/os-widgets' into feat/price-widget-v61
jvsena42 May 6, 2026
5be6014
feat: set backgroud color Gray7
jvsena42 May 6, 2026
b0d05be
Merge branch 'feat/price-widget-v61' of github.com:synonymdev/bitkit-…
jvsena42 May 6, 2026
d60c84c
feat: migrate news widget to design v61 and port OS widget
jvsena42 May 7, 2026
ab5b8d5
fix: push source text to bottom
jvsena42 May 7, 2026
66f82ff
refactor: extract articles url to a shared files
jvsena42 May 7, 2026
78b4dcd
feat: open browser on widget click
jvsena42 May 7, 2026
12fe6e6
doc: changelog entry
jvsena42 May 7, 2026
667e544
fix: small and medium sizes displaying different random url
jvsena42 May 7, 2026
40b0ad7
chore: remove schedule file
jvsena42 May 7, 2026
2e3f81c
fix: replace onAppear with task
jvsena42 May 7, 2026
a25a221
fix: use stable dafe format identifier
jvsena42 May 7, 2026
c2e2bd3
feat: migrate blocks to v61 and implement OS widget
jvsena42 May 7, 2026
2469d3b
fix: use arrow-up-down for transfer icons
jvsena42 May 7, 2026
442ea60
fix: drop large OS widget support
jvsena42 May 7, 2026
22dc3e1
Merge branch 'feat/os-widgets' into feat/price-widget-v61
jvsena42 May 7, 2026
6e3ab90
fix: reuse existing text component and remove scale factor
jvsena42 May 7, 2026
b2df71f
fix: display white32 checkmark for unselected item
jvsena42 May 7, 2026
7994460
fix: vertical padding anchored to checkbox image
jvsena42 May 7, 2026
200d2f8
fix: remove the gray bg and custom bg from Navigation bar
jvsena42 May 7, 2026
870d5e8
fix: try to fetch real data for preview
jvsena42 May 7, 2026
d2f4120
refactor: make string keys generic to be reused in the furue implemen…
jvsena42 May 7, 2026
1c8350a
fix: make prevew frame height adaptable
jvsena42 May 7, 2026
779e215
fix: solve conflicts and apply downstream changes
jvsena42 May 7, 2026
ddfd42b
fix: display checkmark for title
jvsena42 May 7, 2026
88843b6
fix: remove app group fallback
jvsena42 May 7, 2026
955e293
Merge remote-tracking branch 'origin/feat/price-widget-v61' into feat…
jvsena42 May 7, 2026
d636551
Merge branch 'feat/headlines-v61' into feat/blocks-v61
jvsena42 May 7, 2026
a2e0e7b
WIP
pwltr May 15, 2026
0cd3101
Merge remote-tracking branch 'origin/feat/os-widgets' into feat/block…
pwltr May 15, 2026
f8f4f6f
fixes
pwltr May 15, 2026
90e68bc
fixes
pwltr May 15, 2026
33431a0
fixes
pwltr May 15, 2026
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
5 changes: 5 additions & 0 deletions Bitkit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"Extensions/LDKNode+AddressType.swift",
Extensions/PaymentDetails.swift,
Models/BlocktankNotificationType.swift,
Models/BlocksWidgetOptions.swift,
Models/LnPeer.swift,
Models/PubkyPublicKeyFormat.swift,
Models/Toast.swift,
Expand Down Expand Up @@ -173,10 +174,14 @@
Fonts/InterTight-Regular.ttf,
Constants/WidgetEnv.swift,
Fonts/InterTight-SemiBold.ttf,
Models/BlocksWidgetData.swift,
Models/BlocksWidgetFields.swift,
Models/BlocksWidgetOptions.swift,
Models/NewsWidgetData.swift,
Models/NewsWidgetOptions.swift,
Models/PriceWidgetData.swift,
Models/PriceWidgetOptions.swift,
Services/Widgets/BlocksHomeScreenWidgetOptionsStore.swift,
Services/Widgets/NewsHomeScreenWidgetOptionsStore.swift,
Services/Widgets/PriceHomeScreenWidgetOptionsStore.swift,
Styles/Colors.swift,
Expand Down
174 changes: 78 additions & 96 deletions Bitkit/Components/Widgets/BlocksWidget.swift
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import SwiftUI

/// Options for configuring the BlocksWidget
struct BlocksWidgetOptions: Codable, Equatable {
var height: Bool = true
var time: Bool = true
var date: Bool = true
var transactionCount: Bool = false
var size: Bool = false
var weight: Bool = false
var difficulty: Bool = false
var hash: Bool = false
var merkleRoot: Bool = false
var showSource: Bool = false
}
// MARK: - Widget

/// A widget that displays Bitcoin block information
/// In-app Bitcoin Blocks widget (v61). Renders the wide layout — used inside the home feed
/// and the wide carousel page on the preview screen.
struct BlocksWidget: View {
/// Configuration options for the widget
var options: BlocksWidgetOptions = .init()

/// Flag indicating if the widget is in editing mode
var isEditing: Bool = false

/// Callback to signal when editing should end
var onEditingEnd: (() -> Void)?

/// View model for handling block data
@StateObject private var viewModel = BlocksViewModel.shared

/// Initialize the widget
init(
options: BlocksWidgetOptions = BlocksWidgetOptions(),
isEditing: Bool = false,
Expand All @@ -39,96 +21,96 @@ struct BlocksWidget: View {
self.onEditingEnd = onEditingEnd
}

/// Mapping of block data keys to display labels
private let blocksMapping: [String: String] = [
"height": "Block",
"time": "Time",
"date": "Date",
"transactionCount": "Transactions",
"size": "Size",
"weight": "Weight",
"difficulty": "Difficulty",
"hash": "Hash",
"merkleRoot": "Merkle Root",
]

var body: some View {
BaseWidget(
type: .blocks,
isEditing: isEditing,
onEditingEnd: onEditingEnd
) {
VStack(spacing: 0) {
if viewModel.isLoading {
WidgetContentBuilder.loadingView()
} else if viewModel.error != nil {
WidgetContentBuilder.errorView(t("widgets__blocks__error"))
} else if let data = viewModel.blockData {
VStack(spacing: 0) {
// Display block data rows based on options
ForEach(getDisplayableData(data), id: \.key) { item in
HStack(spacing: 0) {
HStack {
BodySSBText(item.label, textColor: .textSecondary)
.lineLimit(1)
}
.frame(maxWidth: .infinity, alignment: .leading)

HStack {
BodyMSBText(item.value)
.lineLimit(1)
.truncationMode(.middle)
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
.frame(minHeight: 28)
}

if options.showSource {
WidgetContentBuilder.sourceRow(source: "mempool.space")
}
}
}
}
content
}
.onAppear {
.task {
viewModel.startUpdates()
}
}

/// Get displayable data based on current options
private func getDisplayableData(_ data: BlockData) -> [(key: String, label: String, value: String)] {
var items: [(key: String, label: String, value: String)] = []

if options.height {
items.append((key: "height", label: blocksMapping["height"]!, value: data.height))
}
if options.time {
items.append((key: "time", label: blocksMapping["time"]!, value: data.time))
}
if options.date {
items.append((key: "date", label: blocksMapping["date"]!, value: data.date))
@ViewBuilder
private var content: some View {
if viewModel.isLoading && viewModel.blockData == nil {
WidgetContentBuilder.loadingView()
} else if viewModel.error != nil && viewModel.blockData == nil {
WidgetContentBuilder.errorView(t("widgets__blocks__error"))
} else if let data = viewModel.blockData {
BlocksWidgetWideContent(data: data, options: options)
}
if options.transactionCount {
items.append((key: "transactionCount", label: blocksMapping["transactionCount"]!, value: data.transactionCount))
}
if options.size {
items.append((key: "size", label: blocksMapping["size"]!, value: data.size))
}
if options.weight {
items.append((key: "weight", label: blocksMapping["weight"]!, value: data.weight))
}
if options.difficulty {
items.append((key: "difficulty", label: blocksMapping["difficulty"]!, value: data.difficulty))
}
if options.hash {
items.append((key: "hash", label: blocksMapping["hash"]!, value: data.hash))
}
}

// MARK: - Wide layout (in-app + 343-wide carousel page + .systemMedium / .systemLarge OS widget)

struct BlocksWidgetWideContent: View {
let data: CachedBlock
let options: BlocksWidgetOptions

var body: some View {
VStack(alignment: .leading, spacing: 12) {
ForEach(options.enabledFields, id: \.self) { field in
BlocksWidgetWideRow(field: field, value: field.value(from: data))
}
}
if options.merkleRoot {
items.append((key: "merkleRoot", label: blocksMapping["merkleRoot"]!, value: data.merkleRoot))
.frame(maxWidth: .infinity, alignment: .leading)
}
}

private struct BlocksWidgetWideRow: View {
let field: BlocksWidgetField
let value: String

var body: some View {
HStack(alignment: .center, spacing: 8) {
Image(field.iconName)
.resizable()
.renderingMode(.template)
.foregroundColor(.brandAccent)
.frame(width: 20, height: 20)

BodyMText(field.label, textColor: .white80)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)

BodyMSBText(value)
.lineLimit(1)
.truncationMode(.middle)
}
}
}

// MARK: - Compact layout (small carousel preview + 163×192 OS small widget)

return items
struct BlocksWidgetCompactContent: View {
let data: CachedBlock
let options: BlocksWidgetOptions

var body: some View {
VStack(alignment: .leading, spacing: 16) {
ForEach(options.enabledFields, id: \.self) { field in
HStack(alignment: .center, spacing: 8) {
Image(field.iconName)
.resizable()
.renderingMode(.template)
.foregroundColor(.brandAccent)
.frame(width: 20, height: 20)

BodySSBText(field.value(from: data))
.lineLimit(1)
.truncationMode(.middle)
}
}
}
.padding(16)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.background(Color.gray6)
.cornerRadius(16)
}
}

Expand Down
2 changes: 2 additions & 0 deletions Bitkit/MainNavView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ struct MainNavView: View {
PriceWidgetPreviewView()
case .news:
NewsWidgetPreviewView()
case .blocks:
BlocksWidgetPreviewView()
default:
WidgetDetailView(id: widgetType)
}
Expand Down
43 changes: 43 additions & 0 deletions Bitkit/Models/BlocksWidgetData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Foundation

/// Persistable representation of the latest mined block, shared between the main app and the
/// widget extension via the App Group. Strings are pre-formatted by the main-app `BlocksService`
/// so the widget extension can render without re-running locale-sensitive formatting.
struct CachedBlock: Codable, Equatable {
let height: String
let time: String
let date: String
let transactionCount: String
let size: String
let fees: String
}

/// Cache reader/writer used by both the main app and the widget extension.
enum BlocksWidgetCache {
static let appGroupSuiteName = "group.bitkit"
private static let latestKey = "blocks_widget_latest_v1"
private static let legacyStandardKey = "blocks_widget_cache"

private static func defaults() -> UserDefaults {
UserDefaults(suiteName: appGroupSuiteName) ?? .standard
}

static func saveLatest(_ block: CachedBlock) {
guard let encoded = try? JSONEncoder().encode(block) else { return }
defaults().set(encoded, forKey: latestKey)
}

static func loadLatest() -> CachedBlock? {
guard let data = defaults().data(forKey: latestKey),
let decoded = try? JSONDecoder().decode(CachedBlock.self, from: data)
else {
return nil
}
return decoded
}

/// One-time cleanup of the pre-App-Group cache that lived in `UserDefaults.standard`.
static func legacyDropStandardSuiteCache() {
UserDefaults.standard.removeObject(forKey: legacyStandardKey)
}
}
67 changes: 67 additions & 0 deletions Bitkit/Models/BlocksWidgetFields.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import Foundation

/// Ordered field set used by the v61 Blocks widget.
///
/// Shared between the main app and the WidgetKit extension via the App Group target membership.
/// Labels are intentionally hardcoded English to avoid reaching into the main app's
/// `LocalizeHelpers` from the widget extension.
enum BlocksWidgetField: String, CaseIterable {
case height
case time
case date
case transactionCount
case size
case fees

var label: String {
switch self {
case .height: return "Block"
case .time: return "Time"
case .date: return "Date"
case .transactionCount: return "Transactions"
case .size: return "Size"
case .fees: return "Fees"
}
}

/// Asset name for the brand-orange icon used in both the wide and compact layouts.
var iconName: String {
switch self {
case .height: return "cube"
case .time: return "clock"
case .date: return "calendar"
case .transactionCount: return "arrow-up-down"
case .size: return "file-text"
case .fees: return "coins"
}
}

func isEnabled(in options: BlocksWidgetOptions) -> Bool {
switch self {
case .height: return options.height
case .time: return options.time
case .date: return options.date
case .transactionCount: return options.transactionCount
case .size: return options.size
case .fees: return options.fees
}
}

func value(from data: CachedBlock) -> String {
switch self {
case .height: return data.height
case .time: return data.time
case .date: return data.date
case .transactionCount: return data.transactionCount
case .size: return data.size
case .fees: return data.fees
}
}
}

extension BlocksWidgetOptions {
/// All enabled fields in declared order.
var enabledFields: [BlocksWidgetField] {
BlocksWidgetField.allCases.filter { $0.isEnabled(in: self) }
}
}
Loading
Loading