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"
|
2017-05-22 08:43:13 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"[handleSignal] Received an event from Status-Go: %@", signal);
|
|
|
|
#endif
|
|
|
|
[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
|
|
|
|
NSLog(@"DeleteImportedKey() method called");
|
|
|
|
#endif
|
2024-01-15 13:27:35 +00:00
|
|
|
NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID];
|
2021-08-13 07:53:40 +00:00
|
|
|
NSString *result = StatusgoDeleteImportedKey(address, password, multiaccountKeystoreDir.path);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:11:10 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountGenerateAndDeriveAddresses:(NSString *)json
|
2019-05-13 07:58:41 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2019-07-19 14:11:10 +00:00
|
|
|
NSLog(@"MultiAccountGenerateAndDeriveAddresses() method called");
|
2019-05-13 07:58:41 +00:00
|
|
|
#endif
|
2019-07-19 14:11:10 +00:00
|
|
|
NSString *result = StatusgoMultiAccountGenerateAndDeriveAddresses(json);
|
2019-05-13 07:58:41 +00:00
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-08-12 08:53:31 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountStoreAccount:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountStoreAccount() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountStoreAccount(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_EXPORT_METHOD(multiAccountLoadAccount:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountLoadAccount() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountLoadAccount(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:11:10 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountStoreDerived:(NSString *)json
|
2019-05-13 07:58:41 +00:00
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
2019-07-19 14:11:10 +00:00
|
|
|
NSLog(@"MultiAccountStoreDerived() method called");
|
2019-05-13 07:58:41 +00:00
|
|
|
#endif
|
2019-07-19 14:11:10 +00:00
|
|
|
NSString *result = StatusgoMultiAccountStoreDerivedAccounts(json);
|
2019-05-13 07:58:41 +00:00
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2020-02-28 11:37:16 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountImportPrivateKey:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountImportPrivateKey() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountImportPrivateKey(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:49:33 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountImportMnemonic:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountImportMnemonic() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountImportMnemonic(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2019-08-12 08:53:31 +00:00
|
|
|
RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json
|
|
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"MultiAccountDeriveAddresses() method called");
|
|
|
|
#endif
|
|
|
|
NSString *result = StatusgoMultiAccountDeriveAddresses(json);
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
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
|
|
|
|
NSString *result = StatusgoGetNodeConfig();
|
|
|
|
callback(@[result]);
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:49:54 +00:00
|
|
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(fleets) {
|
|
|
|
return StatusgoFleets();
|
|
|
|
}
|
|
|
|
|
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
|
2019-02-12 11:35:26 +00:00
|
|
|
StatusgoConnectionChange(type, isExpensive ? 1 : 0);
|
2018-02-26 02:27:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 12:01:10 +00:00
|
|
|
RCT_EXPORT_METHOD(appStateChange:(NSString *)type) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"AppStateChange() method called");
|
|
|
|
#endif
|
2019-02-12 11:35:26 +00:00
|
|
|
StatusgoAppStateChange(type);
|
2018-03-16 12:01:10 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 12:35:10 +00:00
|
|
|
RCT_EXPORT_METHOD(startLocalNotifications) {
|
|
|
|
#if DEBUG
|
|
|
|
NSLog(@"StartLocalNotifications() method called");
|
|
|
|
#endif
|
|
|
|
StatusgoStartLocalNotifications();
|
|
|
|
}
|
|
|
|
|
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
|