Add user to delete ERC20 tokens

pull/428/head
Hwee-Boon Yar 6 years ago
parent abbbd23d3c
commit 6117679b66
  1. 4
      AlphaWallet.xcodeproj/project.pbxproj
  2. 2
      AlphaWallet/Core/Initializers/MirgrationInitializer.swift
  3. 4
      AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift
  4. 10
      AlphaWallet/Tokens/Types/TokensDataStore.swift
  5. 13
      AlphaWallet/Tokens/ViewModels/HiddenContract.swift
  6. 12
      AlphaWallet/Tokens/ViewModels/TokensViewModel.swift

@ -334,6 +334,7 @@
5E7C776BE1B19F824954962D /* BaseTicketTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7F5C10E3895E805EA7E0 /* BaseTicketTableViewCell.swift */; };
5E7C776CF721EBBD43195926 /* GenerateSellMagicLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C79CF6150E4CD4A276FC0 /* GenerateSellMagicLinkViewController.swift */; };
5E7C7788984F7ADCFE5B4DE0 /* AddressTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C75B5AF76279A71395FC7 /* AddressTextField.swift */; };
5E7C7788FA549A0402BB33CB /* HiddenContract.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7C01F8C42D7A43792C26 /* HiddenContract.swift */; };
5E7C7793AB6B577906F2BCA3 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7AFE9AF9FE6B58C925D4 /* SettingsViewController.swift */; };
5E7C77A8425E0AFAB11F1FCD /* PromptBackupCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7ADD0FBE8708A6E98AF8 /* PromptBackupCoordinator.swift */; };
5E7C77AD9FAAC18211B6F355 /* TransferTicketsQuantitySelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7419F47CC8B2996AA8F9 /* TransferTicketsQuantitySelectionViewController.swift */; };
@ -889,6 +890,7 @@
5E7C7BA578BE5FB0E613A6D6 /* ChooseTicketTransferModeViewControllerViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChooseTicketTransferModeViewControllerViewModel.swift; sourceTree = "<group>"; };
5E7C7BD9B4BDAFC2D9EBD741 /* StatusViewControllerViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusViewControllerViewModel.swift; sourceTree = "<group>"; };
5E7C7BF09AD68C113D58344C /* LocalesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalesViewController.swift; sourceTree = "<group>"; };
5E7C7C01F8C42D7A43792C26 /* HiddenContract.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HiddenContract.swift; sourceTree = "<group>"; };
5E7C7C077372C3F2A4349FA1 /* TokenViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenViewCell.swift; sourceTree = "<group>"; };
5E7C7C2872E213BBB05D55BA /* ImportWalletTabBarViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportWalletTabBarViewModel.swift; sourceTree = "<group>"; };
5E7C7C58586099F082973073 /* WalletFilterView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletFilterView.swift; sourceTree = "<group>"; };
@ -1696,6 +1698,7 @@
5E7C74B82783A94091A43470 /* EthTokenViewCellViewModel.swift */,
5E7C7A16ABC8BD5D508AA641 /* ImportWalletHelpBubbleViewViewModel.swift */,
5E7C73DF5FBFE756097D32B1 /* EthCurrencyHelper.swift */,
5E7C7C01F8C42D7A43792C26 /* HiddenContract.swift */,
);
path = ViewModels;
sourceTree = "<group>";
@ -3649,6 +3652,7 @@
5E7C7B348A4DB36FC2D39DDF /* AssetField.swift in Sources */,
76F1D74912F5D8CDA72363BD /* GetContractInteractions.swift in Sources */,
5E7C741353DDF87133054FCC /* DeletedContract.swift in Sources */,
5E7C7788FA549A0402BB33CB /* HiddenContract.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -20,7 +20,7 @@ class MigrationInitializer: Initializer {
}
func perform() {
config.schemaVersion = 42
config.schemaVersion = 43
config.migrationBlock = { migration, oldSchemaVersion in
switch oldSchemaVersion {
case 0...32:

@ -83,7 +83,8 @@ class TokensCoordinator: Coordinator {
let detectedContracts = contracts.map { $0.lowercased() }
let alreadyAddedContracts = self.storage.enabledObject.map { $0.address.eip55String.lowercased() }
let deletedContracts = self.storage.deletedContracts.map { $0.contract.lowercased() }
let contractsToAdd = detectedContracts - alreadyAddedContracts - deletedContracts
let hiddenContracts = self.storage.hiddenContracts.map { $0.contract.lowercased() }
let contractsToAdd = detectedContracts - alreadyAddedContracts - deletedContracts - hiddenContracts
var contractsPulled = 0
var hasRefreshedAfterAddingAllContracts = false
for eachContract in contractsToAdd {
@ -285,6 +286,7 @@ extension TokensCoordinator: TokensViewControllerDelegate {
}
func didDelete(token: TokenObject, in viewController: UIViewController) {
storage.add(hiddenContracts: [HiddenContract(contract: token.contract)])
storage.delete(tokens: [token])
tokensViewController.fetch()
}

@ -113,6 +113,10 @@ class TokensDataStore {
return Array(realm.objects(DeletedContract.self))
}
var hiddenContracts: [HiddenContract] {
return Array(realm.objects(HiddenContract.self))
}
static func update(in realm: Realm, tokens: [Token]) {
realm.beginWrite()
for token in tokens {
@ -292,6 +296,12 @@ class TokensDataStore {
}
}
func add(hiddenContracts: [HiddenContract]) {
try! realm.write {
realm.add(hiddenContracts, update: false)
}
}
@discardableResult
func add(tokens: [TokenObject]) -> [TokenObject] {
realm.beginWrite()

@ -0,0 +1,13 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Foundation
import RealmSwift
class HiddenContract: Object {
@objc dynamic var contract: String = ""
convenience init(contract: String) {
self.init()
self.contract = contract
}
}

@ -12,6 +12,7 @@ class TokensViewModel {
}
}
var tickers: [String: CoinTicker]?
var etherTokenContract: String
var filter: WalletFilter = .all
var filteredTokens: [TokenObject] {
switch filter {
@ -87,11 +88,13 @@ class TokensViewModel {
func canDelete(for row: Int, section: Int) -> Bool {
let token = item(for: row, section: section)
if let ticketContractAddress = config.ticketContractAddress {
return token.isCustom && token.contract.lowercased() != ticketContractAddress.lowercased()
} else {
return token.isCustom
if etherTokenContract == token.contract {
return false
}
if let ticketContractAddress = config.ticketContractAddress, token.contract.lowercased() == ticketContractAddress.lowercased() {
return false
}
return true
}
var footerTextColor: UIColor {
@ -108,6 +111,7 @@ class TokensViewModel {
tickers: [String: CoinTicker]?
) {
self.config = config
self.etherTokenContract = TokensDataStore.etherToken(for: config).contract
self.tokens = reorderTokensSoFIFAAtIndex1(tokens: tokens)
self.tickers = tickers
}

Loading…
Cancel
Save