Skip to content

Commit

Permalink
Merge pull request #1507 from p2p-org/fix/pwn-9390
Browse files Browse the repository at this point in the history
[PWN-9390] Show custom format when balance < 0.01 on Wallet
  • Loading branch information
TrGiLong authored Jul 26, 2023
2 parents fc7e5db + fb41982 commit 18514b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 6 additions & 5 deletions p2p_wallet/Common/Extensions/Double+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ extension Double {
maximumFractionDigits: Int = 2,
currency: Fiat = Defaults.fiat,
roundingMode: NumberFormatter.RoundingMode? = nil,
customFormattForLessThan1E_2: Bool = false
customFormattForLessThan1E_2: Bool = false,
spacing: String = " "
) -> String {
// amount < 0.01
if customFormattForLessThan1E_2 && self > 0 && self < 0.01 {
if currency == .usd {
return "< \(currency.symbol) 0.01"
return "<\(spacing)\(currency.symbol)\(spacing)0.01"
} else {
return "< 0.01 \(currency.symbol)"
return "<\(spacing)0.01\(spacing)\(currency.symbol)"
}
}

Expand All @@ -129,9 +130,9 @@ extension Double {
let formattedString = toString(maximumFractionDigits: maximumFractionDigits, roundingMode: roundingMode)

if currency == .usd {
return "\(currency.symbol) \(formattedString)"
return "\(currency.symbol)\(spacing)\(formattedString)"
} else {
return "\(formattedString) \(currency.symbol)"
return "\(formattedString)\(spacing)\(currency.symbol)"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ final class HomeAccountsViewModel: BaseViewModel, ObservableObject {
return $0 + $1.amountInFiatDouble
}
}
return "\(Defaults.fiat.symbol)\(equityValue.toString(maximumFractionDigits: 2, roundingMode: .down))"
return equityValue.fiatAmountFormattedString(
maximumFractionDigits: 2,
roundingMode: .down,
customFormattForLessThan1E_2: true,
spacing: ""
)
}
.receive(on: RunLoop.main)
.assignWeak(to: \.balance, on: self)
Expand Down

0 comments on commit 18514b1

Please sign in to comment.