Skip to content

Commit

Permalink
🪲[Techdebt] polish layout fees (#229)
Browse files Browse the repository at this point in the history
* Reset layot of Edit Fee Button

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Re-added the formatted fees

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Set the new fee schedule

TIME:  1707828867
Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Filtered to just the destination addresses

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

* Moved the placement of the fee

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>

---------

Signed-off-by: kcw-grunt <mrkerrywashington@icloud.com>
  • Loading branch information
kcw-grunt authored Feb 14, 2024
1 parent e8f5cbe commit 316108d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 58 deletions.
24 changes: 8 additions & 16 deletions litewallet/Constants/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,16 @@ func strongify<Context: AnyObject, Arguments>(_ context: Context?, closure: @esc
}
}

/// Description: 1701029422
/// Description: 1707828867
func tieredOpsFee(amount: UInt64) -> UInt64 {
switch amount {
case 0 ..< 1_398_000:
return 69900
case 1_398_000 ..< 6_991_000:
return 111_910
case 6_991_000 ..< 27_965_000:
return 279_700
case 27_965_000 ..< 139_820_000:
return 699_540
case 139_820_000 ..< 279_653_600:
return 1_049_300
case 279_653_600 ..< 699_220_000:
return 1_398_800
case 699_220_000 ..< 1_398_440_000:
return 2_797_600
case 0 ..< 250_000_000:
return 350_000
case 250_000_000 ..< 1_000_000_000:
return 1_500_000
case _ where amount > 1_000_000_000:
return 3_500_000
default:
return 2_797_600
return 3_500_000
}
}
2 changes: 2 additions & 0 deletions litewallet/Constants/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ enum S {
static let cameraUnavailableMessage = Localization(key: "Send.cameraunavailableMessage", value: "Go to Settings to allow camera access.", comment: "Camera not allowed message")
static let balance = Localization(key: "Send.balance", value: "Balance: %1$@", comment: "Balance: $4.00")
static let fee = Localization(key: "Send.fees", value: "Fees: %1$@", comment: "Fees: $0.10")
static let networkFee = Localization(key: "Send.networkFee", value: "Network", comment: "Network")
static let serviceFee = Localization(key: "Send.serviceFee", value: "Service", comment: "Service")
static let feeBlank = Localization(key: "Send.feeBlank", value: "Fees:", comment: "Fees: ")
static let bareFee = Localization(key: "Send.fee", value: "Fee: %1$@", comment: "Fee: $0.01")
static let containsAddress = Localization(key: "Send.containsAddress", value: "The destination is your own address. You cannot send to yourself.", comment: "Warning when sending to self.")
Expand Down
3 changes: 0 additions & 3 deletions litewallet/Extensions/SafariServices+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ struct WebView: UIViewRepresentable {
}

func updateUIView(_ webview: WKWebView, context _: Context) {
print("::: webview \(webview.frame.size)")

webview.endEditing(true)

if scrollToSignup {
let point = CGPoint(x: 0, y: webview.scrollView.contentSize.height - webview.frame.size.height / 2)
print("::: point \(point)")

webview.scrollView.setContentOffset(point, animated: true)
DispatchQueue.main.async {
Expand Down
22 changes: 11 additions & 11 deletions litewallet/ViewControllers/AmountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AmountViewController: UIViewController, Trackable {
private let bottomBorder = UIView(color: .secondaryShadow)
private let cursor = BlinkingView(blinkColor: C.defaultTintColor)
private let balanceLabel = UILabel()
private let feeLabel = UILabel()
private let feesLabel = UILabel()
private let feeContainer = InViewAlert(type: .secondary)
private let tapView = UIView()
private let editFee = UIButton(type: .system)
Expand Down Expand Up @@ -110,7 +110,7 @@ class AmountViewController: UIViewController, Trackable {
view.addSubview(border)
view.addSubview(cursor)
view.addSubview(balanceLabel)
view.addSubview(feeLabel)
view.addSubview(feesLabel)
view.addSubview(tapView)
view.addSubview(amountLabel)
view.addSubview(bottomBorder)
Expand Down Expand Up @@ -140,7 +140,7 @@ class AmountViewController: UIViewController, Trackable {
currencyToggle.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -C.padding[2]),
])
feeSelectorHeight = feeContainer.heightAnchor.constraint(equalToConstant: 0.0)
feeSelectorTop = feeContainer.topAnchor.constraint(equalTo: feeLabel.bottomAnchor, constant: 0.0)
feeSelectorTop = feeContainer.topAnchor.constraint(equalTo: feesLabel.bottomAnchor, constant: 0.0)

feeContainer.constrain([
feeSelectorTop,
Expand All @@ -161,9 +161,9 @@ class AmountViewController: UIViewController, Trackable {
balanceLabel.leadingAnchor.constraint(equalTo: amountLabel.leadingAnchor),
balanceLabel.topAnchor.constraint(equalTo: cursor.bottomAnchor, constant: 10.0),
])
feeLabel.constrain([
feeLabel.leadingAnchor.constraint(equalTo: balanceLabel.leadingAnchor),
feeLabel.topAnchor.constraint(equalTo: balanceLabel.bottomAnchor),
feesLabel.constrain([
feesLabel.leadingAnchor.constraint(equalTo: balanceLabel.leadingAnchor),
feesLabel.topAnchor.constraint(equalTo: balanceLabel.bottomAnchor),
])
pinPadHeight = pinPad.view.heightAnchor.constraint(equalToConstant: 0.0)
addChildViewController(pinPad, layout: {
Expand All @@ -176,13 +176,13 @@ class AmountViewController: UIViewController, Trackable {
])
})
editFee.constrain([
editFee.leadingAnchor.constraint(equalTo: feeLabel.trailingAnchor, constant: -8.0),
editFee.centerYAnchor.constraint(equalTo: feeLabel.centerYAnchor, constant: -1.0),
editFee.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0),
editFee.centerYAnchor.constraint(equalTo: feesLabel.centerYAnchor, constant: -1.0),
editFee.widthAnchor.constraint(equalToConstant: 44.0),
editFee.heightAnchor.constraint(equalToConstant: 44.0),
])
bottomBorder.constrain([
bottomBorder.topAnchor.constraint(greaterThanOrEqualTo: currencyToggle.bottomAnchor, constant: C.padding[2]),
bottomBorder.topAnchor.constraint(greaterThanOrEqualTo: currencyToggle.bottomAnchor, constant: C.padding[3]),
bottomBorder.leadingAnchor.constraint(equalTo: view.leadingAnchor),
bottomBorder.bottomAnchor.constraint(equalTo: view.bottomAnchor),
bottomBorder.trailingAnchor.constraint(equalTo: view.trailingAnchor),
Expand Down Expand Up @@ -313,9 +313,9 @@ class AmountViewController: UIViewController, Trackable {
}

func updateBalanceLabel() {
if let (balance, fee) = balanceTextForAmount?(amount, selectedRate) {
if let (balance, fees) = balanceTextForAmount?(amount, selectedRate) {
balanceLabel.attributedText = balance
feeLabel.attributedText = fee
feesLabel.attributedText = fees
if let amount = amount, amount > 0, !isRequesting {
editFee.isHidden = false
} else {
Expand Down
52 changes: 32 additions & 20 deletions litewallet/ViewControllers/RootModals/SendViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka
// MARK: - AmountView Callbacks

amountView.balanceTextForAmount = { [weak self] amount, rate in
self?.balanceTextForAmount(amount: amount, rate: rate)
self?.balanceTextForAmountWithFormattedFees(amount: amount, rate: rate)
}

amountView.didUpdateAmount = { [weak self] amount in
Expand Down Expand Up @@ -207,45 +207,57 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka
}
}

private func balanceTextForAmount(amount: Satoshis?, rate: Rate?) -> (NSAttributedString?, NSAttributedString?)
private func balanceTextForAmountWithFormattedFees(amount: Satoshis?, rate: Rate?) -> (NSAttributedString?, NSAttributedString?)
{
// DEV: KCW 12-FEB-24
// The results of this output is doing double duty and the method is a nightmare.
// The parent view controller uses the numbers and the text is used in this View Controller

let balanceAmount = DisplayAmount(amount: Satoshis(rawValue: balance), state: store.state, selectedRate: rate, minimumFractionDigits: 2)
let balanceText = balanceAmount.description

let balanceOutput = String(format: S.Send.balance.localize(), balanceText)
var feeOutput = ""
var combinedFeesOutput = ""
var balanceColor: UIColor = .grayTextTint

let balanceStyle = [
NSAttributedString.Key.font: UIFont.customBody(size: 14.0),
NSAttributedString.Key.foregroundColor: balanceColor,
]

/// Check the amount is greater than zero and if user is opting out of fees
if let amount = amount, amount > 0 {
let tieredOpsFee = tieredOpsFee(amount: amount.rawValue)
let totalAmountToCalculateFees = hasActivatedInlineFees ? (amount.rawValue + tieredOpsFee) : amount.rawValue
let totalAmountToCalculateFees = (amount.rawValue + tieredOpsFee)

let networkFee = sender.feeForTx(amount: totalAmountToCalculateFees)

let fee = sender.feeForTx(amount: totalAmountToCalculateFees)
let networkFeeAmount = DisplayAmount(amount: Satoshis(rawValue: networkFee),
state: store.state,
selectedRate: rate,
minimumFractionDigits: 2).description

let feeAmountLabel = DisplayAmount(amount: Satoshis(rawValue: fee) + tieredOpsFee,
let serviceFeeAmount = DisplayAmount(amount: Satoshis(rawValue: tieredOpsFee),
state: store.state,
selectedRate: rate,
minimumFractionDigits: 2).description

let totalFeeAmount = DisplayAmount(amount: Satoshis(rawValue: networkFee + tieredOpsFee),
state: store.state,
selectedRate: rate,
minimumFractionDigits: 2)
minimumFractionDigits: 2).description
let combinedfeeText = networkFeeAmount.description.replacingZeroFeeWithTenCents() +
serviceFeeAmount.description.replacingZeroFeeWithTenCents() +
totalFeeAmount.description.replacingZeroFeeWithTenCents()

let feeText = feeAmountLabel.description.replacingZeroFeeWithTenCents()
feeOutput = hasActivatedInlineFees ? String(format: S.Send.fee.localize(), feeText) :
String(format: S.Send.feeBlank.localize(), feeText)
combinedFeesOutput = "(\(S.Send.networkFee.localize()) + \(S.Send.serviceFee.localize())): \(networkFeeAmount) + \(serviceFeeAmount) = \(totalFeeAmount)"

if balance >= (fee + tieredOpsFee), amount.rawValue > (balance - (fee + tieredOpsFee)) {
if balance >= (networkFee + tieredOpsFee), amount.rawValue > (balance - (networkFee + tieredOpsFee)) {
balanceColor = .litewalletOrange
}
}

let balanceStyle = [
NSAttributedString.Key.font: UIFont.customBody(size: 14.0),
NSAttributedString.Key.foregroundColor: balanceColor,
]

let balanceAttributes: [NSAttributedString.Key: Any] = balanceStyle
let feeAttributes: [NSAttributedString.Key: Any] = balanceStyle

return (NSAttributedString(string: balanceOutput, attributes: balanceAttributes), NSAttributedString(string: feeOutput, attributes: feeAttributes))
return (NSAttributedString(string: balanceOutput, attributes: balanceStyle), NSAttributedString(string: combinedFeesOutput, attributes: balanceStyle))
}

@objc private func pasteTapped() {
Expand Down
18 changes: 10 additions & 8 deletions litewallet/ViewModels/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ class Transaction {
self.kvStore = kvStore

let fee = wallet.feeForTx(tx) ?? 0
self.fee = fee

let opsOutput = tx.outputs.filter { $0.updatedSwiftAddress == Partner.partnerKeyPath(name: .litewalletOps) }.first
guard let opsAmount = opsOutput?.amount else { return nil }

self.fee = fee + opsAmount

let amountReceived = wallet.amountReceivedFromTx(tx)
let amountSent = wallet.amountSentByTx(tx)
let amountSent = wallet.amountSentByTx(tx) - opsAmount

if amountSent > 0, (amountReceived + fee) == amountSent {
direction = .moved
Expand Down Expand Up @@ -158,12 +162,10 @@ class Transaction {
switch self.direction {
case .sent:

guard let output = self
.tx.outputs.filter({ output in
!self.wallet.containsAddress(output.updatedSwiftAddress)
})
.first

let allOutputs = self.tx.outputs.filter { $0.updatedSwiftAddress != Partner.partnerKeyPath(name: .litewalletOps) }
guard let output = allOutputs.filter({ output in
!self.wallet.containsAddress(output.updatedSwiftAddress)
}).first
else {
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR)
return nil
Expand Down

0 comments on commit 316108d

Please sign in to comment.