@@ -333,40 +333,51 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
333333
334334 [SCGateway.shared launchSmallPlugWithPresentingController: [[[UIApplication sharedApplication ] keyWindow ] rootViewController ] smallplugData: smallplugData completion: ^(id smallplugResponse, NSError * error) {
335335
336- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
337-
338336 if (error != nil ) {
339337 NSLog (@" %@ " , error.domain );
340338 double delayInSeconds = 0.5 ;
341339 dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW , (int64_t )(delayInSeconds * NSEC_PER_SEC ));
342340 dispatch_after (popTime, dispatch_get_main_queue (), ^(void ) {
343- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
344- [responseDict setValue: [NSNumber numberWithBool: false ] forKey: @" success" ];
345- [responseDict setValue: [NSNumber numberWithInteger: error.code] forKey: @" errorCode" ];
346- [responseDict setValue: error.domain forKey: @" error" ];
347-
348- resolve (responseDict);
349- return ;
341+ NSMutableDictionary *errorDict = [[NSMutableDictionary alloc ] init ];
342+ [errorDict setValue: [NSNumber numberWithInteger: error.code] forKey: @" errorCode" ];
343+ [errorDict setValue: error.domain forKey: @" errorMessage" ];
344+
345+ reject (@" error" , error.domain , error);
350346 });
351347 } else {
352-
353- if ([smallplugResponse isKindOfClass: [NSString class ]]) {
354- NSLog (@" %@ " , smallplugResponse);
355-
356- [responseDict setValue: [NSNumber numberWithBool: true ] forKey: @" success" ];
357- [responseDict setValue: smallplugResponse forKey: @" smallcaseAuthToken" ];
348+ if ([smallplugResponse isKindOfClass: [SmallPlugResult class ]]) {
349+ SmallPlugResult *result = (SmallPlugResult *)smallplugResponse;
350+
351+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
352+ [responseDict setValue: [NSNumber numberWithBool: true ] forKey: @" success" ];
353+
354+ if (result.smallcaseAuthToken ) {
355+ [responseDict setValue: result.smallcaseAuthToken forKey: @" smallcaseAuthToken" ];
356+ }
357+
358+ // Add userInfo inside data object if available
359+ if (result.userInfo ) {
360+ NSMutableDictionary *dataDict = [[NSMutableDictionary alloc ] init ];
361+ NSMutableDictionary *userInfoDict = [[NSMutableDictionary alloc ] init ];
362+
363+ if (result.userInfo .number ) {
364+ [userInfoDict setValue: result.userInfo.number forKey: @" number" ];
365+ }
366+ if (result.userInfo .countryCode ) {
367+ [userInfoDict setValue: result.userInfo.countryCode forKey: @" countryCode" ];
368+ }
369+
370+ [dataDict setValue: userInfoDict forKey: @" userInfo" ];
371+ [responseDict setValue: dataDict forKey: @" data" ];
372+ }
358373
359374 double delayInSeconds = 0.5 ;
360375 dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW , (int64_t )(delayInSeconds * NSEC_PER_SEC ));
361376 dispatch_after (popTime, dispatch_get_main_queue (), ^(void ) {
362-
363377 resolve (responseDict);
364- return ;
365-
366378 });
367379 }
368380 }
369-
370381 }];
371382 });
372383}
@@ -405,40 +416,51 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
405416
406417 [SCGateway.shared launchSmallPlugWithPresentingController: [[[UIApplication sharedApplication ] keyWindow ] rootViewController ] smallplugData: smallplugData smallplugUiConfig: smallplugUiConfig completion: ^(id smallplugResponse, NSError * error) {
407418
408- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
409-
410419 if (error != nil ) {
411420 NSLog (@" %@ " , error.domain );
412421 double delayInSeconds = 0.5 ;
413422 dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW , (int64_t )(delayInSeconds * NSEC_PER_SEC ));
414423 dispatch_after (popTime, dispatch_get_main_queue (), ^(void ) {
415- NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
416- [responseDict setValue: [NSNumber numberWithBool: false ] forKey: @" success" ];
417- [responseDict setValue: [NSNumber numberWithInteger: error.code] forKey: @" errorCode" ];
418- [responseDict setValue: error.domain forKey: @" error" ];
419-
420- resolve (responseDict);
421- return ;
424+ NSMutableDictionary *errorDict = [[NSMutableDictionary alloc ] init ];
425+ [errorDict setValue: [NSNumber numberWithInteger: error.code] forKey: @" errorCode" ];
426+ [errorDict setValue: error.domain forKey: @" errorMessage" ];
427+
428+ reject (@" error" , error.domain , error);
422429 });
423430 } else {
424-
425- if ([smallplugResponse isKindOfClass: [NSString class ]]) {
426- NSLog (@" %@ " , smallplugResponse);
427-
428- [responseDict setValue: [NSNumber numberWithBool: true ] forKey: @" success" ];
429- [responseDict setValue: smallplugResponse forKey: @" smallcaseAuthToken" ];
431+ if ([smallplugResponse isKindOfClass: [SmallPlugResult class ]]) {
432+ SmallPlugResult *result = (SmallPlugResult *)smallplugResponse;
433+
434+ NSMutableDictionary *responseDict = [[NSMutableDictionary alloc ] init ];
435+ [responseDict setValue: [NSNumber numberWithBool: true ] forKey: @" success" ];
436+
437+ if (result.smallcaseAuthToken ) {
438+ [responseDict setValue: result.smallcaseAuthToken forKey: @" smallcaseAuthToken" ];
439+ }
440+
441+ // Add userInfo inside data object if available
442+ if (result.userInfo ) {
443+ NSMutableDictionary *dataDict = [[NSMutableDictionary alloc ] init ];
444+ NSMutableDictionary *userInfoDict = [[NSMutableDictionary alloc ] init ];
445+
446+ if (result.userInfo .number ) {
447+ [userInfoDict setValue: result.userInfo.number forKey: @" number" ];
448+ }
449+ if (result.userInfo .countryCode ) {
450+ [userInfoDict setValue: result.userInfo.countryCode forKey: @" countryCode" ];
451+ }
452+
453+ [dataDict setValue: userInfoDict forKey: @" userInfo" ];
454+ [responseDict setValue: dataDict forKey: @" data" ];
455+ }
430456
431457 double delayInSeconds = 0.5 ;
432458 dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW , (int64_t )(delayInSeconds * NSEC_PER_SEC ));
433459 dispatch_after (popTime, dispatch_get_main_queue (), ^(void ) {
434-
435460 resolve (responseDict);
436- return ;
437-
438461 });
439462 }
440463 }
441-
442464 }];
443465 });
444466}
0 commit comments