lnlink

iOS app for connecting to lightning nodes
git clone git://jb55.com/lnlink
Log | Files | Refs | Submodules | README | LICENSE

commit 364abfca2b0771c093ff375db9c8011712c11f6b
parent 6212a49d308d938d8a1d85ad1053a477ab79271b
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 31 Mar 2022 07:46:24 -0700

use amount_view everywhere

and include the exchange rate

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mlightninglink/Views/ContentView.swift | 15+--------------
Mlightninglink/Views/PayView.swift | 32+++++++++++++++++++++-----------
2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/lightninglink/Views/ContentView.swift b/lightninglink/Views/ContentView.swift @@ -163,20 +163,7 @@ struct ContentView: View { Text("\(format_last_pay())") .foregroundColor(Color.red) - 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) - } + amount_view(self.funds.channel_sats * 1000, rate: self.rate) if self.funds.onchain_sats != 0 { Text("\(self.funds.onchain_sats) onchain") diff --git a/lightninglink/Views/PayView.swift b/lightninglink/Views/PayView.swift @@ -301,7 +301,7 @@ struct PayView: View { switch amt { case .min(let min_amt): - amount_view(min_amt + self.custom_amount_msats) + amount_view(min_amt + self.custom_amount_msats, rate: self.rate) Text("\(render_amount_msats(self.custom_amount_msats)) tipped") .font(.callout) @@ -315,7 +315,7 @@ struct PayView: View { case .range(let min_amt, let max_amt): if self.paying { let amt = self.custom_amount_msats - amount_view(amt) + amount_view(amt, rate: self.rate) } else { AmountInput(text: $custom_amount_input, placeholder: default_placeholder) { result in if let str = result.msats_str { @@ -342,7 +342,7 @@ struct PayView: View { case .any: if self.paying { let amt = self.custom_amount_msats - amount_view(amt) + amount_view(amt, rate: self.rate) } else { Form { AmountInput(text: $custom_amount_input, placeholder: default_placeholder) { parsed in @@ -358,7 +358,7 @@ struct PayView: View { } case .amount(let amt): - amount_view(amt) + amount_view(amt, rate: self.rate) } if self.custom_amount_input != "", let msats = self.custom_amount_msats { @@ -868,12 +868,22 @@ func pay_amount_matches(pay_amt: PayAmount, invoice_amount: InvoiceAmount) -> Bo -func amount_view(_ msats: Int64) -> some View { - HStack { - let sep = render_amount_msats_sep(msats) - Text(sep.0) - .font(.largeTitle.bold()) - Text(sep.1) - .font(.title) +func amount_view(_ msats: Int64, rate mrate: ExchangeRate?) -> some View { + Group { + HStack { + let sep = render_amount_msats_sep(msats) + Text(sep.0) + .font(.largeTitle) + .fontWeight(.bold) + + Text(sep.1) + .font(.subheadline) + } + + if let rate = mrate { + Text("\(msats_to_fiat(msats: msats, xr: rate))") + .font(.footnote) + .foregroundColor(.gray) + } } }