Skip to content

Commit

Permalink
Fix watch sync manager + shortcut manager
Browse files Browse the repository at this point in the history
  • Loading branch information
SwenVanZanten committed Apr 16, 2019
1 parent fc3a28b commit 4793a11
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 42 deletions.
4 changes: 2 additions & 2 deletions VergeiOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CF_BUNDLE_BUILD_VERSION_STRING = 201904160001;
CF_BUNDLE_BUILD_VERSION_STRING = 201904160002;
CF_BUNDLE_SHORT_VERSION_STRING = 1.0;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -2207,7 +2207,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CF_BUNDLE_BUILD_VERSION_STRING = 201904160001;
CF_BUNDLE_BUILD_VERSION_STRING = 201904160002;
CF_BUNDLE_SHORT_VERSION_STRING = 1.0;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
Expand Down
8 changes: 4 additions & 4 deletions VergeiOS/Assets/Settings.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IMz-eD-ejn">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IMz-eD-ejn">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -836,7 +836,7 @@
</view>
<sections>
<tableViewSection headerTitle="Wallet Service URL" id="aye-uN-tV6">
<string key="footerTitle">This application depends on Verge Wallet Service (VWS) for blockchain information, networking and Copayer synchronization. The default configuration points to https://vws.vergecurrency.com/vws/api (Verge's public VWS instance)</string>
<string key="footerTitle">This application depends on Verge Wallet Service (VWS) for blockchain information, networking and Copayer synchronization. The default configuration points to https://vws.vergecurrency.network/vws/api (Verge's public VWS instance)</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="VL3-dN-irb">
<rect key="frame" x="0.0" y="131.5" width="375" height="44"/>
Expand All @@ -845,7 +845,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="https://vws.vergecurrency.com/bws/api" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="EZ8-va-kPW">
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="https://vws.vergecurrency.network/bws/api" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="EZ8-va-kPW">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<constraints>
<constraint firstAttribute="height" constant="43.5" id="nBK-Yv-Ubv"/>
Expand Down
8 changes: 4 additions & 4 deletions VergeiOS/Components/Shortcuts/ShortcutsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import UIKit

class ShortcutsManager: NSObject {

private var hasWallet: Bool = false
private var applicationRepository: ApplicationRepository!

// MARK: Init

private override init() {}

init(hasWallet: Bool) {
self.hasWallet = hasWallet
init(applicationRepository: ApplicationRepository) {
self.applicationRepository = applicationRepository
}

// MARK: - Types
Expand Down Expand Up @@ -131,7 +131,7 @@ class ShortcutsManager: NSObject {
// Install initial versions of dynamic shortcuts.
if application!.shortcutItems != nil {
// Check wallet setup
let hasWallet = self.hasWallet
let hasWallet = self.applicationRepository.setup

// Construct dynamic short item #3
let websiteShortcutUserInfo = [ShortcutsManager.applicationShortcutUserInfoIconKey: "Website"]
Expand Down
31 changes: 5 additions & 26 deletions VergeiOS/Components/Watch/WatchSyncManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,11 @@ class WatchSyncManager: NSObject, WCSessionDelegate {
super.init()

self.walletClient = walletClient

NotificationCenter.default.addObserver(
self,
selector: #selector(syncCurrency),
name: .didChangeCurrency,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(syncAmount),
name: .didChangeWalletAmount,
object: nil
)

NotificationCenter.default.addObserver(
self,
selector: #selector(syncAddress(notification:)),
name: .didChangeReceiveAddress,
object: nil
)
}

// MARK: Private properties

private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil

private var validSession: WCSession? {
if let session = session, session.isPaired && session.isWatchAppInstalled {
Expand All @@ -68,12 +47,12 @@ class WatchSyncManager: NSObject, WCSessionDelegate {

//MARK: Private methods

@objc private func syncCurrency() {
@objc public func syncCurrency() {
let currency = ApplicationRepository().currency
_ = self.transferMessage(message: ["currency" : currency as AnyObject])
}

@objc private func syncAmount() {
@objc public func syncAmount() {
let balanceCredentials = self.walletClient.watchRequestCredentialsForMethodPath(path: "/v1/balance/")

if balanceCredentials.signature != nil &&
Expand All @@ -91,11 +70,11 @@ class WatchSyncManager: NSObject, WCSessionDelegate {

let amount = ApplicationRepository().amount
let currency = ApplicationRepository().currency

self.transferMessage(message: ["amount" : amount, "currency" : currency as AnyObject])
}

@objc private func syncAddress(notification: Notification? = nil) {
@objc public func syncAddress(notification: Notification? = nil) {
let address = notification?.object as! String;

if var qrCodeObject = QRCode(address) {
Expand Down
16 changes: 10 additions & 6 deletions VergeiOS/Providers/ApplicationServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import IQKeyboardManagerSwift
class ApplicationServiceProvider: ServiceProvider {

override func boot() {
self.bootWatchSyncManager()

TorStatusIndicator.shared.initialize()
NotificationManager.shared.initialize()

IQKeyboardManager.shared.enable = true

let appDelegate = UIApplication.shared.delegate as! AppDelegate
ThemeManager.shared.initialize(withWindow: appDelegate.window ?? UIWindow())

self.bootWatchSyncManager()
}

override func register() {
Expand All @@ -29,18 +29,22 @@ class ApplicationServiceProvider: ServiceProvider {
container.register(ShortcutsManager.self) { r in
let applicationRepository = r.resolve(ApplicationRepository.self)!

return ShortcutsManager(hasWallet: applicationRepository.setup)
return ShortcutsManager(applicationRepository: applicationRepository)
}.inObjectScope(.container)

container.storyboardInitCompleted (MainTabBarController.self) { r, c in
c.shortcutsManager = r.resolve(ShortcutsManager.self)
}

container.register(WatchSyncManager.self) { r in
let walletClient = r.resolve(WalletClient.self)!

return WatchSyncManager(walletClient: walletClient)
}.inObjectScope(.container)
}

private func bootWatchSyncManager() {
let walletClient = container.resolve(WalletClient.self)!

WatchSyncManager(walletClient: walletClient).startSession()
container.resolve(WatchSyncManager.self)?.startSession()
}

}
36 changes: 36 additions & 0 deletions VergeiOS/Providers/EventServiceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,35 @@ class EventServiceProvider: ServiceProvider {
override func register() {
self.nc = NotificationCenter.default

setupWatchListeners()
setupTorListeners()
setupWalletListeners()
setupFiatRatingListeners()
}

func setupWatchListeners() {
self.nc.addObserver(
self,
selector: #selector(syncWatchCurrency),
name: .didChangeCurrency,
object: nil
)

self.nc.addObserver(
self,
selector: #selector(syncWatchAmount),
name: .didChangeWalletAmount,
object: nil
)

self.nc.addObserver(
self,
selector: #selector(syncWatchAddress(notification:)),
name: .didChangeReceiveAddress,
object: nil
)
}

func setupTorListeners() {
self.nc.addObserver(
self,
Expand Down Expand Up @@ -79,6 +103,18 @@ class EventServiceProvider: ServiceProvider {
)
}

@objc func syncWatchCurrency() {
container.resolve(WatchSyncManager.self)?.syncCurrency()
}

@objc func syncWatchAmount() {
container.resolve(WatchSyncManager.self)?.syncAmount()
}

@objc func syncWatchAddress(notification: Notification? = nil) {
container.resolve(WatchSyncManager.self)?.syncAddress(notification: notification)
}

@objc func didStartTorThread(notification: Notification? = nil) {
TorStatusIndicator.shared.setStatus(.disconnected)
}
Expand Down

0 comments on commit 4793a11

Please sign in to comment.