Skip to content

Commit

Permalink
added wallet availability check
Browse files Browse the repository at this point in the history
  • Loading branch information
sidorov-panda committed Jan 9, 2020
1 parent b64cfc3 commit e420251
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
16 changes: 8 additions & 8 deletions MinterWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,7 @@
CODE_SIGN_ENTITLEMENTS = MinterWallet/MinterWallet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 242;
CURRENT_PROJECT_VERSION = 243;
DEVELOPMENT_TEAM = A26H28FPZU;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -3448,7 +3448,7 @@
INFOPLIST_FILE = "$(SRCROOT)/MinterWallet/MinterWallet-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0.21;
MARKETING_VERSION = 1.0.22;
PRODUCT_BUNDLE_IDENTIFIER = MNT.BipWallet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3469,7 +3469,7 @@
CODE_SIGN_ENTITLEMENTS = MinterWallet/MinterWallet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 242;
CURRENT_PROJECT_VERSION = 243;
DEVELOPMENT_TEAM = A26H28FPZU;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -3483,7 +3483,7 @@
INFOPLIST_FILE = "$(SRCROOT)/MinterWallet/MinterWallet-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0.21;
MARKETING_VERSION = 1.0.22;
PRODUCT_BUNDLE_IDENTIFIER = MNT.BipWallet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -3610,7 +3610,7 @@
CODE_SIGN_ENTITLEMENTS = MinterWalletTestnet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 241;
CURRENT_PROJECT_VERSION = 243;
DEVELOPMENT_TEAM = A26H28FPZU;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -3624,7 +3624,7 @@
INFOPLIST_FILE = "$(SRCROOT)/MinterWalletTestnet-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0.21;
MARKETING_VERSION = 1.0.22;
PRODUCT_BUNDLE_IDENTIFIER = MNT.BipWalletTestnet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3645,7 +3645,7 @@
CODE_SIGN_ENTITLEMENTS = MinterWalletTestnet.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 241;
CURRENT_PROJECT_VERSION = 243;
DEVELOPMENT_TEAM = A26H28FPZU;
ENABLE_BITCODE = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand All @@ -3659,7 +3659,7 @@
INFOPLIST_FILE = "$(SRCROOT)/MinterWalletTestnet-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0.21;
MARKETING_VERSION = 1.0.22;
PRODUCT_BUNDLE_IDENTIFIER = MNT.BipWalletTestnet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
2 changes: 1 addition & 1 deletion MinterWallet/Classes/Receive/Receive.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
<action selector="shareButtonDidTap:" destination="AOA-uS-VHB" eventType="touchUpInside" id="tbW-aW-mRW"/>
</connections>
</button>
<button opaque="NO" alpha="0.0" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0wP-w7-zNb" customClass="DefaultButton" customModule="MinterWallet" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0wP-w7-zNb" customClass="DefaultButton" customModule="MinterWallet" customModuleProvider="target">
<rect key="frame" x="65" y="80" width="280" height="50"/>
<constraints>
<constraint firstAttribute="width" constant="280" id="GzN-tg-eP8"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ReceiveViewController: BaseViewController, UITableViewDelegate, Controller

typealias ViewModelType = ReceiveViewModel

var viewModel: ReceiveViewModel! = ReceiveViewModel()
var viewModel: ReceiveViewModel!

func configure(with viewModel: ReceiveViewController.ViewModelType) {

Expand All @@ -41,7 +41,17 @@ class ReceiveViewController: BaseViewController, UITableViewDelegate, Controller
} else {
self?.addWalletActivityIndicator.stopAnimating()
}
}).disposed(by: disposeBag)
}).disposed(by: disposeBag)

viewModel
.output
.shouldShowPass
.map({ (val) -> Bool in
return !val
})
.asDriver(onErrorJustReturn: false)
.drive(addToWalletButton.rx.isHidden)
.disposed(by: disposeBag)
}

// MARK: -
Expand Down
34 changes: 26 additions & 8 deletions MinterWallet/Classes/Receive/ViewModel/ReceiveViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
//

import RxSwift
import RxCocoa
import PassKit
import MinterCore
import MinterMy

class ReceiveViewModel: BaseViewModel, ViewModelProtocol {

// MARK: - ViewModelProtocol

struct Dependency {

var accounts: Observable<[Account]>
}

struct Input {
Expand All @@ -26,8 +28,10 @@ class ReceiveViewModel: BaseViewModel, ViewModelProtocol {
var showViewController: Observable<UIViewController?>
var errorNotification: Observable<NotifiableError?>
var isLoadingPass: Observable<Bool>
var shouldShowPass: Observable<Bool>
}

var dependencies: ReceiveViewModel.Dependency!
var input: ReceiveViewModel.Input!
var output: ReceiveViewModel.Output!

Expand All @@ -45,39 +49,51 @@ class ReceiveViewModel: BaseViewModel, ViewModelProtocol {
private var showViewControllerSubject = PublishSubject<UIViewController?>()
private var isLoadingPassSubject = PublishSubject<Bool>()
private var errorNotificationSubject = PublishSubject<NotifiableError?>()
private var shouldShowPassSubject = BehaviorRelay(value: PKPassLibrary.isPassLibraryAvailable())

// MARK: -

var sectionsObservable: Observable<[BaseTableSectionItem]> {
return self.sections.asObservable()
}

override init() {
init(dependency: Dependency) {
super.init()

self.dependencies = dependency

input = Input(didTapAddPass: didTapAddPassSubject.asObserver())
output = Output(showViewController: showViewControllerSubject.asObservable(),
errorNotification: errorNotificationSubject.asObservable(),
isLoadingPass: isLoadingPassSubject.asObservable())
isLoadingPass: isLoadingPassSubject.asObservable(),
shouldShowPass: shouldShowPassSubject.asObservable())

bind()
}

var accounts: [Account] = [] {
didSet {
self.createSections()
}
}

func bind() {

didTapAddPassSubject.asObservable().subscribe(onNext: { [weak self] (_) in
self?.getPass()
}).disposed(by: disposableBag)

Session.shared.accounts.asDriver().drive(onNext: { [weak self] (accounts) in
self?.createSections()
dependencies
.accounts.asObservable()
.subscribe(onNext: { [weak self] (accounts) in
self?.accounts = accounts
}).disposed(by: disposableBag)
}

// MARK: -

func createSections() {
guard let accounts = Session.shared.accounts.value.first else {
guard let accounts = accounts.first else {
return
}

Expand Down Expand Up @@ -109,7 +125,7 @@ class ReceiveViewModel: BaseViewModel, ViewModelProtocol {
// MARK: - Share

func activities() -> [Any]? {
guard let account = Session.shared.accounts.value.first else {
guard let account = accounts.first else {
return nil
}

Expand All @@ -136,12 +152,14 @@ class ReceiveViewModel: BaseViewModel, ViewModelProtocol {
}

// MARK: -

let passbookManager = PassbookManager()

func getPass() {
guard let account = Session.shared.accounts.value.first else {
guard let account = accounts.first else {
return
}

let address = account.address
isLoadingPassSubject.onNext(true)
passbookManager.pass(with: "Mx" + address) { [weak self] (data, error) in
Expand Down
3 changes: 2 additions & 1 deletion MinterWallet/Classes/Root/ViewModel/RootViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class RootViewModel: BaseViewModel, ViewModelProtocol {
if let sendVC = SendRouter.sendViewController(viewModel: sendVM) {
vcs.append(sendVC)
}
let receiveVM = ReceiveViewModel()

let receiveVM = ReceiveViewModel(dependency: ReceiveViewModel.Dependency(accounts: Session.shared.accounts.asObservable()))
if let receiveVC = ReceiveRouter.receiveViewController(viewModel: receiveVM) {
vcs.append(receiveVC)
}
Expand Down
2 changes: 1 addition & 1 deletion MinterWalletUITests/MinterWalletUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MinterWalletUITests: XCTestCase {
func testSendCoinAdvancedMode() {
loginAdvancedMode()

isBalanceAvailable()
// isBalanceAvailable()

if self.app.tabBars.buttons["Send"].exists {
self.app.tabBars.buttons["Send"].tap()
Expand Down

0 comments on commit e420251

Please sign in to comment.