diff --git a/native/account/qr-auth/qr-auth-context-provider.js b/native/account/qr-auth/qr-auth-context-provider.js --- a/native/account/qr-auth/qr-auth-context-provider.js +++ b/native/account/qr-auth/qr-auth-context-provider.js @@ -29,6 +29,10 @@ import { QRAuthContext } from './qr-auth-context.js'; import { commCoreModule } from '../../native-modules.js'; +import { + SecondaryDeviceConnectedRouteName, + SecondaryDeviceNotRespondingRouteName, +} from '../../navigation/route-names.js'; import { useSelector } from '../../redux/redux-utils.js'; import Alert from '../../utils/alert.js'; import { @@ -36,6 +40,8 @@ parseTunnelbrokerQRAuthMessage, } from '../../utils/qr-code-utils.js'; +const secondaryDeviceTimeout = 30 * 1000; + type Props = { +children: React.Node, }; @@ -44,10 +50,11 @@ const secondaryDeviceID = React.useRef(null); const secondaryDeviceType = React.useRef(null); const [connectingInProgress, setConnectingInProgress] = React.useState(false); + const timeout = React.useRef(null); const ownPeerDevices = useSelector(getOwnPeerDevices); const keyserverDeviceID = getKeyserverDeviceID(ownPeerDevices); - const { goBack } = useNavigation(); + const { goBack, navigate } = useNavigation(); const runDeviceListUpdate = useDeviceListUpdate(); const { addListener, removeListener, sendMessageToDevice } = useTunnelbroker(); @@ -55,6 +62,14 @@ const identityContext = React.useContext(IdentityClientContext); invariant(identityContext, 'identity context not set'); + React.useEffect(() => { + return () => { + if (timeout.current) { + clearTimeout(timeout.current); + } + }; + }, []); + const tunnelbrokerMessageListener = React.useCallback( async (message: TunnelbrokerToDeviceMessage) => { if (!connectingInProgress) { @@ -95,12 +110,11 @@ } setConnectingInProgress(false); - - Alert.alert('Device added', 'Device registered successfully', [ - { text: 'OK', onPress: goBack }, - ]); + clearTimeout(timeout.current); + timeout.current = null; + navigate(SecondaryDeviceConnectedRouteName); }, - [goBack, connectingInProgress], + [connectingInProgress, navigate], ); React.useEffect(() => { @@ -141,6 +155,10 @@ deviceID: targetDeviceID, payload: JSON.stringify(message), }); + timeout.current = setTimeout(() => { + setConnectingInProgress(false); + navigate(SecondaryDeviceNotRespondingRouteName); + }, secondaryDeviceTimeout); }; const handleReplaceDevice = async () => { @@ -206,6 +224,7 @@ goBack, identityContext, keyserverDeviceID, + navigate, runDeviceListUpdate, sendMessageToDevice, ]);