alpha-wallet-ios icon indicating copy to clipboard operation
alpha-wallet-ios copied to clipboard

NSAttributedString Foreground Colours being overridden and not used in TransactionHeaderView

Open eviltofu opened this issue 2 years ago • 3 comments

Simulator Screen Shot - iPhone 14 Pro - 2023-01-04 at 18 19 18 copy

Problem

The foreground color in amountTextColor (first snippet of code) is being overridden by Configuration.Color.Semantic.defaultHeadlineText (fourth snippet of code). The Colors.appHighlightGreen and Colors.appRed never show up.

First code snippet

https://github.com/AlphaWallet/alpha-wallet-ios/blob/a4444260968a61b4543a67c999ebd038d999d054/AlphaWallet/Transactions/ViewModels/TransactionViewModel.swift#L36

    var amountTextColor: UIColor {
        switch direction {
        case .incoming: return Colors.appHighlightGreen
        case .outgoing: return Colors.appRed
        }
    }

This code snippet colours the text for incoming and outgoing amounts.

Second code snippet

https://github.com/AlphaWallet/alpha-wallet-ios/blob/a4444260968a61b4543a67c999ebd038d999d054/AlphaWallet/Transactions/ViewModels/TransactionViewModel.swift#L51

    func amountAttributedString(for value: TransactionValue) -> NSAttributedString {
        let amount = NSAttributedString(string: amountWithSign(for: value.amount), attributes: [
            .font: Fonts.regular(size: 24) as Any,
            .foregroundColor: amountTextColor,
        ])

        let currency = NSAttributedString(string: " " + value.symbol, attributes: [
            .font: Fonts.regular(size: 16) as Any
        ])

        return amount + currency
    }

This code snippet uses the colours generated by amountTextColor.

Third code snippet

https://github.com/AlphaWallet/alpha-wallet-ios/blob/a4444260968a61b4543a67c999ebd038d999d054/AlphaWallet/Transactions/ViewModels/TransactionViewModel.swift#L47

    var fullAmountAttributedString: NSAttributedString {
        return amountAttributedString(for: fullValue)
    }

Fourth code snippet

https://github.com/AlphaWallet/alpha-wallet-ios/blob/6e47c3da7c5d8da344fbef7f0b2934b9224ed4ac/AlphaWallet/Transactions/Views/TransactionHeaderView.swift#L12

    var amount: NSAttributedString {
        NSAttributedString(string: transactionViewModel.fullAmountAttributedString.string, attributes: [
            .font: Fonts.semibold(size: 20) as Any,
            .foregroundColor: Configuration.Color.Semantic.defaultHeadlineText,
        ])
    }

eviltofu avatar Jan 04 '23 10:01 eviltofu

@eviltofu do we address this issue by removing the relevant code? Or are you saying there is a bug?

hboon avatar Jan 05 '23 00:01 hboon

@eviltofu do we address this issue by removing the relevant code? Or are you saying there is a bug?

The colours from previous call are overridden and not used. So we can:

  1. change the code to allow the colours to come through
  2. remove the code that generates these colours
  3. do nothing.

Waiting on your decision.

eviltofu avatar Jan 05 '23 02:01 eviltofu

@eviltofu ah, I see. For this, take the general approach: remove redundant code so the app looks like it does before the change.

hboon avatar Jan 05 '23 07:01 hboon