Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions LDKNodeMonday/Extensions/UInt64+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,29 @@ extension UInt64 {

}

extension UInt64 {
private var numberFormatter: NumberFormatter {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.usesGroupingSeparator = true
numberFormatter.groupingSeparator = ","
numberFormatter.generatesDecimalNumbers = false

return numberFormatter
}

func formattedBip177() -> String {
if self != .zero && self >= 1_000_000 && self % 1_000_000 == .zero {
return "\(self / 1_000_000)M"

} else if self != .zero && self % 1_000 == 0 {
return "\(self / 1_000)K"
}

return numberFormatter.string(from: NSNumber(value: self)) ?? "0"
}
}

public enum BitcoinFormatting {
case satscomma
case truncated
Expand Down
30 changes: 22 additions & 8 deletions LDKNodeMonday/View/Home/BitcoinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ struct BalanceHeader: View {
return viewModel.balances.totalLightningBalanceSats.formatted(
.number.notation(.automatic)
)
case .totalBip177:
return "₿" + viewModel.unifiedBalance.formattedBip177()
case .onchainBip177:
return "₿" + viewModel.balances.totalOnchainBalanceSats.formattedBip177()
case .lightningBip177:
return "₿" + viewModel.balances.totalLightningBalanceSats.formattedBip177()
}
}

Expand All @@ -171,23 +177,22 @@ struct BalanceHeader: View {
return "₿" + viewModel.unifiedBalance.formattedSatsAsBtc()
case .btcFiat:
return viewModel.totalUSDValue
case .totalSats:
case .totalSats, .totalBip177:
return "Total"
case .onchainSats:
case .onchainSats, .onchainBip177:
return "Onchain"
case .lightningSats:
case .lightningSats, .lightningBip177:
return "Lightning"

}
}

var unitValue: String {
switch displayBalanceType {
case .fiatBtc:
return ""
case .btcFiat:
return ""
default:
case .totalSats, .onchainSats, .lightningSats:
return "sats"
default:
return ""
}
}
}
Expand Down Expand Up @@ -312,6 +317,9 @@ public enum DisplayBalanceType: String {
case totalSats
case onchainSats
case lightningSats
case onchainBip177
case lightningBip177
case totalBip177
}

extension DisplayBalanceType {
Expand All @@ -328,6 +336,12 @@ extension DisplayBalanceType {
case .onchainSats:
self = .lightningSats
case .lightningSats:
self = .totalBip177
case .totalBip177:
self = .onchainBip177
case .onchainBip177:
self = .lightningBip177
case .lightningBip177:
self = .fiatSats
}
}
Expand Down