Merge branch 'sellFunctionLink' of https://github.com/James-Sangalli/alpha-wallet-ios into sellFunctionLink

pull/196/head
James Sangalli 7 years ago
commit 626af26016
  1. 19
      Trust/AppCoordinator.swift
  2. 3
      Trust/AppDelegate.swift
  3. 6
      Trust/EtherClient/CoinMarket/Types/CoinTicker.swift
  4. 23
      Trust/InCoordinator.swift
  5. 27
      Trust/Market/Coordinators/UniversalLinkCoordinator.swift
  6. 24
      TrustTests/Coordinators/AppCoordinatorTests.swift

@ -16,6 +16,16 @@ class AppCoordinator: NSObject, Coordinator {
private var keystore: Keystore private var keystore: Keystore
private var appTracker = AppTracker() private var appTracker = AppTracker()
var coordinators: [Coordinator] = [] var coordinators: [Coordinator] = []
var inCoordinator: InCoordinator? {
return coordinators.first { $0 is InCoordinator } as? InCoordinator
}
var ethPrice: Subscribable<Double>? {
if let inCoordinator = inCoordinator {
return inCoordinator.ethPrice
} else {
return nil
}
}
init( init(
window: UIWindow, window: UIWindow,
keystore: Keystore, keystore: Keystore,
@ -95,15 +105,6 @@ class AppCoordinator: NSObject, Coordinator {
) )
} }
func getPriceOfEther() -> Double {
let incoordinator = coordinators.first { $0 is InCoordinator }
if let incoordinator = incoordinator as? InCoordinator {
return incoordinator.getPriceOfEther()
} else {
return 0
}
}
func importPaidSignedOrder(signedOrder: SignedOrder, tokenObject: TokenObject, completion: @escaping (Bool) -> Void) { func importPaidSignedOrder(signedOrder: SignedOrder, tokenObject: TokenObject, completion: @escaping (Bool) -> Void) {
let inCoordinatorInstance = coordinators.first { let inCoordinatorInstance = coordinators.first {
$0 is InCoordinator $0 is InCoordinator

@ -1,5 +1,4 @@
// Copyright SIX DAY LLC. All rights reserved. // Copyright SIX DAY LLC. All rights reserved.
import UIKit import UIKit
import Lokalise import Lokalise
import Branch import Branch
@ -86,7 +85,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
let url = userActivity.webpageURL let url = userActivity.webpageURL
universalLinkCoordinator = UniversalLinkCoordinator() universalLinkCoordinator = UniversalLinkCoordinator()
universalLinkCoordinator.price = appCoordinator.getPriceOfEther() universalLinkCoordinator.ethPrice = appCoordinator.ethPrice
universalLinkCoordinator.delegate = self universalLinkCoordinator.delegate = self
universalLinkCoordinator.start() universalLinkCoordinator.start()
let handled = universalLinkCoordinator.handleUniversalLink(url: url) let handled = universalLinkCoordinator.handleUniversalLink(url: url)

@ -6,11 +6,7 @@ import RealmSwift
struct CoinTicker: Codable { struct CoinTicker: Codable {
let id: String let id: String
let symbol: String let symbol: String
var price: String { var price: String
didSet {
print("here")
}
}
let percent_change_24h: String let percent_change_24h: String
let contract: String let contract: String
let image: String let image: String

@ -36,6 +36,11 @@ class InCoordinator: Coordinator {
var keystore: Keystore var keystore: Keystore
var config: Config var config: Config
let appTracker: AppTracker let appTracker: AppTracker
lazy var ethPrice: Subscribable<Double> = {
var value = Subscribable<Double>(nil)
fetchEthPrice()
return value
}()
weak var delegate: InCoordinatorDelegate? weak var delegate: InCoordinatorDelegate?
var transactionCoordinator: TransactionCoordinator? { var transactionCoordinator: TransactionCoordinator? {
return self.coordinators.flatMap { return self.coordinators.flatMap {
@ -82,19 +87,25 @@ class InCoordinator: Coordinator {
addCoordinator(helpUsCoordinator) addCoordinator(helpUsCoordinator)
} }
func getPriceOfEther() -> Double { func fetchEthPrice() {
let keystore = try! EtherKeystore() let keystore = try! EtherKeystore()
let address = keystore.recentlyUsedWallet?.address
let migration = MigrationInitializer(account: keystore.recentlyUsedWallet! , chainID: config.chainID) let migration = MigrationInitializer(account: keystore.recentlyUsedWallet! , chainID: config.chainID)
migration.perform() migration.perform()
let web3 = self.web3(for: config.server) let web3 = self.web3(for: config.server)
web3.start() web3.start()
let realm = self.realm(for: migration.config) let realm = self.realm(for: migration.config)
let tokensStorage = TokensDataStore(realm: realm, account: keystore.recentlyUsedWallet!, config: config, web3: web3) let tokensStorage = TokensDataStore(realm: realm, account: keystore.recentlyUsedWallet!, config: config, web3: web3)
if let rates = tokensStorage.tickers, let ticker = rates.values.first(where: { $0.symbol == "ETH" }), let price = Double(ticker.price) { tokensStorage.updatePrices()
return price
} else { let etherToken = TokensDataStore.etherToken(for: config)
return 0 tokensStorage.tokensModel.subscribe {[weak self] tokensModel in
guard let tokens = tokensModel, let eth = tokens.first(where: { $0 == etherToken }) else {
return
}
var ticker = tokensStorage.coinTicker(for: eth)
if let ticker = ticker {
self?.ethPrice.value = Double(ticker.price)
}
} }
} }

@ -16,7 +16,7 @@ class UniversalLinkCoordinator: Coordinator {
var coordinators: [Coordinator] = [] var coordinators: [Coordinator] = []
weak var delegate: UniversalLinkCoordinatorDelegate? weak var delegate: UniversalLinkCoordinatorDelegate?
var importTicketViewController: ImportTicketViewController? var importTicketViewController: ImportTicketViewController?
var price: Double? var ethPrice: Subscribable<Double>?
func start() { func start() {
preparingToImportUniversalLink() preparingToImportUniversalLink()
@ -68,11 +68,28 @@ class UniversalLinkCoordinator: Coordinator {
//nil or "" implies free, if using payment server it is always free //nil or "" implies free, if using payment server it is always free
let etherprice = signedOrder.order.price / 1000000000000000000 let etherprice = signedOrder.order.price / 1000000000000000000
let etherPriceDecimal = Decimal(string: etherprice.description)! let etherPriceDecimal = Decimal(string: etherprice.description)!
if let price = ethPrice {
if let s = price.value {
self.promptImportUniversalLink( self.promptImportUniversalLink(
ticketHolder: ticketHolder, ticketHolder: ticketHolder,
ethCost: etherPriceDecimal.description, ethCost: etherPriceDecimal.description,
dollarCost: self.price!.description dollarCost: s.description)
) } else {
price.subscribe { value in
//TODO good to test if there's a leak here if user has already cancelled before this
if let s = price.value {
self.promptImportUniversalLink(
ticketHolder: ticketHolder,
ethCost: etherPriceDecimal.description,
dollarCost: s.description)
}
}
}
} else {
//No wallet and should be handled by client code, but we'll just be careful
//TODO pass in error message
showImportError(errorMessage: R.string.localizable.aClaimTicketFailedTitle())
}
} }
return true return true
} }
@ -98,7 +115,7 @@ class UniversalLinkCoordinator: Coordinator {
self.promptImportUniversalLink( self.promptImportUniversalLink(
ticketHolder: ticketHolder, ticketHolder: ticketHolder,
ethCost: "", ethCost: "",
dollarCost: self.price!.description dollarCost: ""
) )
} }
return true return true
@ -110,6 +127,7 @@ class UniversalLinkCoordinator: Coordinator {
guard matchedPrefix else { guard matchedPrefix else {
return false return false
} }
let signedOrder = UniversalLinkHandler().parseUniversalLink(url: (url?.absoluteString)!) let signedOrder = UniversalLinkHandler().parseUniversalLink(url: (url?.absoluteString)!)
getTicketDetailsAndEcRecover(signedOrder: signedOrder) { getTicketDetailsAndEcRecover(signedOrder: signedOrder) {
result in result in
@ -303,7 +321,6 @@ extension UniversalLinkCoordinator: ImportTicketViewControllerDelegate {
if let signedOrder = viewController.signedOrder, let tokenObj = viewController.tokenObject { if let signedOrder = viewController.signedOrder, let tokenObj = viewController.tokenObject {
importPaidSignedOrder(signedOrder: signedOrder, tokenObject: tokenObj) importPaidSignedOrder(signedOrder: signedOrder, tokenObject: tokenObj)
} }
//kkk look for the call to showImportSuccessful(). Need to call this
} }
} }
} }

@ -84,4 +84,28 @@ class AppCoordinatorTests: XCTestCase {
XCTAssertEqual(1, coordinator.coordinators.count) XCTAssertEqual(1, coordinator.coordinators.count)
XCTAssertTrue(coordinator.navigationController.viewControllers[0] is UITabBarController) XCTAssertTrue(coordinator.navigationController.viewControllers[0] is UITabBarController)
} }
func testHasInCoordinatorWithWallet() {
let coordinator = AppCoordinator(
window: UIWindow(),
keystore: FakeKeystore(
wallets: [.make()]
)
)
coordinator.start()
XCTAssertNotNil(coordinator.inCoordinator)
}
func testHasNoInCoordinatorWithoutWallets() {
let coordinator = AppCoordinator(
window: UIWindow(),
keystore: FakeKeystore()
)
coordinator.start()
XCTAssertNil(coordinator.inCoordinator)
}
} }

Loading…
Cancel
Save