Skip to content

Commit

Permalink
Converted dictionary to json string with mj_JSONString api
Browse files Browse the repository at this point in the history
  • Loading branch information
GinMu committed Jan 9, 2019
1 parent cab698b commit 716a866
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion jcc_oc_base_lib.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "jcc_oc_base_lib"
s.version = "0.1.0"
s.version = "0.1.1"
s.summary = "An interface for interacting with the blockchain wallet operation for ios"

# This description is used to generate tags and improve search results.
Expand Down
23 changes: 4 additions & 19 deletions jcc_oc_base_lib/Jingtum/JTWalletManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ - (void)importSecret:(NSString *)secret chain:(NSString *)chain completion:(void
NSMutableDictionary *parms = [[NSMutableDictionary alloc] initWithCapacity:0];
[parms setObject:secret forKey:@"secret"];
[parms setObject:chain forKey:@"chain"];
NSString *json = [weakSelf dataTojsonString:parms];
NSString *json = [parms mj_JSONString];
[_bridge callHandler:@"importJingtumSecret" data:json responseCallback:^(id responseData) {
if ([responseData isKindOfClass:[NSDictionary class]]) {
JingtumWallet *wallet = [JingtumWallet mj_objectWithKeyValues:responseData];
Expand All @@ -69,11 +69,10 @@ - (void)importSecret:(NSString *)secret chain:(NSString *)chain completion:(void
}

- (void)isValidAddress:(NSString *)address chain:(NSString *)chain completion:(void (^)(BOOL))completion {
__weak typeof(self) weakSelf = self;
NSMutableDictionary *parms = [[NSMutableDictionary alloc] initWithCapacity:0];
[parms setObject:address forKey:@"address"];
[parms setObject:chain forKey:@"chain"];
NSString *json = [weakSelf dataTojsonString:parms];
NSString *json = [parms mj_JSONString];
[_bridge callHandler:@"isJingtumAddress" data:json responseCallback:^(id responseData) {
if(completion) {
completion([responseData boolValue]);
Expand All @@ -82,11 +81,10 @@ - (void)isValidAddress:(NSString *)address chain:(NSString *)chain completion:(v
}

- (void)isValidSecret:(NSString *)secret chain:(NSString *)chain completion:(void (^)(BOOL))completion {
__weak typeof(self) weakSelf = self;
NSMutableDictionary *parms = [[NSMutableDictionary alloc] initWithCapacity:0];
[parms setObject:secret forKey:@"secret"];
[parms setObject:chain forKey:@"chain"];
NSString *json = [weakSelf dataTojsonString:parms];
NSString *json = [parms mj_JSONString];
[_bridge callHandler:@"isJingtumSecret" data:json responseCallback:^(id responseData) {
if(completion) {
completion([responseData boolValue]);
Expand All @@ -100,7 +98,7 @@ - (void)sign:(NSDictionary *)transaction secret:(NSString *)secret chain:(NSStri
[parms setObject:transaction forKey:@"transaction"];
[parms setObject:secret forKey:@"secret"];
[parms setObject:chain forKey:@"chain"];
NSString *json = [weakSelf dataTojsonString:parms];
NSString *json = [parms mj_JSONString];
[_bridge callHandler:@"jingtumSign" data:json responseCallback:^(id responseData) {
if ([responseData isKindOfClass:[NSString class]]) {
if (completion) {
Expand Down Expand Up @@ -145,19 +143,6 @@ - (void)loadHtml: (WKWebView*)webView {
[webView loadHTMLString:appHtml baseURL:baseURL];
}

- (NSString *)dataTojsonString:(id)object {

NSString *jsonString = nil;
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object options:NSJSONWritingPrettyPrinted error:&error];
if (!jsonData) {
NSLog(@"error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}

- (NSError *)errorDomain:(NSString *)domain reason:(NSString *)reason {
NSError *error = [NSError errorWithDomain:domain code:-1 userInfo:@{NSLocalizedDescriptionKey:reason}];
return error;
Expand Down

0 comments on commit 716a866

Please sign in to comment.