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 appTracker = AppTracker()
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(
window: UIWindow,
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) {
let inCoordinatorInstance = coordinators.first {
$0 is InCoordinator

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

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

@ -36,6 +36,11 @@ class InCoordinator: Coordinator {
var keystore: Keystore
var config: Config
let appTracker: AppTracker
lazy var ethPrice: Subscribable<Double> = {
var value = Subscribable<Double>(nil)
fetchEthPrice()
return value
}()
weak var delegate: InCoordinatorDelegate?
var transactionCoordinator: TransactionCoordinator? {
return self.coordinators.flatMap {
@ -82,19 +87,25 @@ class InCoordinator: Coordinator {
addCoordinator(helpUsCoordinator)
}
func getPriceOfEther() -> Double {
func fetchEthPrice() {
let keystore = try! EtherKeystore()
let address = keystore.recentlyUsedWallet?.address
let migration = MigrationInitializer(account: keystore.recentlyUsedWallet! , chainID: config.chainID)
migration.perform()
let web3 = self.web3(for: config.server)
web3.start()
let realm = self.realm(for: migration.config)
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) {
return price
} else {
return 0
tokensStorage.updatePrices()
let etherToken = TokensDataStore.etherToken(for: config)
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] = []
weak var delegate: UniversalLinkCoordinatorDelegate?
var importTicketViewController: ImportTicketViewController?
var price: Double?
var ethPrice: Subscribable<Double>?
func start() {
preparingToImportUniversalLink()
@ -68,11 +68,28 @@ class UniversalLinkCoordinator: Coordinator {
//nil or "" implies free, if using payment server it is always free
let etherprice = signedOrder.order.price / 1000000000000000000
let etherPriceDecimal = Decimal(string: etherprice.description)!
if let price = ethPrice {
if let s = price.value {
self.promptImportUniversalLink(
ticketHolder: ticketHolder,
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
}
@ -98,7 +115,7 @@ class UniversalLinkCoordinator: Coordinator {
self.promptImportUniversalLink(
ticketHolder: ticketHolder,
ethCost: "",
dollarCost: self.price!.description
dollarCost: ""
)
}
return true
@ -110,6 +127,7 @@ class UniversalLinkCoordinator: Coordinator {
guard matchedPrefix else {
return false
}
let signedOrder = UniversalLinkHandler().parseUniversalLink(url: (url?.absoluteString)!)
getTicketDetailsAndEcRecover(signedOrder: signedOrder) {
result in
@ -303,7 +321,6 @@ extension UniversalLinkCoordinator: ImportTicketViewControllerDelegate {
if let signedOrder = viewController.signedOrder, let tokenObj = viewController.tokenObject {
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)
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