2016-09-07 17:35:04 +00:00
|
|
|
#import "RCTStatus.h"
|
2017-04-24 14:50:16 +00:00
|
|
|
#import "React/RCTBridge.h"
|
|
|
|
#import "React/RCTEventDispatcher.h"
|
2021-03-29 16:23:40 +00:00
|
|
|
#import "Statusgo.h"
|
2024-11-19 10:50:01 +00:00
|
|
|
#import "StatusBackendClient.h"
|
2024-01-15 13:27:35 +00:00
|
|
|
#import "Utils.h"
|
2016-09-07 17:35:04 +00:00
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
static RCTBridge *bridge;
|
2019-02-12 11:35:26 +00:00
|
|
|
|
|
|
|
@implementation Status
|
|
|
|
|
2024-11-19 10:50:01 +00:00
|
|
|
+ (Status *)sharedInstance {
|
|
|
|
static Status *sharedInstance = nil;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
sharedInstance = [[self alloc] init];
|
|
|
|
});
|
|
|
|
return sharedInstance;
|
|
|
|
}
|
|
|
|
|
2019-02-12 11:35:26 +00:00
|
|
|
- (instancetype)init {
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
// Subscribing to the signals from Status-Go
|
|
|
|
StatusgoSetMobileSignalHandler(self);
|
|
|
|
return self;
|
2016-09-12 08:16:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-11 14:24:52 +00:00
|
|
|
-(RCTBridge *)bridge
|
|
|
|
{
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setBridge:(RCTBridge *)newBridge
|
|
|
|
{
|
|
|
|
bridge = newBridge;
|
|
|
|
}
|
2016-09-07 17:35:04 +00:00
|
|
|
|
2019-02-12 11:35:26 +00:00
|
|
|
- (void)handleSignal:(NSString *)signal
|
|
|
|
{
|
|
|
|
if(!signal){
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"SignalEvent nil");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[bridge.eventDispatcher sendAppEventWithName:@"gethEvent"
|
|
|
|
body:@{@"jsonEvent": signal}];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
|
2017-03-07 17:29:59 +00:00
|
|
|
#pragma mark - shouldMoveToInternalStorage
|
2022-12-16 17:09:39 +00:00
|
|
|
|
2017-03-07 17:29:59 +00:00
|
|
|
RCT_EXPORT_METHOD(shouldMoveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - moveToInternalStorage
|
2022-12-16 17:09:39 +00:00
|
|
|
|
2017-03-07 17:29:59 +00:00
|
|
|
RCT_EXPORT_METHOD(moveToInternalStorage:(RCTResponseSenderBlock)onResultCallback) {
|
|
|
|
// Android only
|
|
|
|
onResultCallback(@[[NSNull null]]);
|
|
|
|
}
|
|
|
|
|
2019-05-03 14:22:43 +00:00
|
|
|
RCT_EXPORT_METHOD(exportLogs:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"exportLogs() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoExportNodeLogs();
|
|
|
|
callback(@[result]);
|
2018-12-15 18:57:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 07:53:40 +00:00
|
|
|
RCT_EXPORT_METHOD(deleteImportedKey:(NSString *)keyUID
|
|
|
|
address:(NSString *)address
|
|
|
|
password:(NSString *)password
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2024-11-19 10:50:01 +00:00
|
|
|
NSLog(@"DeleteImportedKeyV2() method called");
|
2021-08-13 07:53:40 +00:00
|
|
|
#endif
|
2024-01-15 13:27:35 +00:00
|
|
|
NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID];
|
2024-11-19 10:50:01 +00:00
|
|
|
NSString *jsonParams = [NSString stringWithFormat:@"{\"address\":\"%@\",\"password\":\"%@\",\"keyStoreDir\":\"%@\"}",
|
|
|
|
address, password, multiaccountKeystoreDir.path];
|
|
|
|
[StatusBackendClient executeStatusGoRequestWithCallback:@"DeleteImportedKeyV2"
|
|
|
|
body:jsonParams
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoDeleteImportedKeyV2(jsonParams);
|
|
|
|
}
|
|
|
|
callback:callback];
|
2019-08-12 08:53:31 +00:00
|
|
|
}
|
2019-05-13 07:58:41 +00:00
|
|
|
|
2021-05-31 13:10:54 +00:00
|
|
|
#pragma mark - GetNodeConfig
|
2022-12-16 17:09:39 +00:00
|
|
|
|
2021-05-31 13:10:54 +00:00
|
|
|
RCT_EXPORT_METHOD(getNodeConfig:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"GetNodeConfig() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
[StatusBackendClient executeStatusGoRequestWithCallback:@"GetNodeConfig"
|
|
|
|
body:@""
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoGetNodeConfig();
|
|
|
|
}
|
|
|
|
callback:callback];
|
2021-05-31 13:10:54 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 14:49:54 +00:00
|
|
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(fleets) {
|
2024-11-19 10:50:01 +00:00
|
|
|
return [StatusBackendClient executeStatusGoRequestWithResult:@"Fleets"
|
|
|
|
body:@""
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoFleets();
|
|
|
|
}];
|
2023-11-24 14:49:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 11:23:25 +00:00
|
|
|
RCT_EXPORT_METHOD(closeApplication) {
|
|
|
|
exit(0);
|
|
|
|
}
|
2017-04-18 14:22:05 +00:00
|
|
|
|
2018-02-26 02:27:29 +00:00
|
|
|
RCT_EXPORT_METHOD(connectionChange:(NSString *)type
|
|
|
|
isExpensive:(BOOL)isExpensive) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"ConnectionChange() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
NSDictionary *params = @{
|
|
|
|
@"type": type,
|
|
|
|
@"expensive": @(isExpensive)
|
|
|
|
};
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params
|
|
|
|
options:0
|
|
|
|
error:&error];
|
|
|
|
if (error) {
|
|
|
|
NSLog(@"Error creating JSON: %@", error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonData) {
|
|
|
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
[StatusBackendClient executeStatusGoRequest:@"ConnectionChangeV2"
|
|
|
|
body:jsonString
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoConnectionChangeV2(jsonString);
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
NSLog(@"Failed to create JSON data");
|
|
|
|
}
|
2018-02-26 02:27:29 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 10:50:01 +00:00
|
|
|
RCT_EXPORT_METHOD(appStateChange:(NSString *)state) {
|
2018-03-16 12:01:10 +00:00
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AppStateChange() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
NSDictionary *params = @{@"state": state};
|
|
|
|
NSError *error;
|
|
|
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params
|
|
|
|
options:0
|
|
|
|
error:&error];
|
|
|
|
if (error) {
|
|
|
|
NSLog(@"Error creating JSON: %@", error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jsonData) {
|
|
|
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
[StatusBackendClient executeStatusGoRequest:@"AppStateChangeV2"
|
|
|
|
body:jsonString
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoAppStateChangeV2(jsonString);
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
NSLog(@"Failed to create JSON data");
|
|
|
|
}
|
2018-03-16 12:01:10 +00:00
|
|
|
}
|
|
|
|
|
2024-07-04 15:45:00 +00:00
|
|
|
RCT_EXPORT_METHOD(addCentralizedMetric:(NSString *)request
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"addCentralizedMetric() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
[StatusBackendClient executeStatusGoRequestWithCallback:@"AddCentralizedMetric"
|
|
|
|
body:request
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoAddCentralizedMetric(request);
|
|
|
|
}
|
|
|
|
callback:callback];
|
2024-07-04 15:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(toggleCentralizedMetrics:(NSString *)request
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"toggleCentralizedMetrics() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
[StatusBackendClient executeStatusGoRequestWithCallback:@"ToggleCentralizedMetrics"
|
|
|
|
body:request
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoToggleCentralizedMetrics(request);
|
|
|
|
}
|
|
|
|
callback:callback];
|
2024-07-04 15:45:00 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 12:35:10 +00:00
|
|
|
RCT_EXPORT_METHOD(startLocalNotifications) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"StartLocalNotifications() method called");
|
|
|
|
#endif
|
2024-11-19 10:50:01 +00:00
|
|
|
[StatusBackendClient executeStatusGoRequest:@"StartLocalNotifications"
|
|
|
|
body:@""
|
|
|
|
statusgoFunction:^NSString *{
|
|
|
|
return StatusgoStartLocalNotifications();
|
|
|
|
}];
|
2020-09-25 12:35:10 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 17:09:39 +00:00
|
|
|
#pragma mark - deviceinfo
|
2019-05-30 14:01:20 +00:00
|
|
|
|
2018-08-03 16:43:37 +00:00
|
|
|
- (bool) is24Hour
|
|
|
|
{
|
|
|
|
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
|
|
|
|
return ([format rangeOfString:@"a"].location == NSNotFound);
|
|
|
|
}
|
|
|
|
|
2019-05-30 14:01:20 +00:00
|
|
|
- (NSString *)getBuildId {
|
|
|
|
return @"not available";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) deviceId
|
|
|
|
{
|
|
|
|
struct utsname systemInfo;
|
|
|
|
|
|
|
|
uname(&systemInfo);
|
|
|
|
|
|
|
|
NSString* deviceId = [NSString stringWithCString:systemInfo.machine
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
if ([deviceId isEqualToString:@"i386"] || [deviceId isEqualToString:@"x86_64"] ) {
|
|
|
|
deviceId = [NSString stringWithFormat:@"%s", getenv("SIMULATOR_MODEL_IDENTIFIER")];
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*) deviceName
|
|
|
|
{
|
2024-01-15 13:27:35 +00:00
|
|
|
return [[UIDevice currentDevice] name];
|
2019-05-30 14:01:20 +00:00
|
|
|
}
|
|
|
|
|
2018-08-03 16:43:37 +00:00
|
|
|
- (NSDictionary *)constantsToExport
|
|
|
|
{
|
|
|
|
return @{
|
|
|
|
@"is24Hour": @(self.is24Hour),
|
2019-05-30 14:01:20 +00:00
|
|
|
@"model": self.deviceName ?: [NSNull null],
|
|
|
|
@"brand": @"Apple",
|
|
|
|
@"buildId": [self getBuildId],
|
|
|
|
@"deviceId": self.deviceId ?: [NSNull null],
|
2018-08-03 16:43:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:54:29 +00:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2016-09-07 17:35:04 +00:00
|
|
|
@end
|