Skip to content

Commit 0177207

Browse files
committed
init
1 parent 562182c commit 0177207

37 files changed

+419
-264
lines changed

BeamWallet.xcodeproj/project.pbxproj

Lines changed: 100 additions & 86 deletions
Large diffs are not rendered by default.

BeamWallet/AppDelegate.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
134134
AppModel.sharedManager().connectionTimer = nil
135135
}
136136

137-
if AppModel.sharedManager().isRestoreFlow || AppModel.sharedManager().isUpdating {
138-
self.registerBackgroundTask()
139-
}
137+
self.registerBackgroundTask()
140138

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

166164
func applicationWillEnterForeground(_ application: UIApplication) {
167-
if AppModel.sharedManager().isRestoreFlow || AppModel.sharedManager().isUpdating {
168-
self.endBackgroundTask()
169-
}
165+
self.endBackgroundTask()
170166
}
171167

172168
func applicationDidBecomeActive(_ application: UIApplication) {

BeamWallet/BeamSDK/AppModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,6 @@ typedef void(^ExportOwnerKey)(NSString * _Nonnull key);
253253
-(void)deleteNotification:(NSString*_Nonnull) notifId;
254254
-(void)deleteAllNotifications;
255255
-(BMNotification*_Nullable)getLastVersionNotification;
256+
-(void)readAllNotifications;
256257

257258
@end

BeamWallet/BeamSDK/AppModel.mm

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ -(void)start {
680680
wallet = make_shared<WalletModel>(walletDb, nodeAddrStr, walletReactor);
681681
wallet->getAsync()->setNodeAddress(nodeAddrStr);
682682

683-
wallet->start(activeNotifications, isSecondCurrencyEnabled);
683+
wallet->start(activeNotifications, false, isSecondCurrencyEnabled);
684684

685685
isRunning = YES;
686686
isStarted = YES;
@@ -698,7 +698,7 @@ -(void)start {
698698
if(self.isInternetAvailable && isRunning == NO && ![[Settings sharedManager] isLocalNode])
699699
{
700700
isRunning = YES;
701-
wallet->start(activeNotifications, isSecondCurrencyEnabled);
701+
wallet->start(activeNotifications, false, isSecondCurrencyEnabled);
702702
}
703703
}
704704
}
@@ -752,12 +752,16 @@ -(BOOL)isValidNodeAddress:(NSString*_Nonnull)string {
752752
}
753753

754754
-(void)exportOwnerKey:(NSString*_Nonnull)password result:(ExportOwnerKey _Nonnull)block{
755+
if(self->wallet == nil) {
756+
[self start];
757+
}
758+
755759
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
756760
dispatch_async(queue, ^{
757761
auto pass = SecString(password.string);
758-
762+
759763
const auto& ownerKey = self->wallet->exportOwnerKey(pass);
760-
764+
761765
NSString *exportedKey = [NSString stringWithUTF8String:ownerKey.c_str()];
762766
dispatch_async(dispatch_get_main_queue(), ^{
763767
block(exportedKey);
@@ -1335,6 +1339,8 @@ -(void)editAddress:(BMAddress*_Nonnull)address {
13351339
}
13361340

13371341
if(address.isNowExpired) {
1342+
[_presendedNotifications setValue:address.walletId forKey:address.walletId];
1343+
13381344
wallet->getAsync()->updateAddress(walletID, address.label.string, WalletAddress::ExpirationStatus::Expired);
13391345
}
13401346
else if(address.isNowActive) {
@@ -1563,19 +1569,25 @@ -(void)send:(double)amount fee:(double)fee to:(NSString*_Nonnull)to comment:(NSS
15631569
auto bAmount = round(amount * Rules::Coin);
15641570

15651571
try{
1566-
__block BMAddress *address = [[AppModel sharedManager] findAddressByID:to];
1567-
1572+
// __block BMAddress *address = [[AppModel sharedManager] findAddressByID:to];
1573+
1574+
__block auto address = walletDb->getAddress(walletID);
1575+
15681576
wallet->getAsync()->sendMoney(fromID, walletID, comment.string, bAmount, fee);
15691577
wallet->getAsync()->getWalletStatus();
15701578

1571-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
1572-
if ([[AppModel sharedManager] isMyAddress:to]) {
1573-
[[AppModel sharedManager] setWalletComment:address.label toAddress:address.walletId];
1574-
}
1575-
else if (address != nil){
1576-
[[AppModel sharedManager] setContactComment:address.label toAddress:address.walletId];
1577-
}
1578-
});
1579+
if(address) {
1580+
__block NSString *name = [NSString stringWithUTF8String:address->m_label.c_str()];
1581+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
1582+
if (address->isOwn()) {
1583+
[[AppModel sharedManager] setWalletComment:name toAddress:to];
1584+
}
1585+
else {
1586+
[[AppModel sharedManager] setContactComment:name toAddress:to];
1587+
}
1588+
});
1589+
}
1590+
15791591
}
15801592
catch(NSException *ex) {
15811593
NSLog(@"%@",ex);
@@ -2469,8 +2481,14 @@ -(NSString*_Nonnull)exportData:(NSArray*_Nonnull)items{
24692481
}
24702482

24712483
-(NSString*_Nonnull)exchangeValue:(double)amount {
2472-
for (BMCurrency *currency in _currencies) {
2473-
if(currency.type == Settings.sharedManager.currency) {
2484+
if(Settings.sharedManager.currency == BMCurrencyOff) {
2485+
return @"";
2486+
}
2487+
if(amount == 0.0) {
2488+
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
2489+
}
2490+
for (BMCurrency *currency in [_currencies objectEnumerator].allObjects) {
2491+
if(currency.type == Settings.sharedManager.currency && currency.value > 0) {
24742492
currencyFormatter.maximumFractionDigits = currency.maximumFractionDigits;
24752493
currencyFormatter.positiveSuffix = [NSString stringWithFormat:@" %@",currency.code];
24762494

@@ -2480,15 +2498,18 @@ -(NSString*_Nonnull)exchangeValue:(double)amount {
24802498
}
24812499
}
24822500

2483-
return @"";
2501+
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
24842502
}
24852503

24862504
-(NSString*_Nonnull)exchangeValueFee:(double)amount {
2505+
if(Settings.sharedManager.currency == BMCurrencyOff) {
2506+
return @"";
2507+
}
24872508
if(amount == 0) {
24882509
return @"";
24892510
}
24902511
for (BMCurrency *currency in _currencies) {
2491-
if(currency.type == Settings.sharedManager.currency) {
2512+
if(currency.type == Settings.sharedManager.currency && currency.value > 0) {
24922513
currencyFormatter.maximumFractionDigits = currency.maximumFractionDigits;
24932514
currencyFormatter.positiveSuffix = [NSString stringWithFormat:@" %@",currency.code];
24942515

@@ -2507,7 +2528,7 @@ -(NSString*_Nonnull)exchangeValueFee:(double)amount {
25072528
}
25082529
}
25092530

2510-
return @"";
2531+
return [NSString stringWithFormat:@"-%@",Settings.sharedManager.currencyName];
25112532
}
25122533

25132534
#pragma mark - Notifications
@@ -2608,6 +2629,14 @@ -(void)clearNotifications {
26082629
[_presendedNotifications removeAllObjects];
26092630
}
26102631

2632+
-(void)readAllNotifications {
2633+
NSMutableArray *notifications = [NSMutableArray arrayWithArray:_notifications];
2634+
for (BMNotification *notification in notifications) {
2635+
if(![notification isRead]) {
2636+
[self readNotification: notification.nId];
2637+
}
2638+
}
2639+
}
26112640

26122641
@end
26132642

BeamWallet/BeamSDK/ObjcExtensions/StringLocalize.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
@implementation NSString (Localization)
2424

2525
-(NSString*)localized {
26+
NSString *result = @"";
27+
2628
NSString *lang = [Settings sharedManager].language;
2729

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

3537
if (bundle!=nil) {
36-
return NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
38+
result = NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
3739
}
3840
}
3941

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

43-
return NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
45+
result = NSLocalizedStringWithDefaultValue(self, nil, bundle, @"", @"");
46+
47+
if ([result isEqualToString:self]) {
48+
NSString *pathEn = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
49+
NSBundle * bundleEn = [[NSBundle alloc] initWithPath:pathEn];
50+
result = NSLocalizedStringWithDefaultValue(self, nil, bundleEn, @"", @"");
51+
}
52+
53+
return result;
4454
}
4555

4656
@end

BeamWallet/BeamSDK/Objects/BMCurrency.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
enum {
2222
BEAM = 0,
2323
BMCurrencyUSD = 1,
24-
BMCurrencyBTC = 2
24+
BMCurrencyBTC = 2,
25+
BMCurrencyOff = 3
2526
};
2627
typedef int BMCurrencyType;
2728

BeamWallet/BeamSDK/RecoveryProgress.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
}
112112
}
113113

114-
bool RecoveryProgress::OnProgress(uint64_t done, uint64_t total) {
114+
bool RecoveryProgress::OnProgress(uint64_t done, uint64_t total) {
115115
if (!m_isStart) {
116116
m_isStart = true;
117117

BeamWallet/BeamSDK/Settings.m

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ + (Settings*_Nonnull)sharedManager {
5454
-(id)init {
5555
self = [super init];
5656

57+
5758
_delegates = [NSHashTable weakObjectsHashTable];
5859

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

72+
// [self copyOldDatabaseToGroup];
73+
7174
_isLocalNode = NO;
7275

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

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

150-
if ([[NSUserDefaults standardUserDefaults] objectForKey:languageKey]) {
151-
_language = [[NSUserDefaults standardUserDefaults] objectForKey:languageKey];
152-
}
153-
else{
154-
_language = [[NSLocale currentLocale] languageCode];
155-
156-
if ([_language isEqualToString:@"zh"]) {
157-
_language = @"zh-Hans";
158-
}
159-
160-
if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:_language ofType:@"lproj"]]) {
161-
_language = @"en";
162-
}
163-
}
153+
_language = @"en";
154+
155+
// if ([[NSUserDefaults standardUserDefaults] objectForKey:languageKey]) {
156+
// _language = [[NSUserDefaults standardUserDefaults] objectForKey:languageKey];
157+
// }
158+
// else{
159+
// _language = [[NSLocale currentLocale] languageCode];
160+
//
161+
// if ([_language isEqualToString:@"zh"]) {
162+
// _language = @"zh-Hans";
163+
// }
164+
//
165+
// if (![[NSFileManager defaultManager] fileExistsAtPath:[[NSBundle mainBundle] pathForResource:_language ofType:@"lproj"]]) {
166+
// _language = @"en";
167+
// }
168+
// }
164169

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

338343
-(void)setLanguage:(NSString *_Nonnull)language {
339-
_language = language;
340-
341-
[[NSUserDefaults standardUserDefaults] setObject:_language forKey:languageKey];
342-
[[NSUserDefaults standardUserDefaults] synchronize];
343-
344-
for(id<SettingsModelDelegate> delegate in [Settings sharedManager].delegates)
345-
{
346-
if ([delegate respondsToSelector:@selector(onChangeLanguage)]) {
347-
[delegate onChangeLanguage];
348-
}
349-
}
344+
_language = @"en";
345+
346+
// _language = language;
347+
//
348+
// [[NSUserDefaults standardUserDefaults] setObject:_language forKey:languageKey];
349+
// [[NSUserDefaults standardUserDefaults] synchronize];
350+
//
351+
// for(id<SettingsModelDelegate> delegate in [Settings sharedManager].delegates)
352+
// {
353+
// if ([delegate respondsToSelector:@selector(onChangeLanguage)]) {
354+
// [delegate onChangeLanguage];
355+
// }
356+
// }
350357
}
351358

352359

@@ -371,7 +378,7 @@ -(NSString*_Nonnull)currencyName {
371378
case BMCurrencyBTC:
372379
return @"BTC";
373380
default:
374-
return @"";
381+
return [@"off" localized];
375382
}
376383
}
377384

@@ -466,8 +473,10 @@ -(NSString *)groupDBPath{
466473
}
467474

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

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

0 commit comments

Comments
 (0)