Skip to content

Commit

Permalink
fixup! feat(mobile): better connect popup flow
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Sep 24, 2024
1 parent 4fc2f1b commit afb76de
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions suite-native/module-authorize-device/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@suite-native/forms": "workspace:*",
"@suite-native/intl": "workspace:*",
"@suite-native/link": "workspace:*",
"@suite-native/module-connect-popup": "workspace:*",
"@suite-native/navigation": "workspace:*",
"@suite-native/theme": "workspace:*",
"@suite-native/toasts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
RootStackRoutes,
StackToTabCompositeProps,
} from '@suite-native/navigation';
import { useIsConnectPopupOpened } from '@suite-native/module-connect-popup';

const LOADING_TIMEOUT = 2500;

Expand All @@ -37,6 +38,7 @@ export const useOnDeviceReadyNavigation = () => {
selectDeviceEnabledDiscoveryNetworkSymbols,
);
const isCoinEnablingInitFinished = useSelector(selectIsCoinEnablingInitFinished);
const isConnectPopupOpened = useIsConnectPopupOpened();

// The connecting screen should be visible for at least 2.5 seconds before redirecting to HomeScreen.
useEffect(() => {
Expand All @@ -56,7 +58,7 @@ export const useOnDeviceReadyNavigation = () => {
(isDeviceReadyToUseAndAuthorized && isTimeoutFinished) ||
(deviceEnabledDiscoveryNetworkSymbols.length === 0 && isCoinEnablingInitFinished)
) {
if (navigation.canGoBack()) {
if (navigation.canGoBack() && isConnectPopupOpened) {
// NOTE: we don't want to go back to the home screen if Connect Popup is opened
navigation.goBack();

Expand All @@ -76,5 +78,6 @@ export const useOnDeviceReadyNavigation = () => {
navigation,
deviceEnabledDiscoveryNetworkSymbols,
isCoinEnablingInitFinished,
isConnectPopupOpened,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { IconButton, Text, VStack } from '@suite-native/atoms';
import TrezorConnect from '@trezor/connect';
import { useAuthorizationGoBack } from '@suite-native/device-authorization';
import { Translation, useTranslate } from '@suite-native/intl';
import { useIsConnectPopupOpened } from '@suite-native/module-connect-popup';

import { PassphraseForm } from '../../components/passphrase/PassphraseForm';

export const PassphraseFeatureUnlockFormScreen = () => {
const { handleGoBack } = useAuthorizationGoBack();
const isConnectPopupOpened = useIsConnectPopupOpened();

const { translate } = useTranslate();

Expand Down Expand Up @@ -37,7 +39,7 @@ export const PassphraseFeatureUnlockFormScreen = () => {
</Text>
<PassphraseForm
inputLabel={translate('modulePassphrase.form.createWalletInputLabel')}
noPassphraseEnabled
noPassphraseEnabled={isConnectPopupOpened}
/>
</VStack>
</Screen>
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-authorize-device/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{ "path": "../forms" },
{ "path": "../intl" },
{ "path": "../link" },
{ "path": "../module-connect-popup" },
{ "path": "../navigation" },
{ "path": "../theme" },
{ "path": "../toasts" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect, useState } from 'react';

import { useNavigation } from '@react-navigation/native';

export const useIsConnectPopupOpened = () => {
const navigation = useNavigation();
const rootNavigation = navigation.getParent() ?? navigation;

const [rootNavState, setRootNavState] = useState(() => rootNavigation.getState());

useEffect(() => {
const unsubscribe = rootNavigation.addListener('state', e => {
setRootNavState(e.data.state);
});

return unsubscribe;
}, [rootNavigation]);

const isPopupInStack = rootNavState?.routes.find(route => route.name === 'ConnectPopup');

return !!isPopupInStack;
};
1 change: 1 addition & 0 deletions suite-native/module-connect-popup/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './screens/ConnectPopupScreen';
export * from './hooks/useConnectPopupNavigation';
export * from './hooks/useIsConnectPopupOpened';
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10203,6 +10203,7 @@ __metadata:
"@suite-native/forms": "workspace:*"
"@suite-native/intl": "workspace:*"
"@suite-native/link": "workspace:*"
"@suite-native/module-connect-popup": "workspace:*"
"@suite-native/navigation": "workspace:*"
"@suite-native/theme": "workspace:*"
"@suite-native/toasts": "workspace:*"
Expand Down

0 comments on commit afb76de

Please sign in to comment.