Skip to content

Commit 4a05f03

Browse files
committed
feat: add balance format in TransactionDetailView and LocalOutputItemView
1 parent e8769ed commit 4a05f03

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

BDKSwiftExampleWallet/Resources/Localizable.xcstrings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
}
289289
},
290290
"%llu sats" : {
291+
"extractionState" : "stale",
291292
"localizations" : {
292293
"fr" : {
293294
"stringUnit" : {

BDKSwiftExampleWallet/View/Activity/ActivityListView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ struct ActivityListView: View {
3636
} else {
3737
LocalOutputListView(
3838
localOutputs: viewModel.localOutputs,
39-
walletSyncState: viewModel.walletSyncState
39+
walletSyncState: viewModel.walletSyncState,
40+
fiatPrice: viewModel.fiatPrice
4041
)
4142
.transition(.blurReplace)
4243
}

BDKSwiftExampleWallet/View/Activity/LocalOutputItemView.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import BitcoinDevKit
99
import SwiftUI
1010

1111
struct LocalOutputItemView: View {
12+
@AppStorage("balanceDisplayFormat") private var balanceFormat: BalanceDisplayFormat =
13+
.bitcoinSats
1214
@Environment(\.dynamicTypeSize) var dynamicTypeSize
1315
let isRedacted: Bool
1416
let output: LocalOutput
17+
let fiatPrice: Double
1518

1619
var body: some View {
1720
HStack(spacing: 15) {
@@ -53,14 +56,24 @@ struct LocalOutputItemView: View {
5356
.redacted(reason: isRedacted ? .placeholder : [])
5457

5558
Spacer()
56-
57-
Text("\(output.txout.value.toSat()) sats")
58-
.font(.subheadline)
59-
.fontWeight(.semibold)
60-
.fontDesign(.rounded)
61-
.lineLimit(1)
62-
.redacted(reason: isRedacted ? .placeholder : [])
63-
59+
60+
Group {
61+
HStack {
62+
Text(balanceFormat.displayPrefix)
63+
Text(
64+
balanceFormat.formatted(
65+
output.txout.value.toSat(),
66+
fiatPrice: fiatPrice
67+
)
68+
)
69+
Text(balanceFormat.displayText)
70+
}
71+
}
72+
.font(.subheadline)
73+
.fontWeight(.semibold)
74+
.fontDesign(.rounded)
75+
.lineLimit(1)
76+
.redacted(reason: isRedacted ? .placeholder : [])
6477
}
6578
.padding(.vertical, 15.0)
6679
.padding(.vertical, 5.0)
@@ -71,6 +84,7 @@ struct LocalOutputItemView: View {
7184
#Preview {
7285
LocalOutputItemView(
7386
isRedacted: false,
74-
output: .mock
87+
output: .mock,
88+
fiatPrice: 714.23
7589
)
7690
}

BDKSwiftExampleWallet/View/Activity/LocalOutputListView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import SwiftUI
1111
struct LocalOutputListView: View {
1212
let localOutputs: [LocalOutput]
1313
let walletSyncState: WalletSyncState
14+
let fiatPrice: Double
1415

1516
var body: some View {
1617
List {
1718
if localOutputs.isEmpty && walletSyncState == .syncing {
1819
LocalOutputItemView(
1920
isRedacted: true,
20-
output: .mock
21+
output: .mock,
22+
fiatPrice: .zero
2123
)
2224
.listRowInsets(EdgeInsets())
2325
.listRowSeparator(.hidden)
@@ -30,7 +32,8 @@ struct LocalOutputListView: View {
3032
ForEach(localOutputs, id: \.outpoint) { output in
3133
LocalOutputItemView(
3234
isRedacted: false,
33-
output: output
35+
output: output,
36+
fiatPrice: fiatPrice
3437
)
3538
}
3639
.listRowInsets(EdgeInsets())
@@ -43,5 +46,5 @@ struct LocalOutputListView: View {
4346
}
4447

4548
#Preview {
46-
LocalOutputListView(localOutputs: [.mock], walletSyncState: .synced)
49+
LocalOutputListView(localOutputs: [.mock], walletSyncState: .synced, fiatPrice: 714.23)
4750
}

BDKSwiftExampleWallet/View/Activity/TransactionDetailView.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import BitcoinUI
1010
import SwiftUI
1111

1212
struct TransactionDetailView: View {
13+
@AppStorage("balanceDisplayFormat") private var balanceFormat: BalanceDisplayFormat =
14+
.bitcoinSats
1315
@Bindable var viewModel: TransactionDetailViewModel
1416
@State private var isCopied = false
1517
@State private var showCheckmark = false
1618
let txDetails: TxDetails
19+
let fiatPrice: Double
1720

1821
var body: some View {
1922

@@ -55,8 +58,14 @@ struct TransactionDetailView: View {
5558

5659
VStack(spacing: 8) {
5760
HStack {
58-
Text(abs(txDetails.balanceDelta).delimiter)
59-
Text("sats")
61+
Text(balanceFormat.displayPrefix)
62+
Text(
63+
balanceFormat.formatted(
64+
UInt64(abs(txDetails.balanceDelta)),
65+
fiatPrice: fiatPrice
66+
)
67+
)
68+
Text(balanceFormat.displayText)
6069
}
6170
.lineLimit(1)
6271
.minimumScaleFactor(0.5)
@@ -168,7 +177,8 @@ struct TransactionDetailView: View {
168177
viewModel: .init(
169178
bdkClient: .mock
170179
),
171-
txDetails: .mock
180+
txDetails: .mock,
181+
fiatPrice: 714.23
172182
)
173183
}
174184
#endif

BDKSwiftExampleWallet/View/Activity/TransactionListView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ struct TransactionListView: View {
112112
viewModel: .init(
113113
bdkClient: .live
114114
),
115-
txDetails: txDetails
115+
txDetails: txDetails,
116+
fiatPrice: fiatPrice
116117
)
117118
) {
118119
TransactionItemView(

0 commit comments

Comments
 (0)