Skip to content

Commit

Permalink
Fix displaying coin alternative icons in Transactions list
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Sep 10, 2024
1 parent 1b96e2d commit ac56310
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13144,7 +13144,7 @@
repositoryURL = "https://github.com/horizontalsystems/ComponentKit.Swift";
requirement = {
kind = exactVersion;
version = 2.0.13;
version = 2.0.14;
};
};
D3C187D3290FCF7D00FE1900 /* XCRemoteSwiftPackageReference "HUD" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class TonTransactionRecord: TransactionRecord {
blockHeight: nil,
confirmationsThreshold: nil,
date: Date(timeIntervalSince1970: TimeInterval(event.timestamp)),
failed: false
failed: false,
spam: event.isScam
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum TransactionValue {

var coin: Coin? {
switch self {
case let .coinValue(token, _): return token.isCustom ? nil : token.coin
case let .coinValue(token, _): return token.coin
default: return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extension CexWithdrawConfirmViewController: SectionsDataSource {
private func row(viewItem: CexWithdrawConfirmViewModel.ViewItem, rowInfo: RowInfo) -> RowProtocol {
switch viewItem {
case let .amount(title, iconUrl, iconPlaceholderImageName, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, imageUrl: iconUrl, placeholderImageName: iconPlaceholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, imageUrl: iconUrl, alternativeImageUrl: nil, placeholderImageName: iconPlaceholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ResendBitcoinViewController: KeyboardAwareViewController, SectionsDataSour
private func row(viewItem: ResendBitcoinViewModel.ViewItem, rowInfo: RowInfo) -> RowProtocol {
switch viewItem {
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, alternativeImageUrl: token.coin.image, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SendConfirmationViewController: ThemeViewController, SectionsDataSource {
private func row(viewItem: SendConfirmationViewModel.ViewItem, rowInfo: RowInfo) -> RowProtocol {
switch viewItem {
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, alternativeImageUrl: token.coin.image, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class SendEvmTransactionViewController: ThemeViewController {
case let .subhead(iconName, title, value):
return CellComponent.actionTitleRow(tableView: tableView, rowInfo: rowInfo, iconName: iconName, iconDimmed: true, title: title, value: value)
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, alternativeImageUrl: token.coin.image, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .nftAmount(iconUrl, iconPlaceholderImageName, nftAmount, type):
return CellComponent.nftAmountRow(tableView: tableView, rowInfo: rowInfo, iconUrl: iconUrl, iconPlaceholderImageName: iconPlaceholderImageName, nftAmount: nftAmount, type: type, onTapOpenNft: nil)
case let .doubleAmount(title, coinValue, currencyValue):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SendTronConfirmationViewController: ThemeViewController {
private func row(viewItem: SendTronConfirmationViewModel.ViewItem, rowInfo: RowInfo) -> RowProtocol {
switch viewItem {
case let .amount(title, token, coinAmount, currencyAmount, type):
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: token.fullBadge, imageUrl: token.coin.imageUrl, alternativeImageUrl: token.coin.image, placeholderImageName: token.placeholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type)
case let .address(title, value, valueTitle, contactAddress, statSection):
var onAddToContact: (() -> Void)? = nil
if let contactAddress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension TransactionInfoModule {

enum ViewItem {
case actionTitle(iconName: String?, iconDimmed: Bool, title: String, subTitle: String?)
case amount(title: String, subtitle: String?, iconUrl: String?, iconPlaceholderImageName: String, coinAmount: String, currencyAmount: String?, type: AmountType, coin: Coin?)
case amount(title: String, subtitle: String?, iconUrl: String?, iconAlternativeUrl: String?, iconPlaceholderImageName: String, coinAmount: String, currencyAmount: String?, type: AmountType, coin: Coin?)
case nftAmount(iconUrl: String?, iconPlaceholderImageName: String, nftAmount: String, type: AmountType, providerCollectionUid: String?, nftUid: NftUid?)
case status(status: TransactionStatus)
case option(option: Option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class TransactionInfoViewController: ThemeViewController {
switch viewItem {
case let .actionTitle(iconName, iconDimmed, title, subTitle):
return CellComponent.actionTitleRow(tableView: tableView, rowInfo: rowInfo, iconName: iconName, iconDimmed: iconDimmed, title: title, value: subTitle ?? "")
case let .amount(title, subtitle, iconUrl, iconPlaceholderImageName, coinAmount, currencyAmount, type, coin):
case let .amount(title, subtitle, iconUrl, iconAlternativeUrl, iconPlaceholderImageName, coinAmount, currencyAmount, type, coin):
var action: (() -> Void)?

if let coin {
Expand All @@ -492,7 +492,7 @@ class TransactionInfoViewController: ThemeViewController {
}
}

return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: subtitle, imageUrl: iconUrl, placeholderImageName: iconPlaceholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type, action: action)
return CellComponent.amountRow(tableView: tableView, rowInfo: rowInfo, title: title, subtitle: subtitle, imageUrl: iconUrl, alternativeImageUrl: iconAlternativeUrl, placeholderImageName: iconPlaceholderImageName, coinAmount: coinAmount, currencyAmount: currencyAmount, type: type, action: action)
case let .nftAmount(iconUrl, iconPlaceholderImageName, nftAmount, type, providerCollectionUid, nftUid):
var onTapOpenNft: (() -> Void)?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ class TransactionInfoViewItemFactory {

private func amount(source: TransactionSource, title: String, subtitle: String?, transactionValue: TransactionValue, rate: CurrencyValue?, type: AmountType, balanceHidden: Bool) -> TransactionInfoModule.ViewItem {
let iconUrl = transactionValue.coin?.imageUrl
let iconAlternativeUrl = transactionValue.coin?.image
let iconPlaceholderImageName = source.blockchainType.placeholderImageName(tokenProtocol: transactionValue.tokenProtocol)

let coin = transactionValue.token.flatMap { $0.isCustom ? nil : $0.coin }

if transactionValue.isMaxValue {
return .amount(
title: title,
subtitle: subtitle,
iconUrl: iconUrl,
iconAlternativeUrl: iconAlternativeUrl,
iconPlaceholderImageName: iconPlaceholderImageName,
coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : "\(transactionValue.coinCode)",
currencyAmount: balanceHidden ? BalanceHiddenManager.placeholder : "transactions.value.unlimited".localized,
type: type,
coin: transactionValue.coin
coin: coin
)
} else {
var currencyValue: CurrencyValue?
Expand All @@ -43,11 +47,12 @@ class TransactionInfoViewItemFactory {
title: title,
subtitle: subtitle,
iconUrl: iconUrl,
iconAlternativeUrl: iconAlternativeUrl,
iconPlaceholderImageName: iconPlaceholderImageName,
coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(signType: type.signType) ?? "n/a".localized,
currencyAmount: balanceHidden ? BalanceHiddenManager.placeholder : currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) },
type: type,
coin: transactionValue.coin
coin: coin
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ extension BaseTransactionsViewModel {
}

enum IconType {
case icon(imageUrl: String?, placeholderImageName: String)
case doubleIcon(frontType: TransactionImageComponent.ImageType, frontUrl: String?, frontPlaceholder: String, backType: TransactionImageComponent.ImageType, backUrl: String?, backPlaceholder: String)
case icon(url: String?, alternativeUrl: String?, placeholderImageName: String)
case doubleIcon(frontType: TransactionImageComponent.ImageType, frontUrl: String?, frontAlternativeUrl: String?, frontPlaceholder: String, backType: TransactionImageComponent.ImageType, backUrl: String?, backAlternativeUrl: String?, backPlaceholder: String)
case localIcon(imageName: String?)
case failedIcon
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,19 @@ class TransactionsTableViewDataSource: NSObject {
component.set(progress: viewItem.progress)

switch viewItem.iconType {
case let .icon(imageUrl, placeholderImageName):
component.setImage(
urlString: imageUrl,
placeholder: UIImage(named: placeholderImageName)
)
case let .icon(url, alternativeUrl, placeholderImageName):
component.setImage(url: url, alternativeUrl: alternativeUrl, placeholder: UIImage(named: placeholderImageName))
case let .localIcon(imageName):
component.set(image: imageName.flatMap { UIImage(named: $0)?.withTintColor(.themeLeah) })
case let .doubleIcon(frontType, frontUrl, frontPlaceholder, backType, backUrl, backPlaceholder):
case let .doubleIcon(frontType, frontUrl, frontAlternativeUrl, frontPlaceholder, backType, backUrl, backAlternativeUrl, backPlaceholder):
component.setDoubleImage(
frontType: frontType,
frontUrl: frontUrl,
frontAlternativeUrl: frontAlternativeUrl,
frontPlaceholder: UIImage(named: frontPlaceholder),
backType: backType,
backUrl: backUrl,
backAlternativeUrl: backAlternativeUrl,
backPlaceholder: UIImage(named: backPlaceholder)
)
case .failedIcon:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ class TransactionsViewItemFactory {
switch value {
case let .nftValue(nftUid, _, _, _):
return .icon(
imageUrl: nftMetadata[nftUid]?.previewImageUrl,
url: nftMetadata[nftUid]?.previewImageUrl,
alternativeUrl: nil,
placeholderImageName: "placeholder_nft_32"
)
default:
return .icon(
imageUrl: value.coin?.imageUrl,
url: value.coin?.imageUrl,
alternativeUrl: value.coin?.image,
placeholderImageName: source.blockchainType.placeholderImageName(tokenProtocol: value.tokenProtocol)
)
}
Expand All @@ -73,9 +75,11 @@ class TransactionsViewItemFactory {
private func doubleValueIconType(source: TransactionSource, primaryValue: TransactionValue?, secondaryValue: TransactionValue?, nftMetadata: [NftUid: NftAssetBriefMetadata] = [:]) -> BaseTransactionsViewModel.IconType {
let frontType: TransactionImageComponent.ImageType
let frontUrl: String?
var frontAlternativeUrl: String?
let frontPlaceholder: String
let backType: TransactionImageComponent.ImageType
let backUrl: String?
var backAlternativeUrl: String?
let backPlaceholder: String

if let primaryValue {
Expand All @@ -87,6 +91,7 @@ class TransactionsViewItemFactory {
default:
frontType = .circle
frontUrl = primaryValue.coin?.imageUrl
frontAlternativeUrl = primaryValue.coin?.image
frontPlaceholder = source.blockchainType.placeholderImageName(tokenProtocol: primaryValue.tokenProtocol)
}
} else {
Expand All @@ -104,6 +109,7 @@ class TransactionsViewItemFactory {
default:
backType = .circle
backUrl = secondaryValue.coin?.imageUrl
backAlternativeUrl = secondaryValue.coin?.image
backPlaceholder = source.blockchainType.placeholderImageName(tokenProtocol: secondaryValue.tokenProtocol)
}
} else {
Expand All @@ -112,7 +118,16 @@ class TransactionsViewItemFactory {
backPlaceholder = "placeholder_circle_32"
}

return .doubleIcon(frontType: frontType, frontUrl: frontUrl, frontPlaceholder: frontPlaceholder, backType: backType, backUrl: backUrl, backPlaceholder: backPlaceholder)
return .doubleIcon(
frontType: frontType,
frontUrl: frontUrl,
frontAlternativeUrl: frontAlternativeUrl,
frontPlaceholder: frontPlaceholder,
backType: backType,
backUrl: backUrl,
backAlternativeUrl: backAlternativeUrl,
backPlaceholder: backPlaceholder
)
}

private func iconType(source: TransactionSource, incomingValues: [TransactionValue], outgoingValues: [TransactionValue], nftMetadata: [NftUid: NftAssetBriefMetadata]) -> BaseTransactionsViewModel.IconType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ enum CellComponent {
)
}

static func amountRow(tableView: SectionsTableView, rowInfo: RowInfo, title: String, subtitle: String? = nil, imageUrl: String?, placeholderImageName: String, coinAmount: String, currencyAmount: String?, type: AmountType, action: (() -> Void)? = nil) -> RowProtocol {
static func amountRow(tableView: SectionsTableView, rowInfo: RowInfo, title: String, subtitle: String? = nil, imageUrl: String?, alternativeImageUrl: String?, placeholderImageName: String, coinAmount: String, currencyAmount: String?, type: AmountType, action: (() -> Void)? = nil) -> RowProtocol {
CellBuilderNew.row(
rootElement: .hStack([
.image32 { (component: ImageComponent) in
component.setImage(urlString: imageUrl, placeholder: UIImage(named: placeholderImageName))
component.imageView.setImage(url: imageUrl, alternativeUrl: alternativeImageUrl, placeholder: UIImage(named: placeholderImageName))
component.imageView.cornerRadius = CGFloat.iconSize32 / 2
},
.vStackCentered([
.text { (component: TextComponent) in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import Alamofire
import Kingfisher
import ComponentKit
import MarketKit
import UIKit

extension UIImageView {
func setImage(coin: Coin?, placeholder: String? = nil) {
let options: [KingfisherOptionsInfoItem] = [.scaleFactor(UIScreen.main.scale)]
let placeholder = UIImage(named: placeholder ?? "placeholder_circle_32")

if let alternativeUrlString = coin?.image, let alternativeUrl = URL(string: alternativeUrlString) {
if ImageCache.default.isCached(forKey: alternativeUrlString) {
kf.setImage(
with: alternativeUrl,
placeholder: placeholder,
options: options
)
} else {
kf.setImage(
with: URL(string: coin?.imageUrl ?? ""),
placeholder: placeholder,
options: options + [.alternativeSources([.network(alternativeUrl)])]
)
}
} else {
kf.setImage(
with: URL(string: coin?.imageUrl ?? ""),
placeholder: placeholder,
options: options
)

return
}

setImage(url: coin?.imageUrl, alternativeUrl: coin?.image, placeholder: UIImage(named: placeholder ?? "placeholder_circle_32"))
cornerRadius = CGFloat.iconSize32 / 2
}
}

0 comments on commit ac56310

Please sign in to comment.