Skip to content

Commit 5b5267d

Browse files
committed
no message
1 parent 7ba8127 commit 5b5267d

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

BDKSwiftExampleWallet/Model/BalanceDisplayFormat.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ enum BalanceDisplayFormat: String, CaseIterable, Codable {
1515
case fiat = "usd"
1616
case bip177 = "bip177"
1717

18+
var displayPrefix: String {
19+
switch self {
20+
case .bitcoinSats, .bitcoin, .bip177: return ""
21+
case .fiat: return "$"
22+
default : return ""
23+
}
24+
}
25+
1826
var displayText: String {
1927
switch self {
2028
case .sats, .bitcoinSats: return "sats"

BDKSwiftExampleWallet/Resources/Localizable.xcstrings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@
204204
}
205205
}
206206
},
207-
"%@%lld sats" : {
207+
"%@%@ %@" : {
208208
"localizations" : {
209209
"en" : {
210210
"stringUnit" : {
211211
"state" : "new",
212-
"value" : "%1$@%2$lld sats"
212+
"value" : "%1$@%2$@ %3$@"
213213
}
214214
}
215215
}

BDKSwiftExampleWallet/View Model/Activity/ActivityListViewModel.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ActivityListViewModel {
2222
var totalScripts: UInt64 = 0
2323
var walletSyncState: WalletSyncState
2424
var walletViewError: AppError?
25+
var fiatPrice: Double
2526

2627
private var updateProgress: @Sendable (UInt64, UInt64) -> Void {
2728
{ [weak self] inspected, total in
@@ -41,11 +42,13 @@ class ActivityListViewModel {
4142
init(
4243
bdkClient: BDKClient = .live,
4344
transactions: [CanonicalTx] = [],
44-
walletSyncState: WalletSyncState = .notStarted
45+
walletSyncState: WalletSyncState = .notStarted,
46+
fiatPrice: Double
4547
) {
4648
self.bdkClient = bdkClient
4749
self.transactions = transactions
4850
self.walletSyncState = walletSyncState
51+
self.fiatPrice = fiatPrice
4952

5053
// Preload cached data synchronously so UI has content before first render
5154
// transactions + listUnspent items are available from the persisted wallet db

BDKSwiftExampleWallet/View/Activity/ActivityListView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct ActivityListView: View {
2727
viewModel: .init(),
2828
transactions: viewModel.transactions,
2929
walletSyncState: viewModel.walletSyncState,
30-
format: .bip177
30+
format: .bip177,
31+
fiatPrice: viewModel.fiatPrice
3132
)
3233
.transition(.blurReplace)
3334
} else {
@@ -81,5 +82,5 @@ struct CustomSegmentedControl: View {
8182
}
8283

8384
#Preview {
84-
ActivityListView(viewModel: .init())
85+
ActivityListView(viewModel: .init(fiatPrice: 714.23))
8586
}

BDKSwiftExampleWallet/View/Activity/TransactionItemView.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ struct TransactionItemView: View {
1414
let txDetails: TxDetails
1515
let isRedacted: Bool
1616
private let format: BalanceDisplayFormat
17+
private var fiatPrice: Double
1718

1819
init(
1920
txDetails: TxDetails,
2021
isRedacted: Bool,
21-
format: BalanceDisplayFormat
22+
format: BalanceDisplayFormat,
23+
fiatPrice: Double
2224
) {
2325
self.txDetails = txDetails
2426
self.isRedacted = isRedacted
2527
self.format = format
28+
self.fiatPrice = fiatPrice
2629
}
2730

2831
var body: some View {
@@ -109,10 +112,11 @@ struct TransactionItemView: View {
109112
Spacer()
110113

111114
let delta = txDetails.balanceDelta
112-
let prefix = delta >= 0 ? "+ " : "- "
113-
let amount = abs(delta)
115+
let prefix = (delta >= 0 ? "+ " : "- ").appending("\(format.displayPrefix) ")
116+
let amount = format.formatted(UInt64(abs(delta)), fiatPrice: fiatPrice)
117+
let suffix = format.displayText
114118

115-
Text("\(prefix)\(amount) sats")
119+
Text("\(prefix)\(amount) \(suffix)")
116120
.font(.subheadline)
117121
.fontWeight(.semibold)
118122
.fontDesign(.rounded)
@@ -132,7 +136,8 @@ struct TransactionItemView: View {
132136
TransactionItemView(
133137
txDetails: .mock,
134138
isRedacted: false,
135-
format: .bip177
139+
format: .bip177,
140+
fiatPrice: 714.23
136141
)
137142
}
138143
#endif

BDKSwiftExampleWallet/View/Activity/TransactionListView.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@ struct TransactionListView: View {
1414
let transactions: [CanonicalTx]
1515
let walletSyncState: WalletSyncState
1616
private let format: BalanceDisplayFormat
17+
private let fiatPrice: Double
1718

1819
init(
1920
viewModel: TransactionListViewModel,
2021
transactions: [CanonicalTx],
2122
walletSyncState: WalletSyncState,
22-
format: BalanceDisplayFormat
23+
format: BalanceDisplayFormat,
24+
fiatPrice: Double
2325
) {
2426
self.viewModel = viewModel
2527
self.transactions = transactions
2628
self.walletSyncState = walletSyncState
2729
self.format = format
30+
self.fiatPrice = fiatPrice
2831
}
2932

3033
var body: some View {
@@ -34,7 +37,8 @@ struct TransactionListView: View {
3437
TransactionItemView(
3538
txDetails: .mock,
3639
isRedacted: true,
37-
format: format
40+
format: format,
41+
fiatPrice: fiatPrice
3842
)
3943
.listRowInsets(EdgeInsets())
4044
.listRowSeparator(.hidden)
@@ -114,7 +118,8 @@ struct TransactionListView: View {
114118
TransactionItemView(
115119
txDetails: txDetails,
116120
isRedacted: false,
117-
format: format
121+
format: format,
122+
fiatPrice: fiatPrice
118123
)
119124
}
120125

@@ -155,7 +160,8 @@ struct TransactionListView: View {
155160
.mock
156161
],
157162
walletSyncState: .synced,
158-
format: .bip177
163+
format: .bip177,
164+
fiatPrice: 714.23
159165
)
160166
}
161167
#Preview {
@@ -165,7 +171,8 @@ struct TransactionListView: View {
165171
),
166172
transactions: [],
167173
walletSyncState: .synced,
168-
format: .bip177
174+
format: .bip177,
175+
fiatPrice: 714.23
169176
)
170177
}
171178
#endif

BDKSwiftExampleWallet/View/Home/BalanceView.swift

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ struct BalanceView: View {
1414
private var format: BalanceDisplayFormat
1515
private let balance: UInt64
1616
private var fiatPrice: Double
17-
private var satsPrice: Double {
18-
let usdValue = Double(balance).valueInUSD(price: fiatPrice)
19-
return usdValue
20-
}
2117

2218
private var currencySymbol: some View {
2319
Image(systemName: format == .fiat ? "dollarsign" : "bitcoinsign")
@@ -38,36 +34,22 @@ struct BalanceView: View {
3834
@MainActor
3935
private var formattedBalance: String {
4036
return format.formatted(balance, fiatPrice: fiatPrice)
41-
// switch format {
42-
// case .sats:
43-
// return balance.formatted(.number)
44-
// case .bitcoin:
45-
// return String(format: "%.8f", Double(balance) / 100_000_000)
46-
// case .bitcoinSats:
47-
// return balance.formattedSatoshis()
48-
// case .bip21q:
49-
// return balance.formatted(.number)
50-
// case .fiat:
51-
// return satsPrice.formatted(.number.precision(.fractionLength(2)))
52-
// case .bip177:
53-
// return balance.formattedBip177()
54-
// }
5537
}
5638

5739
@MainActor
5840
var balanceText: some View {
59-
Text(format == .fiat && satsPrice == 0 ? "00.00" : formattedBalance)
41+
Text(format == .fiat && fiatPrice == 0 ? "00.00" : formattedBalance)
6042
.contentTransition(.numericText(countsDown: true))
6143
.fontWeight(.semibold)
6244
.fontDesign(.rounded)
6345
.foregroundStyle(
64-
format == .fiat && satsPrice == 0 ? .secondary : .primary
46+
format == .fiat && fiatPrice == 0 ? .secondary : .primary
6547
)
6648
.opacity(
67-
format == .fiat && satsPrice == 0 ? balanceTextPulsingOpacity : 1
49+
format == .fiat && fiatPrice == 0 ? balanceTextPulsingOpacity : 1
6850
)
6951
.animation(.spring(response: 0.4, dampingFraction: 0.8), value: format)
70-
.animation(.easeInOut, value: satsPrice)
52+
.animation(.easeInOut, value: fiatPrice)
7153
.onAppear {
7254
withAnimation(.easeInOut(duration: 1.5).repeatForever(autoreverses: true)) {
7355
balanceTextPulsingOpacity = 0.3

BDKSwiftExampleWallet/View/WalletView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ struct WalletView: View {
6060
viewModel: .init(),
6161
transactions: viewModel.recentTransactions,
6262
walletSyncState: viewModel.walletSyncState,
63-
format: balanceFormat
63+
format: balanceFormat,
64+
fiatPrice: viewModel.price
6465
)
6566
.refreshable {
6667
if viewModel.isKyotoClient {
@@ -152,7 +153,7 @@ struct WalletView: View {
152153

153154
}
154155
.navigationDestination(isPresented: $showAllTransactions) {
155-
ActivityListView(viewModel: .init())
156+
ActivityListView(viewModel: .init(fiatPrice: viewModel.price))
156157
}
157158
.navigationDestination(for: NavigationDestination.self) { destination in
158159
switch destination {

0 commit comments

Comments
 (0)