dojah-kyc-sdk-react-expo 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +1,91 @@
1
1
  import ExpoModulesCore
2
2
  import DojahWidget
3
3
 
4
+ class DojahNavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
5
+ var onDidShow: (UIViewController) -> Void = { _ in }
6
+ func navigationController(_ navigationController: UINavigationController,
7
+ didShow viewController: UIViewController,
8
+ animated: Bool) {
9
+ print("Did show: \(viewController)")
10
+ onDidShow(viewController)
11
+ }
12
+
13
+ func navigationController(_ navigationController: UINavigationController,
14
+ willShow viewController: UIViewController,
15
+ animated: Bool) {
16
+ print("Will show: \(viewController)")
17
+ }
18
+
19
+ func setOnDidShow(_ onDidShow: @escaping (UIViewController) -> Void) {
20
+ self.onDidShow = onDidShow
21
+ }
22
+ }
23
+
4
24
  public class DojahKycSdkReactExpoModule: Module {
5
- // Each module class must implement the definition function. The definition consists of components
6
- // that describes the module's functionality and behavior.
7
- // See https://docs.expo.dev/modules/module-api for more details about available components.
25
+
26
+ var mPromise:Promise? = nil
27
+
28
+ let navDelegate = DojahNavigationControllerDelegate()
29
+
30
+ let navCtrl = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController
31
+
32
+ var prevController:UIViewController? = nil
33
+
34
+ required public init(appContext: AppContext) {
35
+ super.init(appContext: appContext)
36
+ navDelegate.setOnDidShow { vc in
37
+ print("onDidShow: \(vc)")
38
+ //return result from DojahWidget once verification
39
+ //is done,failed or cancel
40
+ if(!String(describing:vc).contains("DojahWidget")){
41
+ let vStatus = DojahWidgetSDK.getVerificationResultStatus()
42
+ let status = if(vStatus.isEmpty){ "closed"} else {vStatus}
43
+ self.mPromise?.resolve(status)
44
+ self.prevController = nil
45
+ }else if(String(describing:vc).contains("DojahWidget.DJDisclaimer")
46
+ && self.prevController != nil){
47
+ self.navCtrl?.popToRootViewController(animated: false)
48
+ }else if(!String(describing:vc).contains("DojahWidget.SDKInitViewController")){
49
+ self.prevController = vc
50
+ }
51
+ }
52
+
53
+ if navCtrl != nil {
54
+ navCtrl!.delegate = navDelegate
55
+ }
56
+ }
57
+
8
58
  public func definition() -> ModuleDefinition {
9
- // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
10
- // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
11
- // The module will be accessible from `requireNativeModule('DojahKycSdk')` in JavaScript.
59
+
12
60
  Name("DojahKycSdk")
13
61
 
14
- // Defines event names that the module can send to JavaScript.
15
62
  Events("onChange")
16
63
 
17
- // Defines a JavaScript function that always returns a Promise and whose native code
18
- // is by default dispatched on the different thread than the JavaScript runtime runs on.
19
- AsyncFunction("launch") { (widgetId: String, referenceId: String?, email: String?, extraData: ExtraDataRecord?,promise:Promise) in
20
-
21
- guard let rootViewController = UIApplication.shared.keyWindow?.rootViewController else {
22
- print("no root ctrl")
23
- return
24
- }
25
-
26
- print("root ctrl: $\(String(describing: rootViewController))")
64
+ AsyncFunction("launch") { (widgetId: String, referenceId: String?, email: String?, extraData: ExtraDataRecord?,promise:Promise) in
65
+ mPromise = promise
27
66
 
28
- let navController = rootViewController as? UINavigationController
67
+ let navController = navCtrl
29
68
 
30
69
  print("nav ctrl: $\(String(describing: navController))")
31
-
70
+
71
+
32
72
  if(navController == nil){
73
+ self.mPromise?.reject("002","failed to initialize, can't find navController")
33
74
  return
34
75
  }
35
-
36
- DispatchQueue.main.async {
37
- DojahWidgetSDK.initialize(widgetID: widgetId,referenceID: referenceId,emailAddress: email, navController: navController!)
38
- }
76
+
77
+ DispatchQueue.main.async {
78
+ do{
79
+ DojahWidgetSDK.initialize(
80
+ widgetID: widgetId,
81
+ referenceID: referenceId,
82
+ emailAddress: email,
83
+ extraUserData: extraData?.toExtraUserData(),
84
+ navController: navController!)
85
+ }catch{
86
+ self.mPromise?.reject("001","failed to initialize")
87
+ }
88
+ }
39
89
  }
40
90
 
41
91
  // Enables the module to be used as a native view. Definition components that are accepted as part of the
@@ -77,17 +127,17 @@ struct ExtraDataRecord : Record {
77
127
  @Field
78
128
  var metadata: [String:Any]? = nil
79
129
 
80
- // func toExtraUserData()-> ExtraUserData {
81
- // return ExtraUserData(
82
- // userData = userData?.toUserData(),
83
- // govData = govData?.toGovData(),
84
- // govId = govId?.toGovId(),
85
- // location = location?.toLocation(),
86
- // businessData = businessData?.toBusinessData(),
87
- // address = address,
88
- // metadata = metadata
89
- // )
90
- // }
130
+ func toExtraUserData()-> ExtraUserData {
131
+ return ExtraUserData(
132
+ userData: userData?.toUserData(),
133
+ govData: govData?.toGovData(),
134
+ govId: govId?.toGovId(),
135
+ location: location?.toLocation(),
136
+ businessData: businessData?.toBusinessData(),
137
+ address: address,
138
+ metadata: metadata
139
+ )
140
+ }
91
141
 
92
142
  }
93
143
 
@@ -105,14 +155,14 @@ struct UserRecord : Record {
105
155
  @Field
106
156
  var email: String? = nil
107
157
 
108
- // func toUserData(): UserData {
109
- // return UserData(
110
- // firstName = firstName,
111
- // lastName = lastName,
112
- // dob = dob,
113
- // email = email
114
- // )
115
- // }
158
+ func toUserData()-> UserBioData {
159
+ return UserBioData(
160
+ firstName: firstName,
161
+ lastName: lastName,
162
+ dob: dob,
163
+ email: email
164
+ )
165
+ }
116
166
  }
117
167
 
118
168
  struct GovDataRecord : Record {
@@ -129,14 +179,14 @@ struct GovDataRecord : Record {
129
179
  @Field
130
180
  var vnin: String? = nil
131
181
 
132
- // func toGovData(): GovData {
133
- // return GovData(
134
- // bvn = bvn,
135
- // dl = dl,
136
- // nin = nin,
137
- // vnin = vnin
138
- // )
139
- // }
182
+ func toGovData()-> ExtraGovData {
183
+ return ExtraGovData(
184
+ bvn: bvn,
185
+ dl: dl,
186
+ nin: nin,
187
+ vnin: vnin
188
+ )
189
+ }
140
190
  }
141
191
 
142
192
  struct GovIdRecord : Record {
@@ -158,16 +208,16 @@ struct GovIdRecord : Record {
158
208
  @Field
159
209
  var others: String? = nil
160
210
 
161
- // func toGovId(): GovId {
162
- // return GovId(
163
- // national = national,
164
- // passport = passport,
165
- // dl = dl,
166
- // voter = voter,
167
- // nin = nin,
168
- // others = others
169
- // )
170
- // }
211
+ func toGovId()-> ExtraGovIdData {
212
+ return ExtraGovIdData(
213
+ national: national,
214
+ passport: passport,
215
+ dl: dl,
216
+ voter: voter,
217
+ nin: nin,
218
+ others: others
219
+ )
220
+ }
171
221
  }
172
222
 
173
223
  struct LocationRecord : Record {
@@ -177,22 +227,22 @@ struct LocationRecord : Record {
177
227
  @Field
178
228
  var longitude: String? = nil
179
229
 
180
- // func toLocation(): Location {
181
- // return Location(
182
- // latitude = latitude,
183
- // longitude = longitude
184
- // )
185
- // }
230
+ func toLocation()-> ExtraLocationData {
231
+ return ExtraLocationData(
232
+ longitude: longitude,
233
+ latitude: latitude
234
+ )
235
+ }
186
236
  }
187
237
 
188
238
  struct BusinessDataRecord : Record {
189
239
  @Field
190
240
  var cac: String? = nil
191
241
 
192
- // func toBusinessData(): BusinessData {
193
- // return BusinessData(
194
- // cac = cac
195
- // )
196
- // }
242
+ func toBusinessData()-> ExtraBusinessData {
243
+ return ExtraBusinessData(
244
+ cac: cac
245
+ )
246
+ }
197
247
  }
198
248
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dojah-kyc-sdk-react-expo",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Dojah Kyc",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",