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. 10
      Trust/Transactions/Coordinators/TicketsCoordinator.swift
  8. 1
      TrustTests/Coordinators/TokensCoordinatorTests.swift

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

@ -2,6 +2,7 @@
import Foundation import Foundation
import ObjectiveC import ObjectiveC
import TrustKeystore
struct Config { 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) { func addToWalletAddressesAlreadyPromptedForBackup(address: String) {
var addresses: [String] var addresses: [String]
if let value = defaults.array(forKey: Keys.walletAddressesAlreadyPromptedForBackUp) { if let value = defaults.array(forKey: Keys.walletAddressesAlreadyPromptedForBackUp) {

@ -13,6 +13,7 @@ protocol TokensCoordinatorDelegate: class {
class TokensCoordinator: Coordinator { class TokensCoordinator: Coordinator {
let navigationController: UINavigationController let navigationController: UINavigationController
let config: Config
let session: WalletSession let session: WalletSession
let keystore: Keystore let keystore: Keystore
var coordinators: [Coordinator] = [] var coordinators: [Coordinator] = []
@ -35,12 +36,14 @@ class TokensCoordinator: Coordinator {
init( init(
navigationController: UINavigationController = NavigationController(), navigationController: UINavigationController = NavigationController(),
config: Config,
session: WalletSession, session: WalletSession,
keystore: Keystore, keystore: Keystore,
tokensStorage: TokensDataStore tokensStorage: TokensDataStore
) { ) {
self.navigationController = navigationController self.navigationController = navigationController
self.navigationController.modalPresentationStyle = .formSheet self.navigationController.modalPresentationStyle = .formSheet
self.config = config
self.session = session self.session = session
self.keystore = keystore self.keystore = keystore
self.storage = tokensStorage self.storage = tokensStorage
@ -82,35 +85,11 @@ class TokensCoordinator: Coordinator {
// navigationController.pushViewController(controller, animated: true) // navigationController.pushViewController(controller, animated: true)
} }
//FIFA add the FIFA token with a hardcoded address if not already present //FIFA add the FIFA token with a hardcoded address for appropriate network if not already present
//TODO Handle ropsten hardcoding as well as the one for real tickets
private func addFIFAToken() { private func addFIFAToken() {
let fifaTokenPresent = storage.enabledObject.contains{ $0.address.eip55String == Constants.ticketContractAddress if let token = config.createDefaultTicketToken(), !storage.enabledObject.contains { $0.address.eip55String == token.contract.eip55String } {
storage.addCustom(token: token)
} }
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: []
)
storage.addCustom(token: token)
storage.addCustom(token: testToken)
tokensViewController.fetch() tokensViewController.fetch()
} }
} }

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

@ -14,7 +14,7 @@ class TokensViewController: UIViewController {
private let dataStore: TokensDataStore private let dataStore: TokensDataStore
var viewModel: TokensViewModel = TokensViewModel(tokens: [], tickers: .none) { var viewModel: TokensViewModel = TokensViewModel(config: Config(), tokens: [], tickers: .none) {
didSet { didSet {
viewModel.filter = oldValue.filter viewModel.filter = oldValue.filter
refreshView(viewModel: viewModel) 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 //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 { class TokensViewModel {
var config: Config
var tokens: [TokenObject] = [] { var tokens: [TokenObject] = [] {
willSet { willSet {
tokens = reorderTokensSoFIFAAtIndex1(tokens: newValue) tokens = reorderTokensSoFIFAAtIndex1(tokens: newValue)
@ -88,7 +89,11 @@ class TokensViewModel {
func canDelete(for row: Int, section: Int) -> Bool { func canDelete(for row: Int, section: Int) -> Bool {
let token = item(for: row, section: section) 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 { var footerTextColor: UIColor {
@ -100,17 +105,18 @@ class TokensViewModel {
} }
init( init(
config: Config,
tokens: [TokenObject], tokens: [TokenObject],
tickers: [String: CoinTicker]? tickers: [String: CoinTicker]?
) { ) {
self.config = config
self.tokens = reorderTokensSoFIFAAtIndex1(tokens: tokens) self.tokens = reorderTokensSoFIFAAtIndex1(tokens: tokens)
self.tickers = tickers 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 //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] { 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 { if let index = index, tokens.count >= 2 {
var reorderedTokens = tokens var reorderedTokens = tokens
let target = reorderedTokens[index] let target = reorderedTokens[index]

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

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

Loading…
Cancel
Save