chore: first lint pass

This commit is contained in:
pmigueld
2022-03-29 22:42:19 +08:00
parent f9206f2e1c
commit 480332073c
20 changed files with 216 additions and 174 deletions

View File

@@ -7,7 +7,7 @@ import { GlobalContext } from './shared/GlobalContext';
import { useSelector } from '@xstate/react';
import { selectIsReady } from './machines/app';
const AppInitialization: React.FC = (props) => {
const AppInitialization: React.FC = () => {
const { appService } = useContext(GlobalContext);
const hasFontsLoaded = useFont();
const isReady = useSelector(appService, selectIsReady);

View File

@@ -7,7 +7,7 @@ import { Colors } from './ui/styleUtils';
export const EditableListItem: React.FC<EditableListItemProps> = (props) => {
const [isEditing, setIsEditing] = useState(false);
const [newValue, setNewValue] = useState(props.value);
return (
<ListItem bottomDivider onPress={() => setIsEditing(true)}>
<ListItem.Content>
@@ -24,12 +24,7 @@ export const EditableListItem: React.FC<EditableListItemProps> = (props) => {
<Text>Edit {props.label}</Text>
<Input autoFocus value={newValue} onChangeText={setNewValue} />
<Row>
<Button
fill
type="clear"
title="Cancel"
onPress={dismiss}
/>
<Button fill type="clear" title="Cancel" onPress={dismiss} />
<Button fill title="Save" onPress={edit} />
</Row>
</Column>

View File

@@ -4,7 +4,6 @@ import { Icon } from 'react-native-elements';
import { Colors } from './ui/styleUtils';
export function LanguageSelector() {
return (
<View>
<Icon name="language" color={Colors.Orange} />

View File

@@ -16,8 +16,7 @@ export const MessageOverlay: React.FC<MessageOverlayProps> = (props) => {
<Overlay
isVisible={props.isVisible}
overlayStyle={styles.overlay}
onBackdropPress={props.onBackdropPress}
>
onBackdropPress={props.onBackdropPress}>
<Column padding="24" width={Dimensions.get('screen').width * 0.8}>
{props.title && (
<Text weight="semibold" margin="0 0 12 0">

View File

@@ -43,7 +43,6 @@ export const TextEditOverlay: React.FC<EditOverlayProps> = (props) => {
setValue(props.value);
props.onDismiss();
}
};
interface EditOverlayProps {

View File

@@ -56,13 +56,16 @@ export const VcItem: React.FC<VcItemProps> = (props) => {
const verifiableCredential = useSelector(service, selectVerifiableCredential);
const generatedOn = useSelector(service, selectGeneratedOn);
const selectableOrCheck = props.selectable ? <CheckBox
const selectableOrCheck = props.selectable ? (
<CheckBox
checked={props.selected}
checkedIcon={<Icon name="radio-button-checked" />}
uncheckedIcon={<Icon name="radio-button-unchecked" />}
onPress={() => props.onPress(service)}
/> : <Icon name="chevron-right" />;
/>
) : (
<Icon name="chevron-right" />
);
return (
<Pressable
@@ -97,7 +100,11 @@ export const VcItem: React.FC<VcItemProps> = (props) => {
generatedOn}
</Text>
</Column>
{ verifiableCredential ? selectableOrCheck : (<RotatingIcon name="sync" color={Colors.Grey5} />) }
{verifiableCredential ? (
selectableOrCheck
) : (
<RotatingIcon name="sync" color={Colors.Grey5} />
)}
</Row>
</Pressable>
);

View File

@@ -11,89 +11,94 @@ const model = createModel(
},
{
events: {
STORE_RESPONSE: (response: any) => ({ response }),
STORE_RESPONSE: (response: unknown) => ({ response }),
LOG_ACTIVITY: (log: ActivityLog) => ({ log }),
REFRESH: () => ({}),
},
}
);
type ActivityLogEvents = EventFrom<typeof model>;
export const ActivityLogEvents = model.events;
type StoreResponseEvent = EventFrom<typeof model, 'STORE_RESPONSE'>;
type LogActivityEvent = EventFrom<typeof model, 'LOG_ACTIVITY'>;
export const activityLogMachine = model.createMachine(
{
id: 'activityLog',
context: model.initialContext,
initial: 'init',
states: {
init: {
entry: ['loadActivities'],
on: {
STORE_RESPONSE: {
target: 'ready',
actions: ['setActivities', sendParent('READY')],
export const activityLogMachine =
/** @xstate-layout N4IgpgJg5mDOIC5QEMDGAXAlgN0+gngDID2UAdJgHZ4DEAygCoDyASgKID67dACkwHJ02iUAAdisPJmKURIAB6IAHAFYyAdgBM6pQE4AzAAZdK9SsOGAbABoQ+RNt1klezYYCM+pQBZ9m3wC+AbZoWLgEJOQATmDIEPgUEAA2YDSETADiHACCAMIMAJIAagUMAJpy4pJYMnKKCJrulmSaPobe6t4GKpY63rb2CEqWmmT67pq67kqGquNKQSEYOHhEpGQxcQmYyansAGLcABKVElK1SAoOfmS6htp6LpbT7tMDiJbeSs7u5q8W6l0ll0ixAoRWEXWm3iZCSpCgVCg9GY7C4bF4AiEp2q0lkl3qAFp3N4Wt5DGZxuovK0Jip3kNvKMppNNH5vL4WaDweE1tFYjCYgAzGKwAAWiORrE43D4gmElyq5zxoEJxNJ5P0X30+gMnS89JGTm8v3aKiBBnu6iCwRAlGIEDgcm5q0iFGo6GxSrqHxJrxUOp67gMQcM+npxNGnUsPleVLuKhUCxtzshfK2iRSnpqyquCFpGhePXajN0QJsdkQnTUujcJnGHn0Ok0XOWPNd0IScKgCMoUCzuO9Q30ZF8VgToZrVK09JM6ha+jNli8ieM5JbYRdUP5CSFIvFvf7FxVlacul8xIjja8Snc9K6w48wJGsw1CfXEN5G23h5zhK86opdwqSUGlNDpCsEEZQwyEfEwejA4wdW8d821IH9BwJEYAP9IDqRvMCDScKMlE1dRpk0T5DBUa0AiAA */
model.createMachine(
{
tsTypes: {} as import('./activityLog.typegen').Typegen0,
schema: {
context: model.initialContext,
events: {} as ActivityLogEvents,
},
id: 'activityLog',
initial: 'init',
states: {
init: {
entry: 'loadActivities',
on: {
STORE_RESPONSE: {
actions: ['setActivities', sendParent('READY')],
target: 'ready',
},
},
},
},
ready: {
initial: 'idle',
states: {
idle: {
on: {
LOG_ACTIVITY: 'logging',
REFRESH: 'refreshing',
},
},
logging: {
entry: ['storeActivity'],
on: {
STORE_RESPONSE: {
target: 'idle',
actions: ['prependActivity'],
ready: {
initial: 'idle',
states: {
idle: {
on: {
LOG_ACTIVITY: {
target: 'logging',
},
REFRESH: {
target: 'refreshing',
},
},
},
},
refreshing: {
entry: ['loadActivities'],
on: {
STORE_RESPONSE: {
target: 'idle',
actions: ['setActivities'],
logging: {
entry: 'storeActivity',
on: {
STORE_RESPONSE: {
actions: 'prependActivity',
target: 'idle',
},
},
},
refreshing: {
entry: 'loadActivities',
on: {
STORE_RESPONSE: {
actions: 'setActivities',
target: 'idle',
},
},
},
},
},
},
},
},
{
actions: {
loadActivities: send(StoreEvents.GET(ACTIVITY_LOG_STORE_KEY), {
to: (context) => context.serviceRefs.store,
}),
{
actions: {
loadActivities: send(StoreEvents.GET(ACTIVITY_LOG_STORE_KEY), {
to: (context) => context.serviceRefs.store,
}),
setActivities: model.assign({
activities: (_, event: StoreResponseEvent) => event.response || [],
}),
setActivities: model.assign({
activities: (_, event) => (event.response || []) as ActivityLog[],
}),
storeActivity: send(
(_, event: LogActivityEvent) =>
StoreEvents.PREPEND(ACTIVITY_LOG_STORE_KEY, event.log),
{ to: (context) => context.serviceRefs.store }
),
storeActivity: send(
(_, event) => StoreEvents.PREPEND(ACTIVITY_LOG_STORE_KEY, event.log),
{ to: (context) => context.serviceRefs.store }
),
prependActivity: model.assign({
activities: (context, event: StoreResponseEvent) => [
event.response,
...context.activities,
],
}),
},
}
);
prependActivity: model.assign({
activities: (context, event) =>
[event.response, ...context.activities] as ActivityLog[],
}),
},
}
);
export function createActivityLogMachine(serviceRefs: AppServices) {
return activityLogMachine.withContext({

View File

@@ -0,0 +1,32 @@
// This file was automatically generated. Edits will be overwritten
export interface Typegen0 {
'@@xstate/typegen': true;
'eventsCausingActions': {
setActivities: 'STORE_RESPONSE';
prependActivity: 'STORE_RESPONSE';
loadActivities: 'REFRESH';
storeActivity: 'LOG_ACTIVITY';
};
'internalEvents': {
'xstate.init': { type: 'xstate.init' };
};
'invokeSrcNameMap': {};
'missingImplementations': {
actions: never;
services: never;
guards: never;
delays: never;
};
'eventsCausingServices': {};
'eventsCausingGuards': {};
'eventsCausingDelays': {};
'matchesStates':
| 'init'
| 'ready'
| 'ready.idle'
| 'ready.logging'
| 'ready.refreshing'
| { ready?: 'idle' | 'logging' | 'refreshing' };
'tags': never;
}

View File

@@ -216,13 +216,13 @@ export const appMachine = model.createMachine(
checkFocusState: () => (callback) => {
const changeHandler = (newState: AppStateStatus) => {
switch (newState) {
case 'background':
case 'inactive':
callback({ type: 'INACTIVE' });
break;
case 'active':
callback({ type: 'ACTIVE' });
break;
case 'background':
case 'inactive':
callback({ type: 'INACTIVE' });
break;
case 'active':
callback({ type: 'ACTIVE' });
break;
}
};

View File

@@ -100,14 +100,14 @@ export const smartShareMachine = model.createMachine(
onReceive((event: EventFrom<typeof model>) => {
switch (event.type) {
case 'SEND':
SmartShare.send(event.message.toString(), () => {
callback(model.events.SENT());
});
break;
case 'DESTROY':
SmartShare.destroyConnection();
break;
case 'SEND':
SmartShare.send(event.message.toString(), () => {
callback(model.events.SENT());
});
break;
case 'DESTROY':
SmartShare.destroyConnection();
break;
}
});

View File

@@ -141,44 +141,44 @@ export const storeMachine = model.createMachine(
try {
let response: any;
switch (event.type) {
case 'GET': {
response = await getItem(
event.key,
null,
context.encryptionKey
);
break;
}
case 'SET': {
await setItem(event.key, event.value, context.encryptionKey);
response = event.value;
break;
}
case 'APPEND': {
await appendItem(event.key, event.value, context.encryptionKey);
response = event.value;
break;
}
case 'PREPEND': {
await prependItem(
event.key,
event.value,
context.encryptionKey
);
case 'GET': {
response = await getItem(
event.key,
null,
context.encryptionKey
);
break;
}
case 'SET': {
await setItem(event.key, event.value, context.encryptionKey);
response = event.value;
break;
}
case 'APPEND': {
await appendItem(event.key, event.value, context.encryptionKey);
response = event.value;
break;
}
case 'PREPEND': {
await prependItem(
event.key,
event.value,
context.encryptionKey
);
response = event.value;
break;
}
case 'REMOVE': {
await removeItem(event.key);
break;
}
case 'CLEAR': {
await clear();
break;
}
default:
return;
response = event.value;
break;
}
case 'REMOVE': {
await removeItem(event.key);
break;
}
case 'CLEAR': {
await clear();
break;
}
default:
return;
}
callback(model.events.STORE_RESPONSE(response, event.requester));
} catch (e) {

View File

@@ -1,6 +1,9 @@
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { NativeStackNavigationOptions, createNativeStackNavigator } from '@react-navigation/native-stack';
import {
NativeStackNavigationOptions,
createNativeStackNavigator,
} from '@react-navigation/native-stack';
import { LanguageSelector } from '../components/LanguageSelector';
import { authRoutes, baseRoutes } from '../routes';
import { useAppLayout } from './AppLayoutController';

View File

@@ -10,29 +10,32 @@ import { usePasscodeScreen } from './PasscodeScreenController';
export const PasscodeScreen: React.FC<PasscodeRouteProps> = (props) => {
const controller = usePasscodeScreen(props);
const passcodeSetup = controller.passcode === '' ? (
<React.Fragment>
<Text align="center">
Set a passcode to secure{'\n'}your application
</Text>
<PinInput length={MAX_PIN} onDone={controller.setPasscode} />
</React.Fragment>
) : (
<React.Fragment>
<Text align="center">Confirm your passcode</Text>
<PasscodeVerify
onSuccess={controller.SETUP_PASSCODE}
onError={controller.setError}
passcode={controller.passcode}
/>
</React.Fragment>
);
const passcodeSetup =
controller.passcode === '' ? (
<React.Fragment>
<Text align="center">
Set a passcode to secure{'\n'}your application
</Text>
<PinInput length={MAX_PIN} onDone={controller.setPasscode} />
</React.Fragment>
) : (
<React.Fragment>
<Text align="center">Confirm your passcode</Text>
<PasscodeVerify
onSuccess={controller.SETUP_PASSCODE}
onError={controller.setError}
passcode={controller.passcode}
/>
</React.Fragment>
);
return (
<Column fill padding="32" backgroundColor={Colors.White}>
<Icon name="lock" color={Colors.Orange} size={60} />
{props.route.params.setup ? (
<Column fill align="space-between" width="100%">{ passcodeSetup }</Column>
<Column fill align="space-between" width="100%">
{passcodeSetup}
</Column>
) : (
<Column fill align="space-between" width="100%">
<Text align="center">Enter your passcode</Text>

View File

@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Dimensions, Image, StyleSheet, View } from 'react-native';
import { Divider, Icon, ListItem, Overlay } from 'react-native-elements';
import Markdown from 'react-native-simple-markdown'
import Markdown from 'react-native-simple-markdown';
import { Button, Text, Row } from '../../components/ui';
import { Colors } from '../../components/ui/styleUtils';
import creditsContent from '../../Credits.md';
@@ -11,7 +11,7 @@ export const Credits: React.FC<CreditsProps> = (props) => {
const images = {
'docs/images/newlogic_logo.png' : require('../../docs/images/newlogic_logo.png'),
'docs/images/id_pass_logo.png' : require('../../docs/images/id_pass_logo.png'),
}
};
const styles = StyleSheet.create({
buttonContainer: {
position: 'absolute',
@@ -35,7 +35,7 @@ export const Credits: React.FC<CreditsProps> = (props) => {
maxWidth: 150,
margin: 0
}
}
};
const rules = {
image: {
@@ -49,7 +49,7 @@ export const Credits: React.FC<CreditsProps> = (props) => {
</View>
),
}
}
};
return (
<ListItem bottomDivider onPress={() => setIsViewing(true)}>

View File

@@ -30,12 +30,12 @@ export const RequestScreen: React.FC<MainRouteProps> = (props) => {
<Centered fill>
{controller.isWaitingForConnection &&
controller.connectionParams !== '' ? (
<QRCode
size={200}
value={controller.connectionParams}
backgroundColor={Colors.LightGrey}
/>
) : null}
<QRCode
size={200}
value={controller.connectionParams}
backgroundColor={Colors.LightGrey}
/>
) : null}
</Centered>
{controller.statusMessage !== '' && (

View File

@@ -17,16 +17,16 @@ export const ScanScreen: React.FC<MainRouteProps> = (props) => {
{controller.isLocationDisabled ||
controller.isLocationDenied ||
controller.isFlightMode ? (
<Column fill align="space-between">
<Text align="center" margin="16 0" color={Colors.Red}>
{controller.locationError.message}
</Text>
<Button
title={controller.locationError.button}
onPress={controller.ON_REQUEST}
/>
</Column>
) : null}
<Column fill align="space-between">
<Text align="center" margin="16 0" color={Colors.Red}>
{controller.locationError.message}
</Text>
<Button
title={controller.locationError.button}
onPress={controller.ON_REQUEST}
/>
</Column>
) : null}
{!controller.isEmpty ? (
controller.isScanning && (

View File

@@ -32,7 +32,7 @@ export function useScanScreen({ navigation }: MainRouteProps) {
if(isFlightMode) {
locationError.message =
'Flight mode must be disabled for the scanning functionality';
locationError.button = 'Disable flight mode';
locationError.button = 'Disable flight mode';
} else {
if (isLocationDisabled) {
locationError.message =
@@ -85,7 +85,7 @@ export function useScanScreen({ navigation }: MainRouteProps) {
SCAN: (qrCode: string) => scanService.send(ScanEvents.SCAN(qrCode)),
DISMISS_INVALID: () => {
if(isInvalid) {
scanService.send(ScanEvents.DISMISS())
scanService.send(ScanEvents.DISMISS());
}
}
};

View File

@@ -30,7 +30,7 @@ export const SelectVcOverlay: React.FC<SelectVcOverlayProps> = (props) => {
Share {controller.vcLabel.singular}
</Text>
<Text margin="0 0 16 0">
Choose the {controller.vcLabel.singular} you'd like to share with{' '}
Choose the {controller.vcLabel.singular} you&apos;d like to share with{' '}
<Text weight="semibold">{props.receiverName}</Text>
</Text>
<Column margin="0 0 32 0" scroll>

View File

@@ -40,7 +40,7 @@ export const SendVcModal: React.FC<SendVcModalProps> = (props) => {
<Button type="clear" title="Reject" onPress={controller.CANCEL} />
</Column>
</Column>
<SelectVcOverlay
isVisible={controller.isSelectingVc}
receiverName={controller.receiverInfo.deviceName}

View File

@@ -9,7 +9,7 @@ export const VcTabEvents = {
};
export const StoreEvents = {
STORE_RESPONSE: (response: any) => ({ response }),
STORE_RESPONSE: (response: unknown) => ({ response }),
STORE_ERROR: (error: Error) => ({ error }),
};