Skip to content

Commit

Permalink
addresses, new beam library
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Mar 27, 2019
1 parent 85a9204 commit f9eedae
Show file tree
Hide file tree
Showing 63 changed files with 3,515 additions and 409 deletions.
193 changes: 180 additions & 13 deletions BeamWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

95 changes: 71 additions & 24 deletions BeamWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Crashlytics
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var backgroundTask: UIBackgroundTaskIdentifier = .invalid
var completionHandler: ((UIBackgroundFetchResult) -> Void)?

static let targetName = Bundle.main.infoDictionary?["CFBundleExecutable"] as! String

Expand All @@ -44,12 +46,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {


UIApplication.shared.setMinimumBackgroundFetchInterval (UIApplication.backgroundFetchIntervalMinimum)

Crashlytics().debugMode = true
Fabric.with([Crashlytics.self()])

let appModel = AppModel.sharedManager()
let added = appModel.isWalletAlreadyAdded()
NotificationManager.sharedManager.requestPermissions()

AppModel.sharedManager().addDelegate(self)

let added = AppModel.sharedManager().isWalletAlreadyAdded()

let rootController = UINavigationController(rootViewController: added ? EnterWalletPasswordViewController() : LoginViewController())
rootController.navigationBar.setBackgroundImage(UIImage(), for: .default)
Expand All @@ -64,49 +71,89 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.window!.makeKeyAndVisible()



return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NotificationManager.sharedManager.clearNotifications()

}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

extension UIApplication {
class func getTopMostViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopMostViewController(base: nav.visibleViewController)
func registerBackgroundTask() {
backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in
self?.endBackgroundTask()
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return getTopMostViewController(base: selected)
}

func endBackgroundTask() {
UIApplication.shared.endBackgroundTask(backgroundTask)
backgroundTask = .invalid
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

if let password = KeychainManager.getPassword() {
self.completionHandler = completionHandler

self.registerBackgroundTask()

if(AppModel.sharedManager().isLoggedin) {
AppModel.sharedManager().refreshAllInfo()
}
else{
AppModel.sharedManager().openWallet(password)
}

DispatchQueue.main.asyncAfter(deadline: .now() + 26) {
self.endBackgroundTask()
self.completionHandler?(.newData)
}
}
if let presented = base?.presentedViewController {
return getTopMostViewController(base: presented)
}
}


extension AppDelegate : WalletModelDelegate {
public func onReceivedTransactions(_ transactions: [BMTransaction]) {
DispatchQueue.main.async {

var oldTransactions = [BMTransaction]()

//get old notifications
if let data = UserDefaults.standard.data(forKey: "transactions") {
if let array = NSKeyedUnarchiver.unarchiveObject(with: data) as? [BMTransaction] {
oldTransactions = array
}
}

for transaction in transactions {
if transaction.isIncome && !transaction.isSelf {
if let oldTransaction = oldTransactions.first(where: { $0.id == transaction.id }) {
if oldTransaction.status != transaction.status && UIApplication.shared.applicationState != .active {
NotificationManager.sharedManager.scheduleNotification(transaction: transaction)
}
}
else{
NotificationManager.sharedManager.scheduleNotification(transaction: transaction)
}
}
}

UserDefaults.standard.set(NSKeyedArchiver.archivedData(withRootObject: transactions), forKey: "transactions")
UserDefaults.standard.synchronize()
}
return base
}
}

15 changes: 14 additions & 1 deletion BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
-(void)onWalletError:(NSString*_Nonnull)error;
-(void)onWalletStatusChange:(BMWalletStatus*_Nonnull)status;
-(void)onNetwotkStatusChange:(BOOL)connected;
-(void)onNetwotkStartConnecting:(BOOL)connecting;
-(void)onWalletAddresses:(NSArray<BMAddress*>*_Nonnull)walletAddresses;
-(void)onGeneratedNewAddress:(BMAddress*_Nonnull)address;
-(void)onReceivedTransactions:(NSArray<BMTransaction*>*_Nonnull)transactions;
-(void)onSendMoneyVerified;
Expand All @@ -43,11 +45,15 @@

@property (nonatomic,assign) BOOL isConnected;
@property (nonatomic,assign) BOOL isInternetAvailable;
@property (nonatomic,assign) BOOL isUpdating;
@property (nonatomic,assign) BOOL isConnecting;
@property (nonatomic,assign) BOOL isLoggedin;

@property (nonatomic,strong) BMWalletStatus* _Nullable walletStatus;
@property (nonatomic,strong) BMAddress* _Nullable walletAddress;
@property (nonatomic,strong) NSMutableArray<BMTransaction*>*_Nullable transactions;
@property (nonatomic,strong) NSMutableArray<BMUTXO*>*_Nullable utxos;
@property (nonatomic,strong) NSMutableArray<BMAddress*>*_Nullable walletAddresses;

+(AppModel*_Nonnull)sharedManager;

Expand All @@ -60,15 +66,21 @@
-(BOOL)canOpenWallet:(NSString*_Nonnull)pass;
-(void)resetWallet;

-(void)refreshWallet;
//-(void)refreshWallet;
-(void)getWalletStatus;
-(void)getNetworkStatus;
-(void)refreshAllInfo;

-(void)generateNewWalletAddress;
-(void)setExpires:(int)hours toAddress:(NSString*_Nonnull)address ;
-(void)setWalletComment:(NSString*_Nonnull)comment toAddress:(NSString*_Nonnull)address ;
-(NSMutableArray<BMTransaction*>*_Nonnull)getTransactionsFromAddress:(BMAddress*_Nonnull)address;
-(NSMutableArray<BMAddress*>*_Nonnull)getWalletAddresses;
-(void)editAddress:(BMAddress*_Nonnull)address;

-(BOOL)isValidAddress:(NSString*_Nullable)address;
-(BOOL)isExpiredAddress:(NSString*_Nullable)address;
-(void)deleteAddress:(NSString*_Nullable)address;

-(NSString*_Nullable)canSend:(double)amount fee:(double)fee to:(NSString*_Nullable)to;
-(void)send:(double)amount fee:(double)fee to:(NSString*_Nonnull)to comment:(NSString*_Nonnull)comment;
Expand All @@ -80,5 +92,6 @@
-(void)resumeTransaction:(BMTransaction*_Nonnull)transaction;

-(void)getUTXO;
-(NSMutableArray<BMTransaction*>*_Nonnull)getTransactionsFromUTXO:(BMUTXO*_Nonnull)utox;

@end
Loading

0 comments on commit f9eedae

Please sign in to comment.