2
This commit is contained in:
@@ -82,4 +82,35 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)fetchWalletBalanceWithCompletion:(KBShopBalanceCompletion)completion {
|
||||
[[KBNetworkManager shared] GET:API_WALLET_BALANCE
|
||||
parameters:nil
|
||||
headers:nil
|
||||
autoShowBusinessError:NO
|
||||
completion:^(NSDictionary * _Nullable json,
|
||||
NSURLResponse * _Nullable response,
|
||||
NSError * _Nullable error) {
|
||||
if (error) {
|
||||
if (completion) completion(nil, error);
|
||||
return;
|
||||
}
|
||||
id dataObj = json[KBData] ?: json[@"data"];
|
||||
if (![dataObj isKindOfClass:[NSDictionary class]]) {
|
||||
if (completion) completion(nil, [self kb_invalidResponseError]);
|
||||
return;
|
||||
}
|
||||
id balanceValue = dataObj[@"balance"];
|
||||
NSNumber *balanceNumber = nil;
|
||||
if ([balanceValue isKindOfClass:[NSNumber class]]) {
|
||||
balanceNumber = balanceValue;
|
||||
} else if ([balanceValue isKindOfClass:[NSString class]]) {
|
||||
balanceNumber = @([(NSString *)balanceValue doubleValue]);
|
||||
}
|
||||
if (!balanceNumber) {
|
||||
balanceNumber = @(0);
|
||||
}
|
||||
if (completion) completion(balanceNumber, nil);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user