Skip to content

Commit

Permalink
sprint 2.0 completed
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Apr 16, 2019
1 parent 60094e6 commit a984a8e
Show file tree
Hide file tree
Showing 65 changed files with 3,443 additions and 448 deletions.
294 changes: 172 additions & 122 deletions BeamWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,4 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BeamWallet/ViewControllers/GeneratePhrase/InputPhraseViewController.swift"
timestampString = "573141955.781019"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "textValueCellDidEndEditing(_:_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BeamWallet/Controls/BMField.swift"
timestampString = "573151062.72425"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "layoutSubviews()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
2 changes: 2 additions & 0 deletions BeamWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

static var enableNewFeatures = true

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


Expand Down
7 changes: 6 additions & 1 deletion BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@
-(BOOL)createWallet:(NSString*_Nonnull)phrase pass:(NSString*_Nonnull)pass;
-(BOOL)openWallet:(NSString*_Nonnull)pass;
-(BOOL)canOpenWallet:(NSString*_Nonnull)pass;
-(void)resetWallet;
-(void)resetWallet:(BOOL)removeDatabase;
-(void)startForgotPassword;
-(void)stopForgotPassword;
-(void)cancelForgotPassword;
-(BOOL)isValidPassword:(NSString*_Nonnull)pass;
-(void)changePassword:(NSString*_Nonnull)pass;
-(void)onSyncWithLocalNodeCompleted;

// updates
-(void)getWalletStatus;
Expand All @@ -99,6 +100,8 @@
-(void)deleteAddress:(NSString*_Nullable)address;
-(BOOL)isValidAddress:(NSString*_Nullable)address;
-(BOOL)isExpiredAddress:(NSString*_Nullable)address;
-(BOOL)isAddressDeleted:(NSString*_Nullable)address;


// send
-(NSString*_Nullable)canSend:(double)amount fee:(double)fee to:(NSString*_Nullable)to;
Expand All @@ -114,9 +117,11 @@
-(void)cancelTransaction:(BMTransaction*_Nonnull)transaction;
-(void)resumeTransaction:(BMTransaction*_Nonnull)transaction;
-(NSMutableArray<BMUTXO*>*_Nonnull)getUTXOSFromTransaction:(BMTransaction*_Nonnull)transaction;
-(void)exportTransactionsToCSV:(void(^_Nonnull)(NSURL*_Nonnull))callback;

// utxo
-(void)getUTXO;
-(NSMutableArray<BMUTXO*>*_Nonnull)getUTXOWithPadding:(BOOL)active page:(int)page perPage:(int)perPage;
-(NSMutableArray<BMTransaction*>*_Nonnull)getTransactionsFromUTXO:(BMUTXO*_Nonnull)utox;

//contacts
Expand Down
171 changes: 153 additions & 18 deletions BeamWallet/BeamSDK/AppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

#include "utility/bridge.h"
#include "utility/string_helpers.h"
#include "utility/options.h"
//#include "utility/options.h"

#include "mnemonic/mnemonic.h"

Expand All @@ -54,9 +54,11 @@
using namespace beam::io;

static int proofSize = 330;
static NSString *deletedAddressesKEY = @"deletedAddresses";

@implementation AppModel {
BOOL isStarted;
NSTimer *utxoTimer;

Reachability *internetReachableFoo;

Expand Down Expand Up @@ -99,7 +101,7 @@ -(id)init{
name:UIApplicationDidBecomeActiveNotification object:nil];

[self cancelForgotPassword];

return self;
}

Expand Down Expand Up @@ -161,11 +163,12 @@ -(void)setIsLocalNodeStarted:(BOOL)isLocalNodeStarted {
wallet->start();

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self->nodeModel.stopNode();

/// self->nodeModel.stopNode();

string nodeAddrStr = [Settings sharedManager].nodeAddress.string;
/// string nodeAddrStr = [Settings sharedManager].nodeAddress.string;

self->wallet->getAsync()->setNodeAddress(nodeAddrStr);
/// self->wallet->getAsync()->setNodeAddress(nodeAddrStr);

for(id<WalletModelDelegate> delegate in [AppModel sharedManager].delegates)
{
Expand All @@ -174,7 +177,7 @@ -(void)setIsLocalNodeStarted:(BOOL)isLocalNodeStarted {
}
}

[[NSFileManager defaultManager] removeItemAtPath:[Settings sharedManager].localNodeStorage error:nil];
/// [[NSFileManager defaultManager] removeItemAtPath:[Settings sharedManager].localNodeStorage error:nil];

if([AppModel sharedManager].isForgotPasswordFlow) {
[[AppModel sharedManager] stopForgotPassword];
Expand Down Expand Up @@ -231,19 +234,25 @@ -(BOOL)openWallet:(NSString*)pass {

-(BOOL)canOpenWallet:(NSString*)pass {
Rules::get().UpdateChecksum();

string dbFilePath = [Settings sharedManager].walletStoragePath.string;

walletDb = WalletDB::open(dbFilePath, pass.string, walletReactor);
if (!walletDb) {
return NO;
}

if ([[NSFileManager defaultManager] fileExistsAtPath:[Settings sharedManager].localNodeStorage]) {
self.isRestoreFlow = YES;
// self.isRestoreFlow = YES;

if (!nodeModel.isStarted())
{
nodeModel.start();
}

[Settings sharedManager].isLocalNode = YES;
}


return YES;
}

Expand Down Expand Up @@ -304,16 +313,23 @@ -(BOOL)createWallet:(NSString*)phrase pass:(NSString*)pass {
return YES;
}

-(void)resetWallet{
-(void)resetWallet:(BOOL)removeDatabase {
if (self.isRestoreFlow) {
self.isRestoreFlow = NO;
self->nodeModel.stopNode();
}
else{
walletDb.reset();
wallet.reset();


isStarted = NO;

walletDb.reset();
wallet.reset();

wallet = nil;
walletDb = nil;

if(removeDatabase) {
[[NSFileManager defaultManager] removeItemAtPath:[Settings sharedManager].walletStoragePath error:nil];
[[NSFileManager defaultManager] removeItemAtPath:[Settings sharedManager].localNodeStorage error:nil];
}
}

Expand Down Expand Up @@ -509,13 +525,27 @@ -(void)setWalletComment:(NSString*)comment toAddress:(NSString*_Nonnull)address
}

-(void)deleteAddress:(NSString*_Nullable)address {

WalletID walletID(Zero);
if (walletID.FromHex(address.string))
{
walletDb->deleteAddress(walletID);
wallet->getAsync()->deleteAddress(walletID);
// walletDb->deleteAddress(walletID);
}
}

-(BOOL)isAddressDeleted:(NSString*_Nullable)address {
NSMutableArray *deletedAddresses = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults]objectForKey:deletedAddressesKEY]];

for (NSString *a in deletedAddresses) {
if ([a isEqualToString:address]){
return YES;
}
}

return NO;
}

-(void)generateNewWalletAddress {
wallet->getAsync()->generateNewAddress();
}
Expand Down Expand Up @@ -572,7 +602,7 @@ -(void)editAddress:(BMAddress*_Nonnull)address {
}
}
else{
wallet->getAsync()->saveAddressChanges(walletID, address.label.string, (address.duration == 0 ? true : false), false, false);
wallet->getAsync()->saveAddressChanges(walletID, address.label.string, (address.duration == 0 ? true : false), true, false);
}
}
}
Expand Down Expand Up @@ -626,6 +656,7 @@ -(NSString*)sendError:(double)amount fee:(double)fee to:(NSString*_Nullable)to {
currencyFormatter.maximumIntegerDigits = 20;
currencyFormatter.maximumFractionDigits = 20;
currencyFormatter.maximumSignificantDigits = 20;
currencyFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

NSString *beam = [currencyFormatter stringFromNumber:[NSNumber numberWithDouble:need]];

Expand All @@ -641,8 +672,10 @@ -(void)send:(double)amount fee:(double)fee to:(NSString*_Nonnull)to comment:(NSS
WalletID walletID(Zero);
if (walletID.FromHex(to.string))
{
auto bAmount = round(amount * Rules::Coin);

try{
wallet->getAsync()->sendMoney(walletID, comment.string, amount * Rules::Coin,fee);
wallet->getAsync()->sendMoney(walletID, comment.string, bAmount, fee);
}
catch(NSException *ex) {
NSLog(@"%@",ex);
Expand Down Expand Up @@ -822,8 +855,71 @@ -(TxID)txIDfromString:(NSString*)string {
return txID;
}

-(void)exportTransactionsToCSV:(void(^_Nonnull)(NSURL*_Nonnull))callback {
NSString *fileName = @"transactions.csv";
NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:fileName]];

NSString *csvText = @"Type,Date,Amount,Status,Sending address,Receiving address,Transaction fee,Transaction ID,Kernel ID\n";

for (BMTransaction *tr in _transactions) {
NSString *newLine = [tr csvLine];
csvText = [csvText stringByAppendingString:newLine];
}

[csvText writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:nil];

callback(url);
}

#pragma mark - UTXO

-(void)onSyncWithLocalNodeCompleted {
if ([Settings sharedManager].isLocalNode) {
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");
NSLog(@"---------------------------");

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

self->nodeModel.stopNode();

string nodeAddrStr = [Settings sharedManager].nodeAddress.string;

self->wallet->getAsync()->setNodeAddress(nodeAddrStr);

[[NSFileManager defaultManager] removeItemAtPath:[Settings sharedManager].localNodeStorage error:nil];
});

self.isLocalNodeStarted = NO;
self.isRestoreFlow = NO;
}
}

-(void)setUtxos:(NSMutableArray<BMUTXO *> *)utxos {
_utxos = utxos;
// dispatch_async(dispatch_get_main_queue(), ^{
// if ([Settings sharedManager].isLocalNode) {
// if (self->utxoTimer) {
// [self->utxoTimer invalidate];
// self->utxoTimer = nil;
// }
//
// self->utxoTimer = [NSTimer scheduledTimerWithTimeInterval: 15
// target: self
// selector: @selector(onUTXOTimer)
// userInfo: nil
// repeats: NO];
// }
// });
}

-(void)getUTXO {
wallet->getAsync()->getUtxosStatus();
}
Expand All @@ -850,6 +946,45 @@ -(void)getUTXO {
return result;
}

-(NSMutableArray<BMUTXO*>*_Nonnull)getUTXOWithPadding:(BOOL)active page:(int)page perPage:(int)perPage {

NSArray *filteredArray = [self.utxos filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) {
if (active) {
if ([(BMUTXO*)object isActive]) {
return YES;
}
else{
return NO;
}
}

return YES;
}]];

NSMutableArray *result = [NSMutableArray array];

if(filteredArray.count >= (perPage*page)) {
result = [NSMutableArray arrayWithArray:[filteredArray subarrayWithRange:NSMakeRange(0, perPage*page)]];
}
else{
[result addObjectsFromArray:filteredArray];
}

[result sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
BMUTXO *utxo_1 = (BMUTXO*)obj1;
BMUTXO *utxo_2 = (BMUTXO*)obj2;

if (utxo_1.ID > utxo_2.ID) {
return (NSComparisonResult)NSOrderedAscending;
}
else{
return (NSComparisonResult)NSOrderedDescending;
}
}];

return result;
}

#pragma mark - Contacts

-(BMContact*_Nullable)getContactFromId:(NSString*_Nonnull)idValue {
Expand Down
7 changes: 4 additions & 3 deletions BeamWallet/BeamSDK/MnemonicModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@

@interface MnemonicModel : NSObject

+(NSString*)generatePhrase;
+(BOOL)isValidPhrase:(NSString*)phrase;
+(BOOL)isValidWord:(NSString*)word;
+(NSString*_Nonnull)generatePhrase;
+(BOOL)isValidPhrase:(NSString*_Nonnull)phrase;
+(BOOL)isValidWord:(NSString*_Nonnull)word;
+(NSArray<NSString*>*_Nonnull)mnemonicWordsForPrefix:(NSString*_Nonnull)prefix suggestions:(NSArray*_Nullable)suggestions;

@end
Loading

0 comments on commit a984a8e

Please sign in to comment.