Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Jun 5, 2020
1 parent 562182c commit 0177207
Show file tree
Hide file tree
Showing 37 changed files with 419 additions and 264 deletions.
186 changes: 100 additions & 86 deletions BeamWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions BeamWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
AppModel.sharedManager().connectionTimer = nil
}

if AppModel.sharedManager().isRestoreFlow || AppModel.sharedManager().isUpdating {
self.registerBackgroundTask()
}
self.registerBackgroundTask()

if let transactions = AppModel.sharedManager().preparedTransactions as? [BMPreparedTransaction] {
if transactions.count > 0, AppModel.sharedManager().isLoggedin {
Expand Down Expand Up @@ -164,9 +162,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func applicationWillEnterForeground(_ application: UIApplication) {
if AppModel.sharedManager().isRestoreFlow || AppModel.sharedManager().isUpdating {
self.endBackgroundTask()
}
self.endBackgroundTask()
}

func applicationDidBecomeActive(_ application: UIApplication) {
Expand Down
1 change: 1 addition & 0 deletions BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,6 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
-(void)deleteNotification:(NSString*_Nonnull) notifId;
-(void)deleteAllNotifications;
-(BMNotification*_Nullable)getLastVersionNotification;
-(void)readAllNotifications;

@end
67 changes: 48 additions & 19 deletions BeamWallet/BeamSDK/AppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ -(void)start {
wallet = make_shared<WalletModel>(walletDb, nodeAddrStr, walletReactor);
wallet->getAsync()->setNodeAddress(nodeAddrStr);

wallet->start(activeNotifications, isSecondCurrencyEnabled);
wallet->start(activeNotifications, false, isSecondCurrencyEnabled);

isRunning = YES;
isStarted = YES;
Expand All @@ -698,7 +698,7 @@ -(void)start {
if(self.isInternetAvailable && isRunning == NO && ![[Settings sharedManager] isLocalNode])
{
isRunning = YES;
wallet->start(activeNotifications, isSecondCurrencyEnabled);
wallet->start(activeNotifications, false, isSecondCurrencyEnabled);
}
}
}
Expand Down Expand Up @@ -752,12 +752,16 @@ -(BOOL)isValidNodeAddress:(NSString*_Nonnull)string {
}

-(void)exportOwnerKey:(NSString*_Nonnull)password result:(ExportOwnerKey _Nonnull)block{
if(self->wallet == nil) {
[self start];
}

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
auto pass = SecString(password.string);

const auto& ownerKey = self->wallet->exportOwnerKey(pass);

NSString *exportedKey = [NSString stringWithUTF8String:ownerKey.c_str()];
dispatch_async(dispatch_get_main_queue(), ^{
block(exportedKey);
Expand Down Expand Up @@ -1335,6 +1339,8 @@ -(void)editAddress:(BMAddress*_Nonnull)address {
}

if(address.isNowExpired) {
[_presendedNotifications setValue:address.walletId forKey:address.walletId];

wallet->getAsync()->updateAddress(walletID, address.label.string, WalletAddress::ExpirationStatus::Expired);
}
else if(address.isNowActive) {
Expand Down Expand Up @@ -1563,19 +1569,25 @@ -(void)send:(double)amount fee:(double)fee to:(NSString*_Nonnull)to comment:(NSS
auto bAmount = round(amount * Rules::Coin);

try{
__block BMAddress *address = [[AppModel sharedManager] findAddressByID:to];

// __block BMAddress *address = [[AppModel sharedManager] findAddressByID:to];

__block auto address = walletDb->getAddress(walletID);

wallet->getAsync()->sendMoney(fromID, walletID, comment.string, bAmount, fee);
wallet->getAsync()->getWalletStatus();

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if ([[AppModel sharedManager] isMyAddress:to]) {
[[AppModel sharedManager] setWalletComment:address.label toAddress:address.walletId];
}
else if (address != nil){
[[AppModel sharedManager] setContactComment:address.label toAddress:address.walletId];
}
});
if(address) {
__block NSString *name = [NSString stringWithUTF8String:address->m_label.c_str()];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (address->isOwn()) {
[[AppModel sharedManager] setWalletComment:name toAddress:to];
}
else {
[[AppModel sharedManager] setContactComment:name toAddress:to];
}
});
}

}
catch(NSException *ex) {
NSLog(@"%@",ex);
Expand Down Expand Up @@ -2469,8 +2481,14 @@ -(NSString*_Nonnull)exportData:(NSArray*_Nonnull)items{
}

-(NSString*_Nonnull)exchangeValue:(double)amount {
for (BMCurrency *currency in _currencies) {
if(currency.type == Settings.sharedManager.currency) {
if(Settings.sharedManager.currency == BMCurrencyOff) {
return @"";
}
if(amount == 0.0) {
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
}
for (BMCurrency *currency in [_currencies objectEnumerator].allObjects) {
if(currency.type == Settings.sharedManager.currency && currency.value > 0) {
currencyFormatter.maximumFractionDigits = currency.maximumFractionDigits;
currencyFormatter.positiveSuffix = [NSString stringWithFormat:@" %@",currency.code];

Expand All @@ -2480,15 +2498,18 @@ -(NSString*_Nonnull)exchangeValue:(double)amount {
}
}

return @"";
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
}

-(NSString*_Nonnull)exchangeValueFee:(double)amount {
if(Settings.sharedManager.currency == BMCurrencyOff) {
return @"";
}
if(amount == 0) {
return @"";
}
for (BMCurrency *currency in _currencies) {
if(currency.type == Settings.sharedManager.currency) {
if(currency.type == Settings.sharedManager.currency && currency.value > 0) {
currencyFormatter.maximumFractionDigits = currency.maximumFractionDigits;
currencyFormatter.positiveSuffix = [NSString stringWithFormat:@" %@",currency.code];

Expand All @@ -2507,7 +2528,7 @@ -(NSString*_Nonnull)exchangeValueFee:(double)amount {
}
}

return @"";
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
}

#pragma mark - Notifications
Expand Down Expand Up @@ -2608,6 +2629,14 @@ -(void)clearNotifications {
[_presendedNotifications removeAllObjects];
}

-(void)readAllNotifications {
NSMutableArray *notifications = [NSMutableArray arrayWithArray:_notifications];
for (BMNotification *notification in notifications) {
if(![notification isRead]) {
[self readNotification: notification.nId];
}
}
}

@end

14 changes: 12 additions & 2 deletions BeamWallet/BeamSDK/ObjcExtensions/StringLocalize.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@implementation NSString (Localization)

-(NSString*)localized {
NSString *result = @"";

NSString *lang = [Settings sharedManager].language;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
Expand All @@ -33,14 +35,22 @@ -(NSString*)localized {
NSBundle *bundle = [NSBundle bundleWithPath:remotePath];

if (bundle!=nil) {
return NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
result = NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
}
}

NSString *path = [[NSBundle mainBundle] pathForResource:lang ofType:@"lproj"];
NSBundle * bundle = [[NSBundle alloc] initWithPath:path];

return NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
result = NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");

if ([result isEqualToString:self]) {
NSString *pathEn = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
NSBundle * bundleEn = [[NSBundle alloc] initWithPath:pathEn];
result = NSLocalizedStringWithDefaultValue(self, nil, bundleEn, @"", @"");
}

return result;
}

@end
3 changes: 2 additions & 1 deletion BeamWallet/BeamSDK/Objects/BMCurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
enum {
BEAM = 0,
BMCurrencyUSD = 1,
BMCurrencyBTC = 2
BMCurrencyBTC = 2,
BMCurrencyOff = 3
};
typedef int BMCurrencyType;

Expand Down
2 changes: 1 addition & 1 deletion BeamWallet/BeamSDK/RecoveryProgress.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
}
}

bool RecoveryProgress::OnProgress(uint64_t done, uint64_t total) {
bool RecoveryProgress::OnProgress(uint64_t done, uint64_t total) {
if (!m_isStart) {
m_isStart = true;

Expand Down
65 changes: 37 additions & 28 deletions BeamWallet/BeamSDK/Settings.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ + (Settings*_Nonnull)sharedManager {
-(id)init {
self = [super init];


_delegates = [NSHashTable weakObjectsHashTable];

NSString *target = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleExecutable"];
Expand All @@ -68,6 +69,8 @@ -(id)init {
_target = Mainnet;
}

// [self copyOldDatabaseToGroup];

_isLocalNode = NO;

if ([[NSUserDefaults standardUserDefaults] objectForKey:askKey]) {
Expand Down Expand Up @@ -147,20 +150,22 @@ -(id)init {

_whereBuyAddress = @"https://www.beam.mw/#exchanges";

if ([[NSUserDefaults standardUserDefaults] objectForKey:languageKey]) {
_language = [[NSUserDefaults standardUserDefaults] objectForKey:languageKey];
}
else{
_language = [[NSLocale currentLocale] languageCode];

if ([_language isEqualToString:@"zh"]) {
_language = @"zh-Hans";
}

if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:_language ofType:@"lproj"]]) {
_language = @"en";
}
}
_language = @"en";

// if ([[NSUserDefaults standardUserDefaults] objectForKey:languageKey]) {
// _language = [[NSUserDefaults standardUserDefaults] objectForKey:languageKey];
// }
// else{
// _language = [[NSLocale currentLocale] languageCode];
//
// if ([_language isEqualToString:@"zh"]) {
// _language = @"zh-Hans";
// }
//
// if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:_language ofType:@"lproj"]]) {
// _language = @"en";
// }
// }

if ([[NSUserDefaults standardUserDefaults] objectForKey:currenctKey]) {
_currency = [[[NSUserDefaults standardUserDefaults] objectForKey:currenctKey] intValue];
Expand Down Expand Up @@ -336,17 +341,19 @@ -(NSString*_Nonnull)walletStoragePath {
}

-(void)setLanguage:(NSString *_Nonnull)language {
_language = language;

[[NSUserDefaults standardUserDefaults] setObject:_language forKey:languageKey];
[[NSUserDefaults standardUserDefaults] synchronize];

for(id<SettingsModelDelegate> delegate in [Settings sharedManager].delegates)
{
if ([delegate respondsToSelector:@selector(onChangeLanguage)]) {
[delegate onChangeLanguage];
}
}
_language = @"en";

// _language = language;
//
// [[NSUserDefaults standardUserDefaults] setObject:_language forKey:languageKey];
// [[NSUserDefaults standardUserDefaults] synchronize];
//
// for(id<SettingsModelDelegate> delegate in [Settings sharedManager].delegates)
// {
// if ([delegate respondsToSelector:@selector(onChangeLanguage)]) {
// [delegate onChangeLanguage];
// }
// }
}


Expand All @@ -371,7 +378,7 @@ -(NSString*_Nonnull)currencyName {
case BMCurrencyBTC:
return @"BTC";
default:
return @"";
return [@"off" localized];
}
}

Expand Down Expand Up @@ -466,8 +473,10 @@ -(NSString *)groupDBPath{
}

-(void)copyOldDatabaseToGroup {
// [[NSFileManager defaultManager] removeItemAtPath:[self walletStoragePath] error:nil];
// [[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"wallet_old" ofType:@"uu"] toPath:[self walletStoragePath] error:nil];
[[NSFileManager defaultManager] removeItemAtPath:[self walletStoragePath] error:nil];
NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"wallet" ofType:@"db"] toPath:[self walletStoragePath] error:&error];
NSLog(@"%@", error);

// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// NSString *documentsDirectory = [paths objectAtIndex:0];
Expand Down
Loading

0 comments on commit 0177207

Please sign in to comment.