commit b848912eecb9771960fad8a044f638da7ac94335
parent 5ba01a1186b9bc13cfb5f014c335388e89f8eeec
Author: William Casarin <jb55@jb55.com>
Date: Wed, 30 Mar 2022 19:05:59 -0700
fix exchange rate for receive view
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
4 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/lightninglink/Views/AmountInputView.swift b/lightninglink/Views/AmountInputView.swift
@@ -76,11 +76,13 @@ struct AmountInput: View {
}
-
-func sats_to_fiat(msats: Int64, xr: ExchangeRate) -> String {
+func msats_to_fiat(msats: Int64, xr: ExchangeRate) -> String {
let btc = Double(msats) / Double(100_000_000_000)
let rate = xr.rate * btc
- return String(format: "%.2f \(xr.currency)", rate)
+ let num_fmt = NumberFormatter()
+ num_fmt.numberStyle = .decimal
+ let fmt = num_fmt.string(from: NSNumber(value: round(rate * 100) / 100.0))!
+ return "$\(fmt)"
}
diff --git a/lightninglink/Views/ContentView.swift b/lightninglink/Views/ContentView.swift
@@ -163,9 +163,20 @@ struct ContentView: View {
Text("\(format_last_pay())")
.foregroundColor(Color.red)
- Text("\(self.funds.channel_sats) sats")
- .font(.title)
- .padding()
+ HStack {
+ Text("\(self.funds.channel_sats)")
+ .font(.largeTitle)
+ .fontWeight(.bold)
+
+ Text("sats")
+ .font(.subheadline)
+ }
+
+ if let rate = self.rate {
+ Text("\(msats_to_fiat(msats: self.funds.channel_sats * 1000, xr: rate))")
+ .font(.footnote)
+ .foregroundColor(.gray)
+ }
if self.funds.onchain_sats != 0 {
Text("\(self.funds.onchain_sats) onchain")
@@ -219,7 +230,7 @@ struct ContentView: View {
}
case .receive:
- ReceiveView(lnlink: lnlink, rate: self.rate)
+ ReceiveView(rate: $rate, lnlink: lnlink)
case .pay(let decode):
PayView(decode: decode, lnlink: self.lnlink, rate: self.rate)
diff --git a/lightninglink/Views/PayView.swift b/lightninglink/Views/PayView.swift
@@ -365,7 +365,7 @@ struct PayView: View {
if self.custom_amount_input != "", let msats = self.custom_amount_msats {
if let rate = self.rate {
- Text("\(sats_to_fiat(msats: msats, xr: rate))")
+ Text("\(msats_to_fiat(msats: msats, xr: rate))")
.foregroundColor(.gray)
}
}
diff --git a/lightninglink/Views/ReceiveView.swift b/lightninglink/Views/ReceiveView.swift
@@ -23,9 +23,9 @@ struct ReceiveView: View {
@State private var amount_str: String = ""
@State private var making: Bool = false
@FocusState private var is_kb_focused: Bool
+ @Binding var rate: ExchangeRate?
let lnlink: LNLink
- let rate: ExchangeRate?
@Environment(\.presentationMode) var presentationMode
@@ -71,7 +71,7 @@ struct ReceiveView: View {
if self.amount_str != "", let msats = self.amount {
if let rate = self.rate {
- Text("\(sats_to_fiat(msats: msats, xr: rate))")
+ Text("\(msats_to_fiat(msats: msats, xr: rate))")
.foregroundColor(.gray)
}
}