Skip to content

Commit dc057ad

Browse files
refactor: simplify home view
1 parent c9a4670 commit dc057ad

File tree

5 files changed

+153
-84
lines changed

5 files changed

+153
-84
lines changed

BDKSwiftExampleWallet.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
774586B52DB7B2BC00A631E1 /* BalanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 774586B42DB7B2BC00A631E1 /* BalanceView.swift */; };
1111
779E70872DB9C98A006E22D3 /* WalletSyncScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */; };
1212
779E70892DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */; };
13+
77AD9F062DBB031D00182E65 /* ActivityHomeHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AD9F052DBB031D00182E65 /* ActivityHomeHeaderView.swift */; };
1314
77F0FDC92DA9A93D00B30E4F /* Connection+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */; };
1415
A733D6D02A81113000F333B4 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = A733D6CF2A81113000F333B4 /* Localizable.xcstrings */; };
1516
A73F7A362A3B778E00B87FC6 /* Int+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A73F7A352A3B778E00B87FC6 /* Int+Extensions.swift */; };
@@ -114,6 +115,7 @@
114115
774586B42DB7B2BC00A631E1 /* BalanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BalanceView.swift; sourceTree = "<group>"; };
115116
779E70862DB9C98A006E22D3 /* WalletSyncScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSyncScriptInspector.swift; sourceTree = "<group>"; };
116117
779E70882DB9C9AB006E22D3 /* WalletFullScanScriptInspector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletFullScanScriptInspector.swift; sourceTree = "<group>"; };
118+
77AD9F052DBB031D00182E65 /* ActivityHomeHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityHomeHeaderView.swift; sourceTree = "<group>"; };
117119
77F0FDC82DA9A93700B30E4F /* Connection+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Connection+Extensions.swift"; sourceTree = "<group>"; };
118120
A733D6CF2A81113000F333B4 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
119121
A73F7A352A3B778E00B87FC6 /* Int+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+Extensions.swift"; sourceTree = "<group>"; };
@@ -235,6 +237,15 @@
235237
path = Actor;
236238
sourceTree = "<group>";
237239
};
240+
77AD9F072DBB0DBE00182E65 /* Home */ = {
241+
isa = PBXGroup;
242+
children = (
243+
774586B42DB7B2BC00A631E1 /* BalanceView.swift */,
244+
77AD9F052DBB031D00182E65 /* ActivityHomeHeaderView.swift */,
245+
);
246+
path = Home;
247+
sourceTree = "<group>";
248+
};
238249
A7FBCE392A72944C007C960E /* Resources */ = {
239250
isa = PBXGroup;
240251
children = (
@@ -283,7 +294,7 @@
283294
AE2381B92C61255100F6B00C /* Receive */,
284295
AE2381B82C61254B00F6B00C /* Send */,
285296
AE2381B72C61254200F6B00C /* Settings */,
286-
774586B42DB7B2BC00A631E1 /* BalanceView.swift */,
297+
77AD9F072DBB0DBE00182E65 /* Home */,
287298
);
288299
path = View;
289300
sourceTree = "<group>";
@@ -733,6 +744,7 @@
733744
AED4CC0C2A1D3A9400CE1831 /* OnboardingView.swift in Sources */,
734745
77F0FDC92DA9A93D00B30E4F /* Connection+Extensions.swift in Sources */,
735746
AE6716012A9AC089005C193F /* KeyServiceError.swift in Sources */,
747+
77AD9F062DBB031D00182E65 /* ActivityHomeHeaderView.swift in Sources */,
736748
AE0C30FB2A804B95008F1EAE /* WalletViewModel.swift in Sources */,
737749
AE49847C2A1BBBD6009951E2 /* BDKSwiftExampleWalletApp.swift in Sources */,
738750
AE6715FF2A9AC066005C193F /* FeeServiceError.swift in Sources */,

BDKSwiftExampleWallet/View Model/WalletViewModel.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class WalletViewModel {
3939
var transactions: [CanonicalTx]
4040
var walletSyncState: WalletSyncState
4141
var walletViewError: AppError?
42+
var needsFullScan: Bool {
43+
bdkClient.needsFullScan()
44+
}
4245

4346
private var updateProgress: @Sendable (UInt64, UInt64) -> Void {
4447
{ [weak self] inspected, total in
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//
2+
// TransactionListHeaderView.swift
3+
// BDKSwiftExampleWallet
4+
//
5+
// Created by Rubens Machion on 24/04/25.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ActivityHomeHeaderView: View {
11+
12+
let walletSyncState: WalletSyncState
13+
let progress: Float
14+
let inspectedScripts: UInt64
15+
let totalScripts: UInt64
16+
let needsFullScan: Bool
17+
18+
let showAllTransactions: () -> Void
19+
20+
var body: some View {
21+
HStack {
22+
Text("Activity")
23+
Spacer()
24+
25+
HStack {
26+
if needsFullScan {
27+
Text("\(inspectedScripts)")
28+
.padding(.trailing, -5.0)
29+
.fontWeight(.semibold)
30+
.contentTransition(.numericText())
31+
.transition(.opacity)
32+
.fontDesign(.monospaced)
33+
.foregroundStyle(.secondary)
34+
.font(.caption2)
35+
.fontWeight(.thin)
36+
.animation(.easeInOut, value: inspectedScripts)
37+
} else if walletSyncState == .syncing {
38+
HStack {
39+
if progress < 1.0 {
40+
Text("\(inspectedScripts)")
41+
.padding(.trailing, -5.0)
42+
.fontWeight(.semibold)
43+
.contentTransition(.numericText())
44+
.transition(.opacity)
45+
46+
Text("/")
47+
.padding(.trailing, -5.0)
48+
.transition(.opacity)
49+
Text("\(totalScripts)")
50+
.contentTransition(.numericText())
51+
.transition(.opacity)
52+
}
53+
54+
Text(
55+
String(
56+
format: "%.0f%%",
57+
progress * 100
58+
)
59+
)
60+
.contentTransition(.numericText())
61+
.transition(.opacity)
62+
}
63+
.fontDesign(.monospaced)
64+
.foregroundStyle(.secondary)
65+
.font(.caption2)
66+
.fontWeight(.thin)
67+
.animation(.easeInOut, value: inspectedScripts)
68+
.animation(.easeInOut, value: totalScripts)
69+
.animation(.easeInOut, value: progress)
70+
}
71+
}
72+
HStack {
73+
HStack(spacing: 5) {
74+
self.syncImageIndicator()
75+
}
76+
.contentTransition(.symbolEffect(.replace.offUp))
77+
78+
}
79+
.foregroundStyle(.secondary)
80+
.font(.caption)
81+
82+
if walletSyncState == .synced {
83+
Button {
84+
self.showAllTransactions()
85+
} label: {
86+
HStack(spacing: 2) {
87+
Text("Show All")
88+
Image(systemName: "arrow.right")
89+
}
90+
.font(.caption)
91+
.foregroundStyle(.secondary)
92+
.fontWeight(.regular)
93+
}
94+
}
95+
}
96+
.fontWeight(.bold)
97+
}
98+
99+
@ViewBuilder
100+
private func syncImageIndicator() -> some View {
101+
switch walletSyncState {
102+
case .synced:
103+
AnyView(
104+
Image(systemName: "checkmark.circle.fill")
105+
.foregroundStyle(.green)
106+
)
107+
108+
case .syncing:
109+
AnyView(
110+
Image(systemName: "slowmo")
111+
.symbolEffect(
112+
.variableColor.cumulative
113+
)
114+
)
115+
116+
case .notStarted:
117+
AnyView(
118+
Image(systemName: "arrow.clockwise")
119+
)
120+
default:
121+
AnyView(
122+
Image(
123+
systemName: "person.crop.circle.badge.exclamationmark"
124+
)
125+
)
126+
}
127+
}
128+
}

BDKSwiftExampleWallet/View/WalletView.swift

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -42,90 +42,16 @@ struct WalletView: View {
4242
}
4343

4444
VStack {
45-
HStack {
46-
Text("Activity")
47-
Spacer()
48-
if viewModel.walletSyncState == .syncing {
49-
HStack {
50-
if viewModel.progress < 1.0 {
51-
Text("\(viewModel.inspectedScripts)")
52-
.padding(.trailing, -5.0)
53-
.fontWeight(.semibold)
54-
.contentTransition(.numericText())
55-
.transition(.opacity)
56-
57-
if !viewModel.bdkClient.needsFullScan() {
58-
Text("/")
59-
.padding(.trailing, -5.0)
60-
.transition(.opacity)
61-
Text("\(viewModel.totalScripts)")
62-
.contentTransition(.numericText())
63-
.transition(.opacity)
64-
}
65-
}
66-
67-
if !viewModel.bdkClient.needsFullScan() {
68-
Text(
69-
String(
70-
format: "%.0f%%",
71-
viewModel.progress * 100
72-
)
73-
)
74-
.contentTransition(.numericText())
75-
.transition(.opacity)
76-
}
77-
}
78-
.fontDesign(.monospaced)
79-
.foregroundStyle(.secondary)
80-
.font(.caption2)
81-
.fontWeight(.thin)
82-
.animation(.easeInOut, value: viewModel.inspectedScripts)
83-
.animation(.easeInOut, value: viewModel.totalScripts)
84-
.animation(.easeInOut, value: viewModel.progress)
85-
}
86-
HStack {
87-
HStack(spacing: 5) {
88-
if viewModel.walletSyncState == .syncing {
89-
Image(systemName: "slowmo")
90-
.symbolEffect(
91-
.variableColor.cumulative
92-
)
93-
} else if viewModel.walletSyncState == .synced {
94-
Image(systemName: "checkmark.circle.fill")
95-
.foregroundStyle(
96-
viewModel.walletSyncState == .synced
97-
? .green : .secondary
98-
)
99-
} else if viewModel.walletSyncState == .notStarted {
100-
Image(systemName: "arrow.clockwise")
101-
} else {
102-
Image(
103-
systemName: "person.crop.circle.badge.exclamationmark"
104-
)
105-
}
106-
}
107-
.contentTransition(.symbolEffect(.replace.offUp))
108-
109-
}
110-
.foregroundStyle(.secondary)
111-
.font(.caption)
112-
113-
if viewModel.walletSyncState == .synced {
114-
Button {
115-
showAllTransactions = true
116-
} label: {
117-
HStack(spacing: 2) {
118-
Text("Show All")
119-
Image(systemName: "arrow.right")
120-
}
121-
.font(.caption)
122-
.foregroundStyle(.secondary)
123-
.fontWeight(.regular)
124-
}
125-
}
126-
45+
ActivityHomeHeaderView(
46+
walletSyncState: viewModel.walletSyncState,
47+
progress: viewModel.progress,
48+
inspectedScripts: viewModel.inspectedScripts,
49+
totalScripts: viewModel.totalScripts,
50+
needsFullScan: viewModel.needsFullScan
51+
) {
52+
showAllTransactions = true
12753
}
128-
.fontWeight(.bold)
54+
12955
TransactionListView(
13056
viewModel: .init(),
13157
transactions: viewModel.recentTransactions,

0 commit comments

Comments
 (0)