Page MenuHomePhabricator

D14153.id46553.diff
No OneTemporary

D14153.id46553.diff

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<?string>(null);
const secondaryDeviceType = React.useRef<?IdentityDeviceType>(null);
const [connectingInProgress, setConnectingInProgress] = React.useState(false);
+ const timeout = React.useRef<?TimeoutID>(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,
]);

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 1:23 AM (15 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693307
Default Alt Text
D14153.id46553.diff (2 KB)

Event Timeline