Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance OTP request flow in the app #222

Merged
merged 47 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ecd59f2
feat: setup initial scaffolding for token screen
allforabit Nov 16, 2021
5e17d07
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 16, 2021
a7fab57
feat: include extra data in secret
allforabit Nov 16, 2021
ab27166
feat: make tokens on homepage clickable
allforabit Nov 16, 2021
d13d5c8
test: basic fix up of tests
allforabit Nov 16, 2021
8393e19
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 16, 2021
736494f
test: add basic test for token generation
allforabit Nov 17, 2021
84a5a04
feat: create new otp request screen and move OTP approval there
allforabit Nov 19, 2021
b99b1ad
feat: scaffold out otp request screen
allforabit Nov 19, 2021
2596e7f
feat: add new tokens list screen
allforabit Nov 19, 2021
90fcecd
feat: style tokens info on home screen
allforabit Nov 19, 2021
c0d9031
feat: style tokens list screen
allforabit Nov 22, 2021
6c7fd35
refactor: copyable info to avoid margin hack
allforabit Nov 22, 2021
88114e0
test: update home snapshots to allow for tweaks to theme and updated …
allforabit Nov 22, 2021
938e4cd
test: add create token screen
allforabit Nov 22, 2021
0577a16
feat: hide tokens count when only 1 available
allforabit Nov 22, 2021
876c28b
feat: show toasts on approval and rejection
allforabit Nov 22, 2021
3da8b52
fix: make lists refresh on revoke and refresh
allforabit Nov 22, 2021
0c31793
feat: style otp request screen
allforabit Nov 23, 2021
ab62ae3
feat: add spacing to tokens label on home screen
allforabit Nov 23, 2021
a013c3a
feat: make spacing more consistent
allforabit Nov 23, 2021
1b584ba
test: fix create token test and update home screen snapshots
allforabit Nov 23, 2021
02959da
feat: token screen revoke and refresh confirmation
allforabit Nov 23, 2021
812dc1e
feat: make description save in the background on token page
allforabit Nov 23, 2021
cfa6c5c
test: add a test for saving the description in the background
allforabit Nov 23, 2021
01c6b01
feat: don't save description in the bg if empty
allforabit Nov 23, 2021
d9ad31d
test: add basic refresh and revoke tests for token screen
allforabit Nov 23, 2021
190c96d
refactor: note -> description
allforabit Nov 23, 2021
1080bd6
refactor: make routes use secretId instead of passing whole secret obj
allforabit Nov 23, 2021
fe5fd1e
fix: description not showing on OTP request screen
allforabit Nov 24, 2021
51d900e
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 25, 2021
fafe04a
fix: add expo modules core back in to home screen and regen snapshot
allforabit Nov 25, 2021
4f992c1
fix: use new import from expo-modules-core for Subscription
allforabit Nov 25, 2021
a854812
fix: use new import from expo-modules-core for Subscription
allforabit Nov 25, 2021
a84e7c4
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 25, 2021
f975a5d
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 25, 2021
1b439c7
feat: update tokens list page to include empty view
allforabit Nov 29, 2021
1efa0a8
fix: move react key to fragment to prevent dupe key warning
allforabit Nov 29, 2021
3316311
fix: remove logging
allforabit Nov 29, 2021
d65359a
fix: throw error if token not generated correctly
allforabit Nov 29, 2021
10dd7d1
Merge branch 'master' into feat/enhance-otp-request-flow
allforabit Nov 29, 2021
162ba3c
fix: don't allow refreshing or revoking if server connection not present
allforabit Nov 29, 2021
b37c658
test: upgrade react native testing library to allow for async tests a…
allforabit Nov 29, 2021
bfdf058
test: upgrade react native testing library to allow for async tests a…
allforabit Nov 29, 2021
f4eb002
fix: include roboto mono instead of relying on system monospace font
allforabit Nov 29, 2021
230bea3
test: update snapshots and mock font
allforabit Nov 29, 2021
dbaa9c6
feat: add loading indicators
allforabit Nov 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jest.mock('react-native-reanimated', () => {
return Reanimated
})

jest.useFakeTimers()

// This is mocked to silence the warning: Animated: `useNativeDriver` is not supported
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')

Expand All @@ -29,6 +27,10 @@ jest.mock('@expo-google-fonts/didact-gothic', () => ({
useFonts: jest.fn().mockReturnValue([true]),
}))

jest.mock('@expo-google-fonts/roboto-mono', () => ({
useFonts: jest.fn().mockReturnValue([true]),
}))

jest.mock('expo-auth-session/providers/google')
jest.mock('expo-constants', () => ({
manifest: { extra: { apiUrl: 'http://dummy.com/api' } },
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@expo-google-fonts/didact-gothic": "^0.2.0",
"@expo-google-fonts/poppins": "^0.2.0",
"@expo-google-fonts/roboto-mono": "^0.2.0",
"@otplib/core": "^12.0.1",
"@otplib/plugin-base32-enc-dec": "^12.0.1",
"@otplib/plugin-crypto-js": "^12.0.1",
Expand Down Expand Up @@ -64,7 +65,7 @@
"@react-native-community/eslint-config": "^3.0.1",
"@testing-library/jest-native": "^4.0.4",
"@testing-library/react-hooks": "^7.0.2",
"@testing-library/react-native": "^7.2.0",
"@testing-library/react-native": "^8.0.0",
"@types/aes-js": "^3.1.1",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.10",
Expand Down
58 changes: 57 additions & 1 deletion src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
useFonts as useDidactGothic,
DidactGothic_400Regular,
} from '@expo-google-fonts/didact-gothic'
import {
useFonts as useRobotoMono,
RobotoMono_400Regular,
} from '@expo-google-fonts/roboto-mono'
import AppLoading from 'expo-app-loading'
import { NativeStackScreenProps } from 'react-native-screens/native-stack'

import theme from './lib/theme'
import { useAuth } from './context/AuthContext'
Expand All @@ -19,13 +24,33 @@ import { ScanScreen } from './screens/ScanScreen'
import { AuthScreen } from './screens/AuthScreen'
import HomeHeaderRight from './components/HomeHeaderRight'
import DefaultHeaderLeft from './components/DefaultHeaderLeft'
import { TokenScreen } from './screens/TokenScreen'
import { OtpRequestScreen } from './screens/OtpRequestScreen'
import { TokensListScreen } from './screens/TokensListScreen'
import { CreateTokenScreen } from './screens/CreateTokenScreen'

const MainStack = createStackNavigator()

export type MainStackParamList = {
Home: undefined
Scan: undefined
Type: undefined
CreateToken: {
secretId: string
}
Token: {
secretId: string
token: string
}
TokensList: {
secretId: string
issuer: string
}
OtpRequest: {
secretId: string
token: string
uniqueId: string
}
}

export default function Main() {
Expand All @@ -37,9 +62,13 @@ export default function Main() {
DidactGothic_400Regular,
})

const [hasRobotoMonoLoaded] = useRobotoMono({
RobotoMono_400Regular,
})

const { user } = useAuth()

if (!hasPoppinsLoaded || !hasDidactLoaded) {
if (!hasPoppinsLoaded || !hasDidactLoaded || !hasRobotoMonoLoaded) {
return <AppLoading />
}

Expand All @@ -65,6 +94,33 @@ export default function Main() {
component={HomeScreen}
options={{ title: 'Your Tokens', headerRight: HomeHeaderRight }}
/>
<MainStack.Screen
name="TokensList"
component={TokensListScreen}
options={({
route: {
params: { issuer },
},
}: NativeStackScreenProps<MainStackParamList, 'TokensList'>) => ({
title: issuer,
headerLeft: DefaultHeaderLeft,
})}
/>
<MainStack.Screen
name="CreateToken"
component={CreateTokenScreen}
options={{ title: 'Create token', headerLeft: DefaultHeaderLeft }}
/>
<MainStack.Screen
name="Token"
component={TokenScreen}
options={{ title: 'Token', headerLeft: DefaultHeaderLeft }}
/>
<MainStack.Screen
name="OtpRequest"
component={OtpRequestScreen}
options={{ title: 'OTP Request', headerLeft: DefaultHeaderLeft }}
/>
<MainStack.Screen
name="Scan"
component={ScanScreen}
Expand Down
19 changes: 1 addition & 18 deletions src/components/SecretCard/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react'
import { Divider, Menu, IconButton } from 'react-native-paper'
import { Menu, IconButton } from 'react-native-paper'

type ContextMenuProps = {
open: boolean
onToggle: () => void
onRefresh?: () => void
onRevoke?: () => void
onDelete: () => void
}

export const ContextMenu: React.FC<ContextMenuProps> = ({
open,
onToggle,
onRefresh,
onRevoke,
onDelete,
}) => {
return (
Expand All @@ -29,19 +25,6 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({
/>
}
>
<Menu.Item
onPress={onRefresh}
title="Refresh token"
icon="refresh"
disabled={!onRefresh}
/>
<Divider />
<Menu.Item
onPress={onRevoke}
title="Revoke token"
icon="minus"
disabled={!onRevoke}
/>
<Menu.Item onPress={onDelete} title="Delete secret" icon="delete" />
</Menu>
)
Expand Down
21 changes: 13 additions & 8 deletions src/components/SecretCard/CopyableInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import React from 'react'
import { IconButton } from 'react-native-paper'
import { StyleSheet, View, Text, StyleProp, TextStyle } from 'react-native'
import { StyleSheet, View } from 'react-native'
import * as Clipboard from 'expo-clipboard'
import Toast from 'react-native-root-toast'

import { TypographyVariant } from '../../lib/theme'
import { Typography } from '../Typography'

const styles = StyleSheet.create({
row: {
flexDirection: 'row',
alignItems: 'center',
},
iconButton: {
padding: 0,
marginTop: -10,
textContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
})

type CopyableInfoProps = {
children: string
textStyle: StyleProp<TextStyle>
typographyVariant: TypographyVariant
}

export const CopyableInfo: React.FC<CopyableInfoProps> = ({
children,
textStyle,
typographyVariant,
}) => {
return (
<View style={styles.row}>
<Text style={textStyle}>{children}</Text>
<View style={styles.textContainer}>
<Typography variant={typographyVariant}>{children}</Typography>
</View>
<IconButton
style={styles.iconButton}
icon="content-copy"
accessibilityLabel="copy-otp"
size={20}
Expand Down
18 changes: 6 additions & 12 deletions src/components/SecretCard/OTP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CountdownCircleTimer } from 'react-native-countdown-circle-timer'

import otpLib from '../../lib/otp'
import theme from '../../lib/theme'
import { Typography } from '../Typography'

import { CopyableInfo } from './CopyableInfo'

Expand All @@ -18,24 +19,15 @@ const styles = StyleSheet.create({
marginRight: theme.spacing(1),
fontSize: 10,
},
value: {
fontFamily: 'monospace',
fontSize: 24,
color: theme.colors.text,
marginBottom: theme.spacing(2),
},
otpRow: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: theme.spacing(2),
},
otpData: {
flexDirection: 'row',
alignItems: 'center',
},
iconButton: {
padding: 0,
marginTop: -10,
},
otp: { fontSize: 12 },
})

Expand All @@ -48,7 +40,7 @@ export const OTP: React.FC<OTPProps> = ({ value }) => {
<View style={styles.row}>
<Text style={styles.label}>OTP</Text>
<View style={styles.otpRow}>
<CopyableInfo textStyle={styles.value}>{value}</CopyableInfo>
<CopyableInfo typographyVariant="code">{value}</CopyableInfo>
<CountdownCircleTimer
key={value}
size={30}
Expand All @@ -59,7 +51,9 @@ export const OTP: React.FC<OTPProps> = ({ value }) => {
colors="#EB829C"
>
{({ remainingTime }) => (
<Text style={styles.otp}>{remainingTime}</Text>
<Typography style={styles.otp} variant="code">
{remainingTime}
</Typography>
)}
</CountdownCircleTimer>
</View>
Expand Down
Loading