diff --git a/AlphaWallet/AppCoordinator.swift b/AlphaWallet/AppCoordinator.swift index 7832410476..f2902320f2 100644 --- a/AlphaWallet/AppCoordinator.swift +++ b/AlphaWallet/AppCoordinator.swift @@ -224,7 +224,7 @@ class AppCoordinator: NSObject, Coordinator { private let addressStorage: FileAddressStorage private let tokenScriptOverridesFileManager = TokenScriptOverridesFileManager() - private let tokenImageFetcher: TokenImageFetcher = TokenImageFetcherImpl(networking: KingfisherImageFetcher()) + private lazy var tokenImageFetcher: TokenImageFetcher = TokenImageFetcherImpl(networking: KingfisherImageFetcher(), tokenGroupIdentifier: tokenGroupIdentifier, spamImage: R.image.spamSmall()!) private let tokenGroupIdentifier: TokenGroupIdentifierProtocol = TokenGroupIdentifier.identifier(fromFileName: "tokens")! diff --git a/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/Contents.json b/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/Contents.json new file mode 100644 index 0000000000..1f4b993d62 --- /dev/null +++ b/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "spam-small.png", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/spam-small.png b/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/spam-small.png new file mode 100644 index 0000000000..4f4989d6ac Binary files /dev/null and b/AlphaWallet/Resources/Assets.xcassets/spam-small.imageset/spam-small.png differ diff --git a/modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokenImageFetcher.swift b/modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokenImageFetcher.swift index 78132fc302..2b3af50d76 100644 --- a/modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokenImageFetcher.swift +++ b/modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokenImageFetcher.swift @@ -71,14 +71,20 @@ public protocol TokenImageFetcher { public class TokenImageFetcherImpl: TokenImageFetcher { private let networking: ImageFetcher + private let tokenGroupsIdentifier: TokenGroupIdentifierProtocol + private let spamImage: UIImage private let subscribables: AtomicDictionary> = .init() enum ImageAvailabilityError: LocalizedError { case notAvailable } - public init(networking: ImageFetcher) { + public init(networking: ImageFetcher, + tokenGroupIdentifier: TokenGroupIdentifierProtocol, + spamImage: UIImage) { self.networking = networking + self.tokenGroupsIdentifier = tokenGroupIdentifier + self.spamImage = spamImage } private static func programmaticallyGenerateIcon(for contractAddress: AlphaWallet.Address, @@ -132,12 +138,12 @@ public class TokenImageFetcherImpl: TokenImageFetcher { switch type { case .nativeCryptocurrency: - if let img = serverIconImage { - return .init(image: .image(.loaded(image: img)), isFinal: true, overlayServerIcon: nil) + if let img = iconImageForContractAndChainID(image: serverIconImage, address: contractAddress.eip55String, chainID: server.chainID) { + return TokenImage(image: .image(.loaded(image: img)), isFinal: true, overlayServerIcon: nil) } case .erc20, .erc875, .erc721, .erc721ForTickets, .erc1155: - if let img = tokenImage { - return .init(image: .image(.loaded(image: img)), isFinal: true, overlayServerIcon: staticOverlayIcon) + if let img = iconImageForContractAndChainID(image: tokenImage, address: contractAddress.eip55String, chainID: server.chainID) { + return TokenImage(image: .image(.loaded(image: img)), isFinal: true, overlayServerIcon: staticOverlayIcon) } } @@ -151,6 +157,13 @@ public class TokenImageFetcherImpl: TokenImageFetcher { blockChainNameColor: blockChainNameColor) } + private func iconImageForContractAndChainID(image iconImage: UIImage?, address: String, chainID: Int) -> UIImage? { + if tokenGroupsIdentifier.isSpam(address: address, chainID: chainID) { + return spamImage + } + return iconImage + } + public func image(contractAddress: AlphaWallet.Address, server: RPCServer, name: String,