Skip to content

Commit

Permalink
fix(#214): increase sharing timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
pmigueld committed Nov 23, 2022
1 parent 542ef24 commit e99347f
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 54 deletions.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"status": {
"sharing": {
"title": "Sharing...",
"hint": "Please wait for the receiving device to accept or reject the share.",
"timeoutHint": "It's taking longer than expected to share. There could be a problem with the connection."
},
"accepted": {
Expand Down
1 change: 1 addition & 0 deletions locales/fil.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
"status": {
"sharing": {
"title": "Pagbabahagi",
"hint": "Pakihintay na tanggapin o tanggihan ng tumatanggap na device ang pagbabahagi.",
"timeoutHint": "May katagalan ang pagbabahagi. Maaaring may problema sa koneksyon."
},
"accepted": {
Expand Down
20 changes: 12 additions & 8 deletions machines/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ export const requestMachine = model.createMachine(
},
initial: 'inProgress',
states: {
inProgress: {},
inProgress: {
after: {
SHARING_TIMEOUT: {
target: 'timeout',
},
},
},
timeout: {
on: {
CANCEL: {
Expand All @@ -221,11 +227,6 @@ export const requestMachine = model.createMachine(
},
},
},
after: {
CONNECTION_TIMEOUT: {
target: '.timeout',
},
},
},
reviewing: {
on: {
Expand Down Expand Up @@ -680,8 +681,11 @@ export const requestMachine = model.createMachine(

delays: {
CLEAR_DELAY: 250,
CONNECTION_TIMEOUT: () => {
return (Platform.OS === 'ios' ? 10 : 5) * 1000;
CONNECTION_TIMEOUT: (context) => {
return (context.sharingProtocol === 'ONLINE' ? 15 : 5) * 1000;
},
SHARING_TIMEOUT: (context) => {
return (context.sharingProtocol === 'ONLINE' ? 45 : 15) * 1000;
},
},
}
Expand Down
6 changes: 5 additions & 1 deletion machines/request.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface Typegen0 {
'xstate.after(CLEAR_DELAY)#clearingConnection': {
type: 'xstate.after(CLEAR_DELAY)#clearingConnection';
};
'xstate.after(SHARING_TIMEOUT)#request.waitingForVc.inProgress': {
type: 'xstate.after(SHARING_TIMEOUT)#request.waitingForVc.inProgress';
};
'xstate.init': { type: 'xstate.init' };
'xstate.stop': { type: 'xstate.stop' };
};
Expand Down Expand Up @@ -95,7 +98,8 @@ export interface Typegen0 {
};
'eventsCausingDelays': {
CLEAR_DELAY: '';
CONNECTION_TIMEOUT: 'EXCHANGE_DONE' | 'RECEIVE_DEVICE_INFO';
CONNECTION_TIMEOUT: 'RECEIVE_DEVICE_INFO';
SHARING_TIMEOUT: 'EXCHANGE_DONE';
};
'matchesStates':
| 'bluetoothDenied'
Expand Down
20 changes: 12 additions & 8 deletions machines/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,13 @@ export const scanMachine = model.createMachine(
},
initial: 'inProgress',
states: {
inProgress: {},
inProgress: {
after: {
SHARING_TIMEOUT: {
target: 'timeout',
},
},
},
timeout: {
on: {
CANCEL: {
Expand All @@ -305,11 +311,6 @@ export const scanMachine = model.createMachine(
},
},
},
after: {
CONNECTION_TIMEOUT: {
target: '.timeout',
},
},
},
accepted: {
entry: ['logShared'],
Expand Down Expand Up @@ -685,8 +686,11 @@ export const scanMachine = model.createMachine(

delays: {
CLEAR_DELAY: 250,
CONNECTION_TIMEOUT: () => {
return (Platform.OS === 'ios' ? 15 : 5) * 1000;
CONNECTION_TIMEOUT: (context) => {
return (context.sharingProtocol === 'ONLINE' ? 15 : 5) * 1000;
},
SHARING_TIMEOUT: (context) => {
return (context.sharingProtocol === 'ONLINE' ? 45 : 15) * 1000;
},
},
}
Expand Down
8 changes: 5 additions & 3 deletions machines/scan.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export interface Typegen0 {
'xstate.after(CLEAR_DELAY)#clearingConnection': {
type: 'xstate.after(CLEAR_DELAY)#clearingConnection';
};
'xstate.after(SHARING_TIMEOUT)#scan.reviewing.sendingVc.inProgress': {
type: 'xstate.after(SHARING_TIMEOUT)#scan.reviewing.sendingVc.inProgress';
};
'xstate.init': { type: 'xstate.init' };
'xstate.stop': { type: 'xstate.stop' };
};
Expand Down Expand Up @@ -114,11 +117,10 @@ export interface Typegen0 {
};
'eventsCausingDelays': {
CLEAR_DELAY: 'LOCATION_ENABLED';
CONNECTION_TIMEOUT:
CONNECTION_TIMEOUT: 'CONNECTED' | 'RECEIVE_DEVICE_INFO';
SHARING_TIMEOUT:
| 'ACCEPT_REQUEST'
| 'CONNECTED'
| 'FACE_VALID'
| 'RECEIVE_DEVICE_INFO'
| 'done.invoke.scan.reviewing.creatingVp:invocation[0]';
};
'matchesStates':
Expand Down
64 changes: 31 additions & 33 deletions screens/Request/RequestScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import React from 'react';
import { TFunction, useTranslation } from 'react-i18next';
import { Switch } from 'react-native-elements';
import { Platform } from 'react-native';
import QRCode from 'react-native-qrcode-svg';

import { Centered, Button, Row, Column, Text } from '../../components/ui';
import { Theme } from '../../components/ui/styleUtils';
import { useRequestScreen } from './RequestScreenController';
import { TFunction, useTranslation } from 'react-i18next';
import { Switch } from 'react-native-elements';
import { Platform } from 'react-native';

export const RequestScreen: React.FC = () => {
const { t } = useTranslation('RequestScreen');
const controller = useRequestScreen();
const props: RequestScreenProps = { t, controller };

return (
<Column
fill
padding="24"
backgroundColor={Theme.Colors.lightGreyBackgroundColor}>
{controller.isBluetoothDenied && (
<BluetoothPrompt t={t} controller={controller} />
)}
{controller.isBluetoothDenied && <BluetoothPrompt {...props} />}

{!controller.isCheckingBluetoothService &&
!controller.isBluetoothDenied ? (
<Column align="flex-end" fill>
{controller.isWaitingForConnection && (
<SharingCode t={t} controller={controller} />
)}
<StatusMessage t={t} controller={controller} />
{controller.isWaitingForConnection && <SharingQR {...props} />}
<StatusMessage {...props} />
</Column>
) : null}
</Column>
Expand All @@ -48,29 +46,7 @@ const BluetoothPrompt: React.FC<RequestScreenProps> = ({ t, controller }) => {
);
};

const StatusMessage: React.FC<RequestScreenProps> = ({ t, controller }) => {
return (
controller.statusMessage !== '' && (
<Column elevation={1} padding="16 24">
<Text>{controller.statusMessage}</Text>
{controller.statusHint !== '' && (
<Text size="small" color={Theme.Colors.textLabel}>
{controller.statusHint}
</Text>
)}
{controller.isStatusCancellable && (
<Button
margin={[8, 0, 0, 0]}
title={t('cancel', { ns: 'common' })}
onPress={controller.CANCEL}
/>
)}
</Column>
)
);
};

const SharingCode: React.FC<RequestScreenProps> = ({ t, controller }) => {
const SharingQR: React.FC<RequestScreenProps> = ({ t, controller }) => {
return (
<React.Fragment>
<Text align="center">
Expand Down Expand Up @@ -100,6 +76,28 @@ const SharingCode: React.FC<RequestScreenProps> = ({ t, controller }) => {
);
};

const StatusMessage: React.FC<RequestScreenProps> = ({ t, controller }) => {
return (
controller.statusMessage !== '' && (
<Column elevation={1} padding="16 24">
<Text>{controller.statusMessage}</Text>
{controller.statusHint !== '' && (
<Text size="small" color={Theme.Colors.textLabel}>
{controller.statusHint}
</Text>
)}
{controller.isStatusCancellable && (
<Button
margin={[8, 0, 0, 0]}
title={t('cancel', { ns: 'common' })}
onPress={controller.CANCEL}
/>
)}
</Column>
)
);
};

interface RequestScreenProps {
t: TFunction;
controller: ReturnType<typeof useRequestScreen>;
Expand Down
1 change: 1 addition & 0 deletions screens/Scan/SendVcScreen.strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"status": {
"sharing": {
"title": "Sharing...",
"hint": "Please wait for the receiving device to accept or reject the share.",
"timeoutHint": "It's taking longer than expected to share. There could be a problem with the connection."
},
"accepted": {
Expand Down
4 changes: 3 additions & 1 deletion screens/Scan/SendVcScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const SendVcScreen: React.FC = () => {
isVisible={controller.isSendingVc}
title={t('status.sharing.title')}
hint={
controller.isSendingVcTimeout ? t('status.sharing.timeoutHint') : null
controller.isSendingVcTimeout
? t('status.sharing.timeoutHint')
: t('status.sharing.hint')
}
onCancel={controller.isSendingVcTimeout ? controller.CANCEL : null}
progress
Expand Down

0 comments on commit e99347f

Please sign in to comment.