Skip to content

Commit

Permalink
[FEATURE] Adds a new StellarAccountService framework for the app
Browse files Browse the repository at this point in the history
* Moves Stellar SDK integration from the iOS target to a new StellarAccountService
* Bumps version to 2.4.0
* Implements account migrator for old keychain data format
* Implements new StellarTradeService + app structural updates to support integrating it
* Integrated new StellarAccountService with app
* Refactor WalletViewController / WalletPickingViewController
* Updates tests to compile / pass with StellarAccountService integration
* Converted static operation methods for fetching data into Asynchornous operation subclasses
* Correct presentation of inflation view controller
* Correct view controller containment + starting to add response delegates
* Refactor ContactViewController apart into VC / DataSource
* Removing lazy properties for view controllers we know always should be loaded
* Fix copy button image after setting copy as a template image
* Fix trade view controller segmented colours
  • Loading branch information
ndizazzo committed Oct 29, 2018
1 parent 9809684 commit 546ec16
Show file tree
Hide file tree
Showing 129 changed files with 6,178 additions and 3,068 deletions.
122 changes: 70 additions & 52 deletions BlockEQ.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions BlockEQ.xcodeproj/xcshareddata/xcschemes/BlockEQ.xcscheme
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:BlockEQ.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "C5F1C9CE217A7B60001C847A"
BuildableName = "StellarAccountService.framework"
BlueprintName = "StellarAccountService"
ReferencedContainer = "container:StellarAccountService.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
3 changes: 3 additions & 0 deletions BlockEQ.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions BlockEQ/AppDelegate.swift
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2018 BlockEQ. All rights reserved.
//

import UIKit
import StellarAccountService
import os.log

@UIApplicationMain
Expand Down Expand Up @@ -36,6 +36,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
animated: false,
completion: nil)
} else {
appCoordinator.core = StellarCoreService(with: .production)

onboardingContainer = false
container.moveToViewController(appCoordinator.tabController,
fromViewController: nil,
Expand Down Expand Up @@ -93,8 +95,9 @@ extension AppDelegate: ApplicationCoordinatorDelegate {
}

extension AppDelegate: OnboardingCoordinatorDelegate {
func onboardingCompleted() {
func onboardingCompleted(service: StellarCoreService) {
onboardingContainer = false
appCoordinator.core = service
container.moveToViewController(appCoordinator.tabController,
fromViewController: onboardingCoordinator.navController,
animated: true,
Expand Down
68 changes: 68 additions & 0 deletions BlockEQ/Coordinators/AddressCoordinator.swift
@@ -0,0 +1,68 @@
//
// AddressResolver.swift
// BlockEQ
//
// Created by Nick DiZazzo on 2018-10-24.
// Copyright © 2018 BlockEQ. All rights reserved.
//

import StellarAccountService

final class AddressResolver {
enum AddressType {
case exchange
case contact
}

static let shared = AddressResolver()

private var mappedExchanges: [String: Exchange] = [:]
private var mappedContacts: [String: LocalContact] = [:]

private init() {
loadExchangeData()

let contacts: [LocalContact] = []
mappedContacts = contacts.reduce(into: [:]) { map, contact in
map[contact.address] = contact
}
}

static func lookup(address: StellarAddress) -> AddressType {
return .exchange
}

static func resolve(address: StellarAddress) -> LocalContact? {
let type = lookup(address: address)
guard type == .contact else { return nil }

if let contact = shared.mappedContacts[address.string] {
return contact
}

return nil
}

static func resolve(address: StellarAddress) -> Exchange? {
let type = lookup(address: address)
guard type == .exchange else { return nil }

if let exchange = shared.mappedExchanges[address.string] {
return exchange
}

return nil
}

private func loadExchangeData() {
let decoder = JSONDecoder()
guard let path = Bundle.main.path(forResource: "exchanges", ofType: "json") else { return }

if let localExchangeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe),
let decodedExchanges = try? decoder.decode([Exchange].self, from: localExchangeData) {
mappedExchanges = decodedExchanges.reduce(into: [:]) { map, exchange in
map[exchange.address] = exchange
}
}
}
}
121 changes: 92 additions & 29 deletions BlockEQ/Coordinators/ApplicationCoordinator+Extensions.swift
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2018 BlockEQ. All rights reserved.
//

import StellarAccountService

extension ApplicationCoordinator: AuthenticationCoordinatorDelegate {
func authenticationCancelled(_ coordinator: AuthenticationCoordinator,
options: AuthenticationCoordinator.AuthenticationContext) {
Expand Down Expand Up @@ -43,29 +45,37 @@ extension ApplicationCoordinator: AuthenticationCoordinatorDelegate {
}

extension ApplicationCoordinator: WalletViewControllerDelegate {
func selectedSend(_ viewController: WalletViewController, account: StellarAccount, index: Int) {
let sendVC = SendViewController(stellarAccount: account, currentAssetIndex: index)
let container = AppNavigationController(rootViewController: sendVC)
func selectedWalletSwitch(_ viewController: WalletViewController) {
guard let account = core?.accountService.account else { return }

let walletSwitchVC = WalletSwitchingViewController()
let container = AppNavigationController(rootViewController: walletSwitchVC)
container.navigationBar.prefersLargeTitles = true
walletViewController.navigationContainer = container

sendViewController = sendVC
walletSwitchingViewController = walletSwitchVC

walletSwitchVC.delegate = self
walletSwitchVC.updateMenu(account: account)

tabController.present(container, animated: true, completion: nil)
}

func selectedWalletSwitch(_ viewController: WalletViewController, account: StellarAccount) {
let walletSwitchVC = WalletSwitchingViewController()
let container = AppNavigationController(rootViewController: walletSwitchVC)
func selectedSend(_ viewController: WalletViewController, for asset: StellarAsset) {
guard let account = core?.accountService.account else { return }

let sendVC = SendViewController(stellarAccount: account, asset: asset)
let container = AppNavigationController(rootViewController: sendVC)
container.navigationBar.prefersLargeTitles = true

walletSwitchingViewController = walletSwitchVC
walletSwitchVC.delegate = self
walletSwitchVC.updateMenu(stellarAccount: account)
sendViewController = sendVC

tabController.present(container, animated: true, completion: nil)
}

func selectedReceive(_ viewController: WalletViewController, account: StellarAccount) {
func selectedReceive(_ viewController: WalletViewController) {
guard let account = core?.accountService.account else { return }

let address = account.accountId
let receiveVC = ReceiveViewController(address: address, isPersonalToken: false)
let container = AppNavigationController(rootViewController: receiveVC)
Expand All @@ -76,8 +86,10 @@ extension ApplicationCoordinator: WalletViewControllerDelegate {
tabController.present(container, animated: true, completion: nil)
}

func selectBalance(account: StellarAccount, index: Int) {
let balanceVC = BalanceViewController(stellarAccount: account, stellarAsset: account.assets[index])
func selectBalance(_ viewController: WalletViewController, for asset: StellarAsset) {
guard let account = core?.accountService.account else { return }

let balanceVC = BalanceViewController(stellarAccount: account, stellarAsset: asset)
let container = AppNavigationController(rootViewController: balanceVC)
container.navigationBar.prefersLargeTitles = true

Expand Down Expand Up @@ -107,35 +119,67 @@ extension ApplicationCoordinator: WalletViewControllerDelegate {
}

extension ApplicationCoordinator: WalletSwitchingViewControllerDelegate {
func didSelectSetInflation(inflationDestination: String?) {
let inflationViewController = InflationViewController(inflationDestination: inflationDestination)
self.inflationViewController = inflationViewController
func selectedAddAsset() {
let addAssetViewController = AddAssetViewController()
self.addAssetViewController = addAssetViewController
addAssetViewController.delegate = self

wrappingNavController?.pushViewController(inflationViewController, animated: true)
if let container = walletViewController.navigationContainer {
container.pushViewController(addAssetViewController, animated: true)
} else {
wrappingNavController?.pushViewController(addAssetViewController, animated: true)
}
}

func didSelectAddAsset() {
let addAssetViewController = AddAssetViewController()
addAssetViewController.delegate = self
self.addAssetViewController = addAssetViewController
func updateInflation(destination: StellarAddress) {
guard let account = core?.accountService.account else { return }

wrappingNavController?.pushViewController(addAssetViewController, animated: true)
let inflationViewController = InflationViewController(account: account, inflationDestination: destination)
self.inflationViewController = inflationViewController

if let container = walletViewController.navigationContainer {
container.pushViewController(inflationViewController, animated: true)
} else {
wrappingNavController?.pushViewController(inflationViewController, animated: true)
}
}

func didSelectAsset(index: Int) {
walletViewController.selectAsset(at: index)
func switchWallet(to asset: StellarAsset) {
guard let account = core?.accountService.account else { return }
walletViewController.update(with: account, asset: asset)
}

func reloadAssets() {
walletViewController.getAccountDetails()
func createTrustLine(to address: StellarAddress, for asset: StellarAsset) { }

func reloadAssets() { }

func remove(asset: StellarAsset) {
guard let account = core?.accountService.account, let walletVC = walletSwitchingViewController else {
return
}

account.changeTrust(asset: asset, remove: true, delegate: walletVC)
}

func add(asset: StellarAsset) {
guard let account = core?.accountService.account, let walletVC = walletSwitchingViewController else {
return
}

account.changeTrust(asset: asset, remove: false, delegate: walletVC)
}
}

extension ApplicationCoordinator: AddAssetViewControllerDelegate {
func didAddAsset(stellarAccount: StellarAccount) {
reloadAssets()
func requestedAdd(_ viewController: AddAssetViewController, asset: StellarAsset) {

walletSwitchingViewController?.updateMenu(stellarAccount: stellarAccount)
guard let account = core?.accountService.account, let walletVC = walletSwitchingViewController else {
return
}

walletVC.displayAddPrompt()

account.changeTrust(asset: asset, remove: false, delegate: walletVC)
}
}

Expand All @@ -151,3 +195,22 @@ extension ApplicationCoordinator: ContactsViewControllerDelegate {
tabController.present(container, animated: true, completion: nil)
}
}

extension ApplicationCoordinator: StellarAccountServiceDelegate {
func accountUpdated(_ service: StellarAccountService, account: StellarAccount, opts: StellarAccount.UpdateOptions) {
if opts.contains(.effects) || opts.contains(.account) {
self.walletViewController.update(with: account)
}

self.tradingCoordinator.update(with: account)
}

func accountInactive(_ service: StellarAccountService, account: StellarAccount) {
self.walletViewController.update(with: account)
self.tradingCoordinator.update(with: account)
}

func paymentReceived(_ service: StellarAccountService, operation: StellarOperation) {
print("account operation: \(operation)")
}
}

0 comments on commit 546ec16

Please sign in to comment.