Skip to content

Commit 5e2027b

Browse files
committed
https://github.com/BeamMW/ios-wallet/issues/366
1 parent 6796b42 commit 5e2027b

18 files changed

+356
-185
lines changed

BeamWallet.xcodeproj/project.pbxproj

Lines changed: 98 additions & 144 deletions
Large diffs are not rendered by default.

BeamWallet/AppDelegate.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
101101
UserDefaults.standard.synchronize()
102102
})
103103
}
104-
104+
105105
return true
106106
}
107107

108+
func before(value1: String, value2: String) -> Bool {
109+
let ch1 = value1.first
110+
let l1 = ch1!.isLetter
111+
if (!l1) {
112+
return false
113+
}
114+
115+
let ch2 = value2.first
116+
let l2 = ch2!.isLetter
117+
if (!l2) {
118+
return false
119+
}
120+
121+
return value1.lowercased() < value2.lowercased()
122+
}
123+
124+
108125
public func logout() {
109126
AppModel.sharedManager().clearAllCategories()
110127
AppModel.sharedManager().isLoggedin = false

BeamWallet/BeamSDK/AppModel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
191191
-(void)clearAllTransactions;
192192
-(BMTransaction*_Nullable)lastTransactionFromAddress:(NSString*_Nonnull)ID;
193193
-(NSString*_Nullable)getFirstTransactionIdForAddress:(NSString*_Nonnull)address;
194+
-(BOOL)hasActiveTransactions;
194195

195196
// utxo
196197
-(void)getUTXO;
@@ -211,6 +212,7 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
211212
-(NSMutableArray<BMContact*>*_Nonnull)getOnlyContactsFromCategory:(BMCategory*_Nonnull)category;
212213
-(void)fixCategories;
213214
-(void)clearAllCategories;
215+
-(NSMutableArray<BMCategory*>*_Nonnull)sortedCategories;
214216

215217
//fork
216218
-(BOOL)isFork;

BeamWallet/BeamSDK/AppModel.mm

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ -(id)init{
120120
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActiveNotification) name:UIApplicationDidBecomeActiveNotification object:nil];
121121

122122
[self loadRules];
123+
123124

124125
return self;
125126
}
@@ -1894,6 +1895,18 @@ -(NSString*_Nullable)getFirstTransactionIdForAddress:(NSString*_Nonnull)address
18941895
return _id;
18951896
}
18961897

1898+
-(BOOL)hasActiveTransactions {
1899+
for (BMTransaction *tr in self.transactions.reverseObjectEnumerator)
1900+
{
1901+
if(tr.enumStatus == BMTransactionStatusPending || tr.enumStatus == BMTransactionStatusInProgress
1902+
|| tr.enumStatus == BMTransactionStatusRegistering) {
1903+
return YES;
1904+
}
1905+
}
1906+
1907+
return NO;
1908+
}
1909+
18971910
#pragma mark - UTXO
18981911

18991912
-(void)setUtxos:(NSMutableArray<BMUTXO *> *)utxos {
@@ -2163,6 +2176,53 @@ -(void)clearAllCategories {
21632176
}
21642177
}
21652178

2179+
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
2180+
{
2181+
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
2182+
NSInteger sectionCount = [[collation sectionTitles] count]; //section count is take from sectionTitles and not sectionIndexTitles
2183+
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
2184+
2185+
//create an array to hold the data for each section
2186+
for(int i = 0; i < sectionCount; i++)
2187+
{
2188+
[unsortedSections addObject:[NSMutableArray array]];
2189+
}
2190+
2191+
//put each object into a section
2192+
for (id object in array)
2193+
{
2194+
NSInteger index = [collation sectionForObject:object collationStringSelector:selector];
2195+
[[unsortedSections objectAtIndex:index] addObject:object];
2196+
}
2197+
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
2198+
2199+
//sort each section
2200+
for (NSMutableArray *section in unsortedSections)
2201+
{
2202+
[sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
2203+
}
2204+
return sections;
2205+
}
2206+
2207+
-(NSMutableArray<BMCategory*>*_Nonnull)sortedCategories {
2208+
NSArray *sections = [self partitionObjects:_categories collationStringSelector:@selector(name)];
2209+
2210+
NSMutableArray *sorted = [NSMutableArray array];
2211+
2212+
for (NSArray *arr in sections) {
2213+
if(arr.count > 0) {
2214+
NSSortDescriptor *sortDescriptor;
2215+
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name"
2216+
ascending:YES];
2217+
NSArray *sortedArray = [arr sortedArrayUsingDescriptors:@[sortDescriptor]];
2218+
2219+
[sorted addObjectsFromArray:sortedArray];
2220+
}
2221+
}
2222+
2223+
return sorted;
2224+
}
2225+
21662226
-(void)fixCategories {
21672227
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"fix"] intValue]==1) {
21682228
return;

BeamWallet/BeamSDK/WalletModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ class WalletModel : public beam::wallet::WalletClient
7575
void onImportDataFromJson(bool isOk) override;
7676
void onExportDataToJson(const std::string& data) override;
7777
void onPostFunctionToClientContext(MessageFunction&& func) override;
78-
// void onExportTxHistoryToCsv(const std::string& data) override;
79-
//void onAddressesChanged(beam::wallet::ChangeAction, const std::vector<beam::wallet::WalletAddress>& addresses) override;
78+
void onExportTxHistoryToCsv(const std::string& data) override;
79+
// void onAddressesChanged(beam::wallet::ChangeAction, const std::vector<beam::wallet::WalletAddress>& addresses) override;
8080
};

BeamWallet/BeamSDK/WalletModel.mm

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@
8989

9090
void WalletModel::onTxStatus(beam::wallet::ChangeAction action, const std::vector<beam::wallet::TxDescription>& items)
9191
{
92-
NSLog(@"onTxStatus");
93-
9492
NSMutableArray *transactions = [NSMutableArray new];
9593

9694
for (const auto& item : items)
@@ -720,17 +718,13 @@
720718

721719
}
722720

723-
//void WalletModel::onExportTxHistoryToCsv(const std::string& data) {
724-
//
725-
//}
721+
void WalletModel::onExportTxHistoryToCsv(const std::string& data) {
722+
723+
}
726724

727725
//void WalletModel::onAddressesChanged (beam::wallet::ChangeAction action, const std::vector <beam::wallet::WalletAddress > &items) {
728-
// if(items[0].isOwn()) {
729-
// getAsync()->getAddresses(true);
730-
// }
731-
// else{
732-
// getAsync()->getAddresses(false);
733-
// }
726+
// getAsync()->getAddresses(true);
727+
// getAsync()->getAddresses(false);
734728
//}
735729

736730

BeamWallet/Controls/BMCountdownView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ import Foundation
2525

2626
public class BMCountdownView: UIView {
2727
private var lineWidth: CGFloat = 1.5
28-
private var lineColor: UIColor = UIColor.init(hexString: "#032E49")
29-
private var trailLineColor: UIColor = UIColor.main.steelGrey.withAlphaComponent(0.3)
28+
29+
var lineColor: UIColor = UIColor.init(hexString: "#032E49")
30+
var trailLineColor: UIColor = UIColor.main.steelGrey.withAlphaComponent(0.3)
3031

3132
public weak var delegate: BMCountdownViewDelegate?
3233

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

40-
private lazy var counterLabel: UILabel = {
41+
lazy var counterLabel: UILabel = {
4142
let label = UILabel()
4243
self.addSubview(label)
4344

BeamWallet/Controls/BMDataPickerViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ class BMDataPickerViewController: BaseTableViewController {
227227
if selectedCategories.count == 0 {
228228
selectedCategories.append("0")
229229
}
230+
230231
let none = BMCategory.none()
231232
none.name = none.name.capitalizingFirstLetter()
232-
var categories = (AppModel.sharedManager().categories as! [BMCategory])
233+
234+
var categories = AppModel.sharedManager().sortedCategories() as! [BMCategory]
233235
categories.insert(none, at: 0)
236+
234237
for category in categories {
235238
let selected = selectedCategories.contains(String(category.id))
236239
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))

BeamWallet/Controls/BMInputViewController.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
//
2-
// BMInputViewController.swift
3-
// BeamWallet
2+
// BMInputViewController.swift
3+
// BeamWallet
44
//
5-
// Created by Denis on 10/21/19.
6-
// Copyright © 2019 Denis. All rights reserved.
5+
// Copyright 2018 Beam Development
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
718
//
819

920
import UIKit
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//
2+
// BMOverlayTimerView.swift
3+
// BeamWallet
4+
//
5+
// Copyright 2018 Beam Development
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
20+
import UIKit
21+
22+
class BMOverlayTimerView: UIView, BMCountdownViewDelegate {
23+
24+
private var seconds = 0
25+
private var url:URL!
26+
27+
public static func show (text:String, link:URL) {
28+
let view = BMOverlayTimerView(text: text, link: link)
29+
view.display()
30+
}
31+
32+
init(text:String, link:URL) {
33+
super.init(frame: UIScreen.main.bounds)
34+
35+
alpha = 0
36+
37+
let blurEffect = UIBlurEffect(style: .dark)
38+
let blurView = UIVisualEffectView(effect: blurEffect)
39+
blurView.frame = frame
40+
addSubview(blurView)
41+
42+
url = link
43+
44+
let window = (UIApplication.shared.delegate as! AppDelegate).window
45+
46+
self.backgroundColor = UIColor.main.marine.withAlphaComponent(0.4)
47+
48+
let label = UILabel(frame: CGRect.zero)
49+
label.font = RegularFont(size: 17)
50+
label.textColor = UIColor.white
51+
label.numberOfLines = 0
52+
label.text = Localizable.shared.strings.faucet_redirect_text
53+
label.textAlignment = .center
54+
let size = label.sizeThatFits(CGSize(width: 260, height: 99999))
55+
label.frame = CGRect(x: (self.width - size.width)/2,y: (self.h - size.height)/2, width: size.width, height: size.height)
56+
addSubview(label)
57+
58+
let timer = BMCountdownView(frame: CGRect(x: (self.width - 28)/2, y: label.frame.origin.y - 40, width: 28, height: 28))
59+
timer.delegate = self
60+
timer.backgroundColor = UIColor.clear
61+
timer.lineColor = UIColor.white
62+
timer.trailLineColor = UIColor.main.steelGrey.withAlphaComponent(0.1)
63+
timer.counterLabel.textColor = UIColor.white
64+
timer.start(beginingValue: 4)
65+
addSubview(timer)
66+
67+
window?.addSubview(self)
68+
}
69+
70+
public func display()
71+
{
72+
UIView.animate(withDuration: 0.3) {
73+
self.alpha = 1
74+
}
75+
}
76+
77+
required init?(coder: NSCoder) {
78+
fatalError(Localizable.shared.strings.fatalInitCoderError)
79+
}
80+
81+
internal func timerDidEnd() {
82+
UIApplication.shared.open(url, options: [:], completionHandler: nil)
83+
removeFromSuperview()
84+
}
85+
}

0 commit comments

Comments
 (0)