Merge branch 'master' into remove-dup-transfer-import-window

pull/303/head
James Sangalli 7 years ago committed by GitHub
commit cf46093772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Trust/InCoordinator.swift
  2. 31
      Trust/Settings/Types/Config.swift
  3. 33
      Trust/Tokens/Coordinators/TokensCoordinator.swift
  4. 2
      Trust/Tokens/Types/TokensDataStore.swift
  5. 2
      Trust/Tokens/ViewControllers/TokensViewController.swift
  6. 12
      Trust/Tokens/ViewModels/TokensViewModel.swift
  7. 8
      Trust/Transactions/Coordinators/TicketsCoordinator.swift
  8. 1
      TrustTests/Coordinators/TokensCoordinatorTests.swift

@ -164,6 +164,7 @@ class InCoordinator: Coordinator {
if inCoordinatorViewModel.tokensAvailable {
let tokensCoordinator = TokensCoordinator(
config: config,
session: session,
keystore: keystore,
tokensStorage: alphaWalletTokensStorage

@ -2,6 +2,7 @@
import Foundation
import ObjectiveC
import TrustKeystore
struct Config {
@ -125,6 +126,36 @@ struct Config {
}
}
var ticketContractAddress: String? {
return createDefaultTicketToken()?.contract.eip55String
}
//TODO better to have a ERC875Token type instead
func createDefaultTicketToken() -> ERC20Token? {
switch server {
case .main:
return ERC20Token(
contract: Address(string: Constants.ticketContractAddress)!,
name: "Tickets",
symbol: "TICK",
decimals: 0,
isStormBird: true,
balance: []
)
case .ropsten:
return ERC20Token(
contract: Address(string: Constants.ticketContractAddressRopsten)!,
name: "Test Tickets",
symbol: "AWTT",
decimals: 0,
isStormBird: true,
balance: []
)
case .kovan, .rinkeby, .poa, .sokol, .classic, .callisto, .custom:
return nil
}
}
func addToWalletAddressesAlreadyPromptedForBackup(address: String) {
var addresses: [String]
if let value = defaults.array(forKey: Keys.walletAddressesAlreadyPromptedForBackUp) {

@ -13,6 +13,7 @@ protocol TokensCoordinatorDelegate: class {
class TokensCoordinator: Coordinator {
let navigationController: UINavigationController
let config: Config
let session: WalletSession
let keystore: Keystore
var coordinators: [Coordinator] = []
@ -35,12 +36,14 @@ class TokensCoordinator: Coordinator {
init(
navigationController: UINavigationController = NavigationController(),
config: Config,
session: WalletSession,
keystore: Keystore,
tokensStorage: TokensDataStore
) {
self.navigationController = navigationController
self.navigationController.modalPresentationStyle = .formSheet
self.config = config
self.session = session
self.keystore = keystore
self.storage = tokensStorage
@ -82,35 +85,11 @@ class TokensCoordinator: Coordinator {
// navigationController.pushViewController(controller, animated: true)
}
//FIFA add the FIFA token with a hardcoded address if not already present
//TODO Handle ropsten hardcoding as well as the one for real tickets
//FIFA add the FIFA token with a hardcoded address for appropriate network if not already present
private func addFIFAToken() {
let fifaTokenPresent = storage.enabledObject.contains{ $0.address.eip55String == Constants.ticketContractAddress
}
if fifaTokenPresent {
return
}
//for now just add both
let token = ERC20Token(
contract: Address(string: Constants.ticketContractAddress)!,
name: "Tickets",
symbol: "TICK",
decimals: 0,
isStormBird: true,
balance: []
)
let testToken = ERC20Token(
contract: Address(string: Constants.ticketContractAddressRopsten)!,
name: "Test Tickets",
symbol: "AWTT",
decimals: 0,
isStormBird: true,
balance: []
)
if let token = config.createDefaultTicketToken(), !storage.enabledObject.contains { $0.address.eip55String == token.contract.eip55String } {
storage.addCustom(token: token)
storage.addCustom(token: testToken)
}
tokensViewController.fetch()
}
}

@ -227,7 +227,7 @@ class TokensDataStore {
}
func updateDelegate() {
tokensModel.value = enabledObject
let tokensViewModel = TokensViewModel( tokens: enabledObject, tickers: tickers )
let tokensViewModel = TokensViewModel(config: config, tokens: enabledObject, tickers: tickers)
delegate?.didUpdate(result: .success( tokensViewModel ))
}

@ -14,7 +14,7 @@ class TokensViewController: UIViewController {
private let dataStore: TokensDataStore
var viewModel: TokensViewModel = TokensViewModel(tokens: [], tickers: .none) {
var viewModel: TokensViewModel = TokensViewModel(config: Config(), tokens: [], tickers: .none) {
didSet {
viewModel.filter = oldValue.filter
refreshView(viewModel: viewModel)

@ -5,6 +5,7 @@ import UIKit
//Must be a class, and not a struct, otherwise changing `filter` will silently create a copy of TokensViewModel when user taps to change the filter in the UI and break filtering
class TokensViewModel {
var config: Config
var tokens: [TokenObject] = [] {
willSet {
tokens = reorderTokensSoFIFAAtIndex1(tokens: newValue)
@ -88,7 +89,11 @@ class TokensViewModel {
func canDelete(for row: Int, section: Int) -> Bool {
let token = item(for: row, section: section)
return token.isCustom && token.contract.lowercased() != Constants.ticketContractAddress.lowercased()
if let ticketContractAddress = config.ticketContractAddress {
return token.isCustom && token.contract.lowercased() != ticketContractAddress.lowercased()
} else {
return token.isCustom
}
}
var footerTextColor: UIColor {
@ -100,17 +105,18 @@ class TokensViewModel {
}
init(
config: Config,
tokens: [TokenObject],
tickers: [String: CoinTicker]?
) {
self.config = config
self.tokens = reorderTokensSoFIFAAtIndex1(tokens: tokens)
self.tickers = tickers
}
//FIFA make the FIFA token be index 1. Can remove the function and replace with the argument when we no longer need this
private func reorderTokensSoFIFAAtIndex1(tokens: [TokenObject]) -> [TokenObject] {
let index = tokens.index { $0.address.eip55String == Constants.ticketContractAddress
}
let index = tokens.index { $0.address.eip55String == config.ticketContractAddress }
if let index = index, tokens.count >= 2 {
var reorderedTokens = tokens
let target = reorderedTokens[index]

@ -264,12 +264,14 @@ class TicketsCoordinator: NSObject, Coordinator {
return controller
}
//TODO should be returning `String?` instead by only calling `Config().ticketContractAddress`
public static func getContractAddressForLinks() -> String {
if Config().chainID == 1 {
return Constants.ticketContractAddress
}
if let address = Config().ticketContractAddress {
return address
} else {
return Constants.ticketContractAddressRopsten
}
}
private func generateTransferLink(ticketHolder: TicketHolder, paymentFlow: PaymentFlow) -> String {
let timestamp = Int(NSDate().timeIntervalSince1970) + 86400

@ -8,6 +8,7 @@ class TokensCoordinatorTests: XCTestCase {
func testRootViewController() {
let coordinator = TokensCoordinator(
navigationController: FakeNavigationController(),
config: .make(),
session: .make(),
keystore: FakeKeystore(),
tokensStorage: FakeTokensDataStore()

Loading…
Cancel
Save