@@ -90,6 +90,7 @@ import ShowPushNotificationTxDetails from './components/ShowPushNotificationTxDe
90
90
import { NanoContractDetailsScreen } from './screens/NanoContract/NanoContractDetailsScreen' ;
91
91
import { NanoContractTransactionScreen } from './screens/NanoContract/NanoContractTransactionScreen' ;
92
92
import { NanoContractRegisterScreen } from './screens/NanoContract/NanoContractRegisterScreen' ;
93
+ import { NanoContractRegisterQrCodeScreen } from './screens/NanoContractRegisterQrCodeScreen' ;
93
94
94
95
/**
95
96
* This Stack Navigator is exhibited when there is no wallet initialized on the local storage.
@@ -286,6 +287,72 @@ const RegisterTokenStack = ({ navigation }) => {
286
287
) ;
287
288
} ;
288
289
290
+ /**
291
+ * Stack of screens dedicated to the nano contract registration process
292
+ */
293
+ const RegisterNanoContractStack = ( { navigation } ) => {
294
+ const Stack = createStackNavigator ( ) ;
295
+ const dispatch = useDispatch ( ) ;
296
+ const isCameraAvailable = useSelector ( ( state ) => state . isCameraAvailable ) ;
297
+
298
+ /**
299
+ * Defines which screen will be the initial one, according to app camera permissions
300
+ * @param {null|boolean } cameraStatus
301
+ * @returns {string } Route name
302
+ */
303
+ const decideRouteByCameraAvailablity = ( cameraStatus ) => {
304
+ switch ( isCameraAvailable ) {
305
+ case true :
306
+ return 'NanoContractRegisterQrCodeScreen' ;
307
+ case false :
308
+ return 'NanoContractRegisterScreen' ;
309
+ default :
310
+ return 'RegisterCameraPermissionScreen' ;
311
+ }
312
+ } ;
313
+
314
+ // Initial screen set on component initial rendering
315
+ const [ initialRoute , setInitialRoute ] = useState (
316
+ decideRouteByCameraAvailablity ( isCameraAvailable )
317
+ ) ;
318
+
319
+ /*
320
+ * Request camera permission on initialization only if permission is not already set
321
+ */
322
+ useEffect ( ( ) => {
323
+ if ( isCameraAvailable === null ) {
324
+ dispatch ( requestCameraPermission ( ) ) ;
325
+ }
326
+ } , [ ] ) ;
327
+
328
+ // Listen to camera permission changes from user input and navigate to the relevant screen
329
+ useEffect ( ( ) => {
330
+ const newScreenName = decideRouteByCameraAvailablity ( isCameraAvailable ) ;
331
+
332
+ // Navigator screen already correct: no further action.
333
+ if ( initialRoute === newScreenName ) {
334
+ return ;
335
+ }
336
+
337
+ // Set initial route and navigate there according to new permission set
338
+ setInitialRoute ( newScreenName ) ;
339
+ navigation . replace ( newScreenName ) ;
340
+ } , [ isCameraAvailable ] ) ;
341
+
342
+ return (
343
+ < Stack . Navigator
344
+ initialRouteName = { initialRoute }
345
+ screenOptions = { {
346
+ headerShown : false ,
347
+ } }
348
+ >
349
+ < Stack . Screen name = 'RegisterCameraPermissionScreen' component = { CameraPermissionScreen } />
350
+ < Stack . Screen name = 'NanoContractRegisterQrCodeScreen' component = { NanoContractRegisterQrCodeScreen } />
351
+ < Stack . Screen name = 'NanoContractRegisterScreen' component = { NanoContractRegisterScreen } />
352
+ </ Stack . Navigator >
353
+ ) ;
354
+ } ;
355
+
289
356
const tabBarIconMap = {
290
357
Home : 'icDashboard' ,
291
358
Send : 'icSend' ,
@@ -397,6 +464,8 @@ const AppStack = () => {
397
464
/>
398
465
< Stack . Screen name = 'PaymentRequestDetail' component = { PaymentRequestDetail } />
399
466
< Stack . Screen name = 'RegisterToken' component = { RegisterTokenStack } />
467
+ < Stack . Screen name = 'RegisterNanoContract' component = { RegisterNanoContractStack } />
468
+ < Stack . Screen name = 'Register' component = { RegisterTokenStack } />
400
469
< Stack . Screen name = 'ChangeToken' component = { ChangeToken } />
401
470
< Stack . Screen name = { NetworkSettingsFlowNav } component = { NetworkSettingsFlowStack } />
402
471
< Stack . Screen
0 commit comments