Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic to use an internal SpamToken image to TokenImageFetcherImpl instead of fetching it over the network #6657

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion AlphaWallet/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")!

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "spam-small.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CurrentValueSubject<TokenImage?, Never>> = .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,
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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,
Expand Down