Skip to content

Commit

Permalink
https://github.com/BeamMW/ios-wallet/issues/366
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Feb 4, 2020
1 parent 6796b42 commit 5e2027b
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 185 deletions.
242 changes: 98 additions & 144 deletions BeamWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion BeamWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UserDefaults.standard.synchronize()
})
}

return true
}

func before(value1: String, value2: String) -> Bool {
let ch1 = value1.first
let l1 = ch1!.isLetter
if (!l1) {
return false
}

let ch2 = value2.first
let l2 = ch2!.isLetter
if (!l2) {
return false
}

return value1.lowercased() < value2.lowercased()
}


public func logout() {
AppModel.sharedManager().clearAllCategories()
AppModel.sharedManager().isLoggedin = false
Expand Down
2 changes: 2 additions & 0 deletions BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
-(void)clearAllTransactions;
-(BMTransaction*_Nullable)lastTransactionFromAddress:(NSString*_Nonnull)ID;
-(NSString*_Nullable)getFirstTransactionIdForAddress:(NSString*_Nonnull)address;
-(BOOL)hasActiveTransactions;

// utxo
-(void)getUTXO;
Expand All @@ -211,6 +212,7 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
-(NSMutableArray<BMContact*>*_Nonnull)getOnlyContactsFromCategory:(BMCategory*_Nonnull)category;
-(void)fixCategories;
-(void)clearAllCategories;
-(NSMutableArray<BMCategory*>*_Nonnull)sortedCategories;

//fork
-(BOOL)isFork;
Expand Down
60 changes: 60 additions & 0 deletions BeamWallet/BeamSDK/AppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ -(id)init{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActiveNotification) name:UIApplicationDidBecomeActiveNotification object:nil];

[self loadRules];


return self;
}
Expand Down Expand Up @@ -1894,6 +1895,18 @@ -(NSString*_Nullable)getFirstTransactionIdForAddress:(NSString*_Nonnull)address
return _id;
}

-(BOOL)hasActiveTransactions {
for (BMTransaction *tr in self.transactions.reverseObjectEnumerator)
{
if(tr.enumStatus == BMTransactionStatusPending || tr.enumStatus == BMTransactionStatusInProgress
|| tr.enumStatus == BMTransactionStatusRegistering) {
return YES;
}
}

return NO;
}

#pragma mark - UTXO

-(void)setUtxos:(NSMutableArray<BMUTXO *> *)utxos {
Expand Down Expand Up @@ -2163,6 +2176,53 @@ -(void)clearAllCategories {
}
}

-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[collation sectionTitles] count]; //section count is take from sectionTitles and not sectionIndexTitles
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];

//create an array to hold the data for each section
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}

//put each object into a section
for (id object in array)
{
NSInteger index = [collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];

//sort each section
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}

-(NSMutableArray<BMCategory*>*_Nonnull)sortedCategories {
NSArray *sections = [self partitionObjects:_categories collationStringSelector:@selector(name)];

NSMutableArray *sorted = [NSMutableArray array];

for (NSArray *arr in sections) {
if(arr.count > 0) {
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name"
ascending:YES];
NSArray *sortedArray = [arr sortedArrayUsingDescriptors:@[sortDescriptor]];

[sorted addObjectsFromArray:sortedArray];
}
}

return sorted;
}

-(void)fixCategories {
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"fix"] intValue]==1) {
return;
Expand Down
4 changes: 2 additions & 2 deletions BeamWallet/BeamSDK/WalletModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ class WalletModel : public beam::wallet::WalletClient
void onImportDataFromJson(bool isOk) override;
void onExportDataToJson(const std::string& data) override;
void onPostFunctionToClientContext(MessageFunction&& func) override;
// void onExportTxHistoryToCsv(const std::string& data) override;
//void onAddressesChanged(beam::wallet::ChangeAction, const std::vector<beam::wallet::WalletAddress>& addresses) override;
void onExportTxHistoryToCsv(const std::string& data) override;
// void onAddressesChanged(beam::wallet::ChangeAction, const std::vector<beam::wallet::WalletAddress>& addresses) override;
};
16 changes: 5 additions & 11 deletions BeamWallet/BeamSDK/WalletModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@

void WalletModel::onTxStatus(beam::wallet::ChangeAction action, const std::vector<beam::wallet::TxDescription>& items)
{
NSLog(@"onTxStatus");

NSMutableArray *transactions = [NSMutableArray new];

for (const auto& item : items)
Expand Down Expand Up @@ -720,17 +718,13 @@

}

//void WalletModel::onExportTxHistoryToCsv(const std::string& data) {
//
//}
void WalletModel::onExportTxHistoryToCsv(const std::string& data) {

}

//void WalletModel::onAddressesChanged (beam::wallet::ChangeAction action, const std::vector <beam::wallet::WalletAddress > &items) {
// if(items[0].isOwn()) {
// getAsync()->getAddresses(true);
// }
// else{
// getAsync()->getAddresses(false);
// }
// getAsync()->getAddresses(true);
// getAsync()->getAddresses(false);
//}


Expand Down
7 changes: 4 additions & 3 deletions BeamWallet/Controls/BMCountdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import Foundation

public class BMCountdownView: UIView {
private var lineWidth: CGFloat = 1.5
private var lineColor: UIColor = UIColor.init(hexString: "#032E49")
private var trailLineColor: UIColor = UIColor.main.steelGrey.withAlphaComponent(0.3)

var lineColor: UIColor = UIColor.init(hexString: "#032E49")
var trailLineColor: UIColor = UIColor.main.steelGrey.withAlphaComponent(0.3)

public weak var delegate: BMCountdownViewDelegate?

Expand All @@ -37,7 +38,7 @@ public class BMCountdownView: UIView {
private var interval: TimeInterval = 1
private let fireInterval: TimeInterval = 0.01

private lazy var counterLabel: UILabel = {
lazy var counterLabel: UILabel = {
let label = UILabel()
self.addSubview(label)

Expand Down
5 changes: 4 additions & 1 deletion BeamWallet/Controls/BMDataPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,13 @@ class BMDataPickerViewController: BaseTableViewController {
if selectedCategories.count == 0 {
selectedCategories.append("0")
}

let none = BMCategory.none()
none.name = none.name.capitalizingFirstLetter()
var categories = (AppModel.sharedManager().categories as! [BMCategory])

var categories = AppModel.sharedManager().sortedCategories() as! [BMCategory]
categories.insert(none, at: 0)

for category in categories {
let selected = selectedCategories.contains(String(category.id))
values.append(BMPickerData(title: category.name, detail: nil, titleColor: UIColor(hexString: category.color), arrowType: selected ? BMPickerData.ArrowType.selected : BMPickerData.ArrowType.unselected, unique: category.id, multiplie: true))
Expand Down
19 changes: 15 additions & 4 deletions BeamWallet/Controls/BMInputViewController.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
//
// BMInputViewController.swift
// BeamWallet
// BMInputViewController.swift
// BeamWallet
//
// Created by Denis on 10/21/19.
// Copyright © 2019 Denis. All rights reserved.
// Copyright 2018 Beam Development
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit
Expand Down
85 changes: 85 additions & 0 deletions BeamWallet/Controls/BMOverlayTimerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// BMOverlayTimerView.swift
// BeamWallet
//
// Copyright 2018 Beam Development
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit

class BMOverlayTimerView: UIView, BMCountdownViewDelegate {

private var seconds = 0
private var url:URL!

public static func show (text:String, link:URL) {
let view = BMOverlayTimerView(text: text, link: link)
view.display()
}

init(text:String, link:URL) {
super.init(frame: UIScreen.main.bounds)

alpha = 0

let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = frame
addSubview(blurView)

url = link

let window = (UIApplication.shared.delegate as! AppDelegate).window

self.backgroundColor = UIColor.main.marine.withAlphaComponent(0.4)

let label = UILabel(frame: CGRect.zero)
label.font = RegularFont(size: 17)
label.textColor = UIColor.white
label.numberOfLines = 0
label.text = Localizable.shared.strings.faucet_redirect_text
label.textAlignment = .center
let size = label.sizeThatFits(CGSize(width: 260, height: 99999))
label.frame = CGRect(x: (self.width - size.width)/2,y: (self.h - size.height)/2, width: size.width, height: size.height)
addSubview(label)

let timer = BMCountdownView(frame: CGRect(x: (self.width - 28)/2, y: label.frame.origin.y - 40, width: 28, height: 28))
timer.delegate = self
timer.backgroundColor = UIColor.clear
timer.lineColor = UIColor.white
timer.trailLineColor = UIColor.main.steelGrey.withAlphaComponent(0.1)
timer.counterLabel.textColor = UIColor.white
timer.start(beginingValue: 4)
addSubview(timer)

window?.addSubview(self)
}

public func display()
{
UIView.animate(withDuration: 0.3) {
self.alpha = 1
}
}

required init?(coder: NSCoder) {
fatalError(Localizable.shared.strings.fatalInitCoderError)
}

internal func timerDidEnd() {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
removeFromSuperview()
}
}
10 changes: 9 additions & 1 deletion BeamWallet/Manager/OnboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ class OnboardManager: NSObject {
public func canReceiveFaucet() -> Bool {
let isInProgress = AppModel.sharedManager().walletStatus?.hasInProgressBalance() ?? false
let isBalanceZero = (AppModel.sharedManager().walletStatus?.available ?? 0) == 0
return !isInProgress && isBalanceZero && !isCloseFaucet
let emptyTransactions = AppModel.sharedManager().transactions?.count == 0
return !isInProgress && isBalanceZero && !isCloseFaucet && emptyTransactions
}

public func faucetAvailable() -> Bool {
let isInProgress = AppModel.sharedManager().walletStatus?.hasInProgressBalance() ?? false
let isBalanceZero = (AppModel.sharedManager().walletStatus?.available ?? 0) == 0
let emptyTransactions = AppModel.sharedManager().transactions?.count == 0
return !isInProgress && isBalanceZero && emptyTransactions
}

public func receiveFaucet(completion: @escaping ((URL?, Error?) -> Void)) {
let address = AppModel.sharedManager().findAddress(byName: "Beam community faucet")

Expand Down
44 changes: 31 additions & 13 deletions BeamWallet/Model/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class SettingsViewModel: NSObject {
case .tags:
var categories = [SettingsItem]()
if AppModel.sharedManager().categories.count > 0 {
for category in AppModel.sharedManager().categories as! [BMCategory] {

let sorted = AppModel.sharedManager().sortedCategories()

for category in sorted as! [BMCategory] {
categories.append(SettingsItem(title: category.name, detail: nil, isSwitch: nil, type: .open_category, category: category, hasArrow: true))
}
}
Expand Down Expand Up @@ -450,27 +453,42 @@ extension SettingsViewModel {
top.alert(message: reason)
}
else if let result = link {
top.openUrl(url: result, additionalInfo: Localizable.shared.strings.faucet_address_alert, infoDelay: 4)
if Settings.sharedManager().isAllowOpenLink {
BMOverlayTimerView.show(text: Localizable.shared.strings.faucet_redirect_text, link: result)
}
else {
top.confirmAlert(title: Localizable.shared.strings.external_link_title, message: Localizable.shared.strings.external_link_text, cancelTitle: Localizable.shared.strings.cancel, confirmTitle: Localizable.shared.strings.open, cancelHandler: { _ in

}) { _ in
BMOverlayTimerView.show(text: Localizable.shared.strings.faucet_redirect_text, link: result)
}
}
}
}
}
}

func onClearWallet() {
if let top = UIApplication.getTopMostViewController() {
top.confirmAlert(title: Localizable.shared.strings.clear_wallet, message: Localizable.shared.strings.clear_wallet_text, cancelTitle: Localizable.shared.strings.cancel, confirmTitle: Localizable.shared.strings.remove_wallet, cancelHandler: { _ in

}) { _ in
let modalViewController = UnlockPasswordPopover(event: .clear_wallet, allowBiometric: false)
modalViewController.completion = { obj in
if obj {
let app = UIApplication.shared.delegate as! AppDelegate
app.logout()

if(AppModel.sharedManager().hasActiveTransactions()) {
top.alert(title: Localizable.shared.strings.clear_wallet, message: Localizable.shared.strings.clear_wallet_transactions_text, handler: nil)
}
else {
top.confirmAlert(title: Localizable.shared.strings.clear_wallet, message: Localizable.shared.strings.clear_wallet_text, cancelTitle: Localizable.shared.strings.cancel, confirmTitle: Localizable.shared.strings.remove_wallet, cancelHandler: { _ in

}) { _ in
let modalViewController = UnlockPasswordPopover(event: .clear_wallet, allowBiometric: false)
modalViewController.completion = { obj in
if obj {
let app = UIApplication.shared.delegate as! AppDelegate
app.logout()
}
}
modalViewController.modalPresentationStyle = .overFullScreen
modalViewController.modalTransitionStyle = .crossDissolve
top.present(modalViewController, animated: true, completion: nil)
}
modalViewController.modalPresentationStyle = .overFullScreen
modalViewController.modalTransitionStyle = .crossDissolve
top.present(modalViewController, animated: true, completion: nil)
}
}
}
Expand Down
Loading

0 comments on commit 5e2027b

Please sign in to comment.