Merge pull request #4126 from AlphaWallet/filter-spam-tokens

Add hardcoded list of spam tokens (of 1 at the moment). Remove price for tokens in the list
pull/4128/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit ace72a6f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      AlphaWallet.xcodeproj/project.pbxproj
  2. 6
      AlphaWallet/Core/CoinTicker/CoinTickersFetcher.swift
  3. 15
      AlphaWallet/Lists/SpamTokens.swift

@ -478,6 +478,7 @@
5E7C786AD8E4877C36D3B14A /* TokenAdaptorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C775FD95FE80B0F1CEA33 /* TokenAdaptorTest.swift */; };
5E7C786DB5B71302FF66CBAD /* SendTransactionErrorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7BB7DBFDF5A5E4F2DDC0 /* SendTransactionErrorViewModel.swift */; };
5E7C78772A59685C37CB99C2 /* ToolsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7AB8844E5D88BD6B2F2A /* ToolsViewController.swift */; };
5E7C787DED35E3A63E99F78F /* SpamTokens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C756B103348BA67AA0C1A /* SpamTokens.swift */; };
5E7C7883FB31565411F7C928 /* NonFungibleFromJsonTokenType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C78EBC7D0A09B8EAACBE3 /* NonFungibleFromJsonTokenType.swift */; };
5E7C788C6ACB6E5AA24216A6 /* FiatOnRampCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7AF60DF9E7FBD2933C32 /* FiatOnRampCoordinator.swift */; };
5E7C788C8830A7CF05B9189A /* OpenSea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7C0CFD047ED7C488FB45 /* OpenSea.swift */; };
@ -1448,6 +1449,7 @@
5E7C755132D9B6F95080A1BE /* TransferNFTCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferNFTCoordinator.swift; sourceTree = "<group>"; };
5E7C7553BB089397B7E74BE0 /* WalletSecurityLevelIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletSecurityLevelIndicator.swift; sourceTree = "<group>"; };
5E7C7558286761EF1ADD2988 /* ABIError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ABIError.swift; sourceTree = "<group>"; };
5E7C756B103348BA67AA0C1A /* SpamTokens.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpamTokens.swift; sourceTree = "<group>"; };
5E7C7570889AD33EA942D9A6 /* AlphaWalletAddressTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlphaWalletAddressTests.swift; sourceTree = "<group>"; };
5E7C757AEC6586F51EC75646 /* PingInfuraCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PingInfuraCoordinator.swift; sourceTree = "<group>"; };
5E7C7587F30FF1896039B8C8 /* TokenIdOrigin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenIdOrigin.swift; sourceTree = "<group>"; };
@ -2342,6 +2344,7 @@
5E7C7F1CC5699A58ED5D4E74 /* WhatsNew */,
5E7C74F0A1BB877A6FE35F37 /* FiatOnRamp */,
5E7C76487E444E00B78BAA14 /* BlockscanChat */,
5E7C72AB43EC4939E6C7D46B /* Lists */,
);
path = AlphaWallet;
sourceTree = "<group>";
@ -3668,6 +3671,14 @@
path = OpenSea;
sourceTree = "<group>";
};
5E7C72AB43EC4939E6C7D46B /* Lists */ = {
isa = PBXGroup;
children = (
5E7C756B103348BA67AA0C1A /* SpamTokens.swift */,
);
path = Lists;
sourceTree = "<group>";
};
5E7C72C3D9C939508F8EBFAC /* Models */ = {
isa = PBXGroup;
children = (
@ -6618,6 +6629,7 @@
5E7C76AFBBACDD13BEF25DA9 /* ToolsViewModel.swift in Sources */,
5E7C7126E01D824557FD7731 /* BlockscanChat.swift in Sources */,
5E7C756FDCFC0CBC6B9B427A /* BlockscanChatService.swift in Sources */,
5E7C787DED35E3A63E99F78F /* SpamTokens.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -192,11 +192,17 @@ class CoinTickersFetcher: CoinTickersFetcherType {
let pricesCacheLifetime = self.pricesCacheLifetime
let provider = self.provider
let config = self.config
let spamTokens = SpamTokens()
return firstly {
fetchSupportedTickers()
}.compactMap(on: CoinTickersFetcher.queue, { tickers -> [MappedCoinTickerId] in
let mappedTokensToCoinTickerIds = tokens.compactMap { tokenObject -> MappedCoinTickerId? in
let spamNeedle = AddressAndRPCServer(address: tokenObject.contractAddress, server: tokenObject.server)
if spamTokens.isSpamToken(spamNeedle) {
return nil
}
if let ticker = tickers.first(where: { $0.matches(tokenObject: tokenObject) }) {
let tickerId = tokenObject.overridenCoinGeckoTickerId(tickerId: ticker.id)
return MappedCoinTickerId(tickerId: tickerId, contractAddress: tokenObject.contractAddress, server: tokenObject.server)

@ -0,0 +1,15 @@
// Copyright © 2022 Stormbird PTE. LTD.
import Foundation
class SpamTokens {
//TODO: extract from tokens.json when it's ready
private let tokens: [AddressAndRPCServer] = [
AddressAndRPCServer(address: AlphaWallet.Address(string: "0x426ca1ea2406c07d75db9585f22781c096e3d0e0")!, server: .main),
AddressAndRPCServer(address: AlphaWallet.Address(string: "0x0b91b07beb67333225a5ba0259d55aee10e3a578")!, server: .polygon),
]
func isSpamToken(_ needle: AddressAndRPCServer) -> Bool {
tokens.contains(needle)
}
}
Loading…
Cancel
Save