Skip to content

Commit dfb8462

Browse files
committed
refactoring. dao.
1 parent 9c0827f commit dfb8462

22 files changed

Lines changed: 149 additions & 110 deletions

File tree

‎BeamWallet.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,7 +5008,7 @@
50085008
CLANG_WARN_ENUM_CONVERSION = NO;
50095009
CODE_SIGN_ENTITLEMENTS = Resources/BeamWallet.entitlements;
50105010
CODE_SIGN_STYLE = Automatic;
5011-
CURRENT_PROJECT_VERSION = 1;
5011+
CURRENT_PROJECT_VERSION = 8;
50125012
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
50135013
DEVELOPMENT_TEAM = KNU2R94BJK;
50145014
ENABLE_BITCODE = NO;
@@ -5083,7 +5083,7 @@
50835083
CLANG_WARN_ENUM_CONVERSION = NO;
50845084
CODE_SIGN_ENTITLEMENTS = Resources/BeamWallet.entitlements;
50855085
CODE_SIGN_STYLE = Automatic;
5086-
CURRENT_PROJECT_VERSION = 1;
5086+
CURRENT_PROJECT_VERSION = 8;
50875087
DEVELOPMENT_TEAM = KNU2R94BJK;
50885088
ENABLE_BITCODE = NO;
50895089
FRAMEWORK_SEARCH_PATHS = (
@@ -5322,7 +5322,7 @@
53225322
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
53235323
CODE_SIGN_IDENTITY = "iPhone Developer";
53245324
CODE_SIGN_STYLE = Automatic;
5325-
CURRENT_PROJECT_VERSION = 49;
5325+
CURRENT_PROJECT_VERSION = 63;
53265326
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
53275327
DEVELOPMENT_TEAM = KNU2R94BJK;
53285328
ENABLE_BITCODE = NO;
@@ -5402,7 +5402,7 @@
54025402
CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements;
54035403
CODE_SIGN_IDENTITY = "iPhone Developer";
54045404
CODE_SIGN_STYLE = Automatic;
5405-
CURRENT_PROJECT_VERSION = 49;
5405+
CURRENT_PROJECT_VERSION = 63;
54065406
DEVELOPMENT_TEAM = KNU2R94BJK;
54075407
ENABLE_BITCODE = NO;
54085408
FRAMEWORK_SEARCH_PATHS = (

‎BeamWallet/BeamSDK/AppModel.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ typedef void(^ExportCSVBlock)(NSString * _Nonnull data, NSURL * _Nonnull url);
136136
+(AppModel*_Nonnull)sharedManager;
137137

138138
+(NSString*_Nonnull)chooseRandomNode;
139-
+(NSArray*_Nonnull)randomNodes;
140139

141140
// delegates
142141
-(void)addDelegate:(id<WalletModelDelegate>_Nullable) delegate;

‎BeamWallet/BeamSDK/AppModel.mm‎

Lines changed: 33 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
#include <sys/sysctl.h>
7171
#import <sys/utsname.h>
7272

73-
#import "BeamWallet-Swift.h"
73+
//#import "BeamWallet-Swift.h"
74+
#import "BeamWalletMasterNet-Swift.h"
7475

7576
using namespace beam;
7677
using namespace ECC;
@@ -264,10 +265,12 @@ -(void)loadRules{
264265
}
265266

266267
+(NSString*_Nonnull)chooseRandomNodeWithoutNodes:(NSArray*)nodes {
267-
auto peers = getDefaultPeers();
268+
// return @"eu-node02.masternet.beam.mw:8100";
268269

270+
auto peers = getDefaultPeers();
271+
269272
NSMutableArray *array = [NSMutableArray array];
270-
273+
271274
for (const auto& item : peers) {
272275
BOOL found = NO;
273276
NSString *address = [NSString stringWithUTF8String:item.c_str()];
@@ -277,34 +280,19 @@ +(NSString*_Nonnull)chooseRandomNodeWithoutNodes:(NSArray*)nodes {
277280
found = YES;
278281
}
279282
}
280-
283+
281284
if (!found) {
282285
[array addObject:address];
283286
}
284287
}
285288
}
286-
287-
289+
290+
288291
if(array.count>0) {
289292
return array[0];
290293
}
291-
292-
return @"";
293-
}
294294

295-
+(NSArray*_Nonnull)randomNodes {
296-
auto peers = getDefaultPeers();
297-
298-
NSMutableArray *array = [NSMutableArray array];
299-
300-
for (const auto& item : peers) {
301-
NSString *address = [NSString stringWithUTF8String:item.c_str()];
302-
if([address rangeOfString:@"shanghai"].location == NSNotFound) {
303-
[array addObject:address];
304-
}
305-
}
306-
307-
return array;
295+
return @"";
308296
}
309297

310298
+(NSString*_Nonnull)chooseRandomNode {
@@ -1190,32 +1178,10 @@ -(BOOL)isAddress:(NSString*_Nullable)address {
11901178

11911179

11921180
-(BOOL)isExpiredAddress:(NSString*_Nullable)address {
1193-
if (address!=nil) {
1194-
if(address.length)
1195-
{
1196-
WalletID walletID(Zero);
1197-
if (walletID.FromHex(address.string))
1198-
{
1199-
try{
1200-
auto receiverAddr = walletDb->getAddress(walletID);
1201-
1202-
if(receiverAddr) {
1203-
if (receiverAddr->m_OwnID && receiverAddr->isExpired())
1204-
{
1205-
return YES;
1206-
}
1207-
}
1208-
}
1209-
catch (const std::exception& e) {
1210-
return NO;
1211-
}
1212-
catch (...) {
1213-
return NO;
1214-
}
1215-
}
1216-
}
1181+
BMAddress *addr = [self findAddressByID:address];
1182+
if (addr != nil && addr.isContact == NO && [addr isExpired]) {
1183+
return YES;
12171184
}
1218-
12191185
return NO;
12201186
}
12211187

@@ -3106,9 +3072,12 @@ -(void)approveContractInfo:(NSString*_Nonnull)json info:(NSString*_Nonnull)info
31063072

31073073
-(void)stopDAO {
31083074
[daoManager stopApp];
3075+
daoManager = nil;
31093076
}
31103077

31113078
-(void)startApp:(UIViewController*_Nonnull)controller app:(BMApp*)app {
3079+
daoManager = [[DAOManager alloc] initWithWallet:wallet];
3080+
31123081
BOOL isSupported = [daoManager appSupported:app];
31133082

31143083
__weak typeof(self) weakSelf = self;
@@ -3182,22 +3151,24 @@ -(void)loadApps {
31823151
NSArray *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
31833152

31843153
if (jsonError == nil) {
3185-
[strongSelf->_apps removeAllObjects];
3186-
3187-
for (NSDictionary *dct in jsonResponse) {
3188-
BMApp *app = [BMApp new];
3189-
[app setAPIResult:dct];
3190-
[app setIsSupported:[strongSelf->daoManager appSupported:app]];
3191-
if(app.icon == nil) {
3192-
app.icon = @"";
3154+
if(strongSelf->daoManager != nil) {
3155+
[strongSelf->_apps removeAllObjects];
3156+
3157+
for (NSDictionary *dct in jsonResponse) {
3158+
BMApp *app = [BMApp new];
3159+
[app setAPIResult:dct];
3160+
[app setIsSupported:[strongSelf->daoManager appSupported:app]];
3161+
if(app.icon == nil) {
3162+
app.icon = @"";
3163+
}
3164+
[strongSelf->_apps addObject:app];
31933165
}
3194-
[strongSelf->_apps addObject:app];
3195-
}
3196-
3197-
NSArray *delegates = [AppModel sharedManager].delegates.allObjects;
3198-
for(id<WalletModelDelegate> delegate in delegates) {
3199-
if ([delegate respondsToSelector:@selector(onDAPPsLoaded)]) {
3200-
[delegate onDAPPsLoaded];
3166+
3167+
NSArray *delegates = [AppModel sharedManager].delegates.allObjects;
3168+
for(id<WalletModelDelegate> delegate in delegates) {
3169+
if ([delegate respondsToSelector:@selector(onDAPPsLoaded)]) {
3170+
[delegate onDAPPsLoaded];
3171+
}
32013172
}
32023173
}
32033174
}

‎BeamWallet/BeamSDK/AssetsManager.mm‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#import "AppModel.h"
2323
#include "wallet/core/wallet.h"
2424

25-
static NSString *assetsKey = @"assetsKeyNew_21";
25+
static NSString *assetsKey = @"assetsKeyNew_2111";
2626

2727
NSArray *colors = @[@"#72fdff",@"#2acf1d",@"#ffbb54",@"#d885ff",@"#008eff",@"#ff746b",@"#91e300",@"#ffe75a",@"#9643ff",@"#395bff",@"#ff3b3b",@"#73ff7c",@"#ffa86c",@"#ff3abe",@"#00aee1",@"#ff5200",@"#6464ff",@"#ff7a21",@"#63afff",@"#c81f68"];
2828

@@ -63,7 +63,12 @@ -(id)init{
6363
[_assets addObject:asset];
6464

6565
BMAsset *beamX = [[BMAsset alloc] init];
66-
beamX.assetId = 7;
66+
if ([Settings.sharedManager target] == Masternet) {
67+
beamX.assetId = 5;
68+
}
69+
else {
70+
beamX.assetId = 7;
71+
}
6772
beamX.nthUnitName = @"BEAMX";
6873
beamX.unitName = @"BEAMX";
6974
beamX.color = @"#977dff";
@@ -79,8 +84,11 @@ -(id)init{
7984
}
8085

8186
-(NSString*_Nonnull)getAssetColor:(int)value {
82-
if (value == 31) {
83-
return @"#977dff";
87+
if(value == 5 && [Settings.sharedManager target] == Masternet) {
88+
return @"#977dff";
89+
}
90+
else if (value == 7) {
91+
return @"#977dff";
8492
}
8593
int idx = (value % colors.count);
8694
return colors[idx];
@@ -93,10 +101,6 @@ -(BMAsset*_Nullable)getAsset:(int)assetId {
93101
}
94102
}
95103

96-
if (assetId==31) {
97-
98-
}
99-
100104
return nil;
101105
}
102106

‎BeamWallet/BeamSDK/DAO/AppsApiUI.mm‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,37 @@
3737

3838
void AppsApiUI::sendApproved(const std::string& request)
3939
{
40-
LOG_INFO() << "Contract send approved: " << getAppName() << ", " << getAppId() << ", " << request;
40+
// LOG_INFO() << "Contract send approved: " << getAppName() << ", " << getAppId() << ", " << request;
4141
AnyThread_callWalletApiDirectly(request);
4242
}
4343

4444
void AppsApiUI::sendRejected(const std::string& request)
4545
{
46-
LOG_INFO() << "Contract send rejected: " << getAppName() << ", " << getAppId() << ", " << request;
46+
// LOG_INFO() << "Contract send rejected: " << getAppName() << ", " << getAppId() << ", " << request;
4747
AnyThread_sendApiError(request, beam::wallet::ApiError::UserRejected, std::string());
4848
}
4949

5050
void AppsApiUI::contractInfoApproved(const std::string& request)
5151
{
52-
LOG_INFO() << "Contract tx approved: " << getAppName() << ", " << getAppId() << ", " << request;
52+
// LOG_INFO() << "Contract tx approved: " << getAppName() << ", " << getAppId() << ", " << request;
5353
AnyThread_callWalletApiDirectly(request);
5454
}
5555

5656
void AppsApiUI::contractInfoRejected(const std::string& request)
5757
{
58-
LOG_INFO() << "Contract tx rejected: " << getAppName() << ", " << getAppId() << ", " << request;
58+
// LOG_INFO() << "Contract tx rejected: " << getAppName() << ", " << getAppId() << ", " << request;
5959
AnyThread_sendApiError(request, beam::wallet::ApiError::UserRejected, std::string());
6060
}
6161

6262
void AppsApiUI::callWalletApi(const std::string& request)
6363
{
64-
LOG_INFO() << "Call Wallet Api: " << getAppName() << ", " << getAppId() << ", " << request;
64+
//LOG_INFO() << "Call Wallet Api: " << getAppName() << ", " << getAppId() << ", " << request;
6565
AnyThread_callWalletApiChecked(request);
6666
}
6767

6868
void AppsApiUI::AnyThread_sendApiResponse(const std::string& result)
6969
{
70-
LOG_INFO() << "Send Api Response: " << getAppName() << ", " << getAppId() << ", " << result;
70+
// LOG_INFO() << "Send Api Response: " << getAppName() << ", " << getAppId() << ", " << result;
7171
NSString *json = [NSString stringWithUTF8String:result.c_str()];
7272
[[AppModel sharedManager] sendDAOApiResult:json];
7373
}

‎BeamWallet/BeamSDK/DAO/DAOManager.mm‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ -(BOOL)appSupported:(BMApp*_Nonnull)app {
4343
}
4444

4545
-(void)stopApp {
46-
webAPICreator._api.~shared_ptr();
47-
webAPICreator.~WebAPICreator();
46+
// webAPICreator._api.~shared_ptr();
47+
webAPICreator._api.reset();
48+
// webAPICreator._api = nil;
49+
//
50+
// webAPICreator = nil;
51+
52+
// webAPICreator._api.~shared_ptr();
53+
// webAPICreator.~WebAPICreator();
4854
}
4955

5056
-(void)launchApp:(BMApp*_Nonnull)app {
@@ -64,15 +70,21 @@ -(void)launchApp:(BMApp*_Nonnull)app {
6470
}
6571

6672
-(void)callWalletApi:(NSString*_Nonnull)json {
67-
webAPICreator._api->callWalletApi(json.string);
73+
if(webAPICreator._api != nil) {
74+
webAPICreator._api->callWalletApi(json.string);
75+
}
6876
}
6977

7078
-(void)contractInfoApproved:(NSString*_Nonnull)json {
71-
webAPICreator._api->contractInfoApproved(json.string);
79+
if(webAPICreator._api != nil) {
80+
webAPICreator._api->contractInfoApproved(json.string);
81+
}
7282
}
7383

7484
-(void)contractInfoRejected:(NSString*_Nonnull)json {
75-
webAPICreator._api->contractInfoRejected(json.string);
85+
if(webAPICreator._api != nil) {
86+
webAPICreator._api->contractInfoRejected(json.string);
87+
}
7688
}
7789

7890
@end

‎BeamWallet/BeamSDK/Objects/BMAsset.m‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "ExchangeManager.h"
2323
#import "BMTransaction.h"
2424
#import "AssetsManager.h"
25+
#import "Settings.h"
2526

2627
@implementation BMAsset
2728

@@ -126,6 +127,9 @@ -(BOOL)isBeam {
126127
}
127128

128129
-(BOOL)isBeamX {
130+
if(_assetId == 5 && [Settings.sharedManager target] == Masternet) {
131+
return TRUE;
132+
}
129133
return _assetId == 7;
130134
}
131135

‎BeamWallet/BeamSDK/WalletModel.mm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@
16251625
asset.site = site;
16261626
asset.color = color;
16271627
asset.paper = paper;
1628-
if(asset.assetId == 11 && [Settings.sharedManager target] == Mainnet) {
1628+
if(asset.assetId == 11 && [Settings.sharedManager target] == Testnet) {
16291629
asset.color = @"#977dff";
16301630
}
16311631
else if(asset.assetId == 5 && [Settings.sharedManager target] == Masternet) {

‎BeamWallet/ViewControllers/Main/Addresses/AddressViewController.swift‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ extension AddressViewController : UITableViewDataSource {
185185
if Settings.sharedManager().isDarkMode {
186186
header.backgroundColor = UIColor.main.marineThree
187187
}
188+
else if Settings.sharedManager().target == Mainnet {
189+
header.backgroundColor = UIColor.init(red: 17 / 255, green: 41 / 255, blue: 73 / 255, alpha: 1)
190+
}
188191
else {
189192
header.backgroundColor = UIColor.init(red: 28 / 255, green: 28 / 255, blue: 28 / 255, alpha: 1)
190193
}

‎BeamWallet/ViewControllers/Main/Assets/AssetDetailViewController.swift‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ extension AssetDetailViewController: UITableViewDelegate {
218218
tableView.deselectRow(at: indexPath, animated: true)
219219

220220
if indexPath.section == 2, transactionViewModel.transactions.count > 0 {
221-
let vc = TransactionViewController(transaction: transactionViewModel.transactions[indexPath.row])
222-
vc.hidesBottomBarWhenPushed = true
221+
let vc = TransactionPageViewController(transaction: transactionViewModel.transactions[indexPath.row], preview: false)
223222
pushViewController(vc: vc)
224223
}
225224
}

0 commit comments

Comments
 (0)