Skip to content

Commit

Permalink
(ios) Display more accurate lightning fee as a percentage (#449)
Browse files Browse the repository at this point in the history
The actual fee amount is: 4 sats + 0.4%. So this meant the user 
might see an effective fee of "0.5%" or "0.7%" when sending smaller 
payments.  They might proceed to think this is the fee for all payments.

Now the effective fee displays the base fee + the percentage fee when
needed, or just the percentage fee if the payment is large enough.
  • Loading branch information
robbiehanson authored Oct 17, 2023
1 parent 699e32f commit 7b264c0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions phoenix-ios/phoenix-ios/views/send/PaymentSummaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ struct PaymentSummaryView: View {
fiat_total = unknownFiatAmount
}

let percent_tip = percentString(nums.tipPercent)
let percent_lightningFee = percentString(nums.lightningFeePercent)
let percent_minerFee = percentString(nums.minerFeePercent)
let percent_tip = generalPercentString(nums.tipPercent)
let percent_lightningFee = lightningPercentString(nums.lightningFeePercent)
let percent_minerFee = generalPercentString(nums.minerFeePercent)

return PaymentSummaryStrings(
bitcoin_base : bitcoin_base,
Expand All @@ -367,7 +367,7 @@ struct PaymentSummaryView: View {
)
}

func percentString(_ value: Double) -> String {
func generalPercentString(_ value: Double) -> String {

let formatter = NumberFormatter()
formatter.numberStyle = .percent
Expand All @@ -383,6 +383,28 @@ struct PaymentSummaryView: View {
return formatter.string(from: NSNumber(value: value)) ?? ""
}

func lightningPercentString(_ value: Double) -> String {

let formatter = NumberFormatter()
formatter.numberStyle = .percent
formatter.minimumFractionDigits = 1
formatter.maximumFractionDigits = 1
formatter.roundingMode = .halfUp

// The actual lightning fee is: 4 sats + 0.4%
// But this often gets communicated as simply "0.4%"...
// So we want to be more specific when the payment amount is smaller.

if value < 0.0041 { // if amount > 40,000 sats
return formatter.string(from: NSNumber(value: value)) ?? ""

} else {
let percentStr = formatter.string(from: NSNumber(value: 0.004)) ?? ""
let flatStr = Utils.formatBitcoin(sat: 4, bitcoinUnit: .sat)
return "\(percentStr) + \(flatStr.string)"
}
}

func accessibilityLabel_baseAmount(_ info: PaymentSummaryStrings) -> String {

let amountBitcoin = info.bitcoin_base.string
Expand Down

0 comments on commit 7b264c0

Please sign in to comment.