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: send package info when requesting OTP #1198

Merged
merged 6 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.3.10",
"versionCode": 21,
"scripts": {
"start": "expo start --dev-client",
guilhermelimak marked this conversation as resolved.
Show resolved Hide resolved
"start": "expo start",
"start:native": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
Expand Down Expand Up @@ -117,4 +117,4 @@
"prettier --write"
]
}
}
}
4 changes: 4 additions & 0 deletions src/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export type MainStackParamList = {
secretId: string
token: string
uniqueId: string
packageInfo?: {
name?: string
version?: string
}
guilhermelimak marked this conversation as resolved.
Show resolved Hide resolved
}
Notifications: undefined
ExportFileSecret: undefined
Expand Down
12 changes: 9 additions & 3 deletions src/components/NotificationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useSecretSelector } from '../hooks/use-secret-selector'
import { useTokenDataSelector } from '../hooks/use-token-data-selector'

import { Typography } from './Typography'
import { PackageInfo } from './PackageInfo'

const OTP_REQUEST_TIMEOUT = 60001 // See https://github.com/nearform/optic/blob/master/server/lib/routes/otp.js#L5

Expand All @@ -37,7 +38,7 @@ const styles = StyleSheet.create({
tokenDescriptionRow: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: theme.spacing(2),
marginBottom: theme.spacing(1),
},
button: {
marginTop: theme.spacing(2),
Expand Down Expand Up @@ -77,8 +78,6 @@ const TokenInfo: React.FC<TokenInfoProps> = ({ token, description }) => {
<View style={styles.tokenDescriptionRow}>
<Typography variant="code">{token}</Typography>
</View>
</View>
<View style={styles.cardRow}>
<View style={styles.tokenDescriptionRow}>
<Typography variant="body1">{description}</Typography>
</View>
Expand Down Expand Up @@ -140,6 +139,8 @@ export const NotificationCard: React.FC<NotificationCardProps> = ({
[data.uniqueId, removeNotification]
)

const packageInfo = notification.request.content.data.packageInfo

return (
<>
<View style={styles.container}>
Expand All @@ -151,6 +152,11 @@ export const NotificationCard: React.FC<NotificationCardProps> = ({
/>
<Card.Content>
<TokenInfo token={token.token} description={token.description} />
{packageInfo && (
<View style={styles.cardRow}>
<PackageInfo packageInfo={packageInfo} />
</View>
)}
<View style={styles.cardRow}>
<TimeAgo
date={new Date(notification.date)}
Expand Down
43 changes: 43 additions & 0 deletions src/components/PackageInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'
import { StyleSheet, View } from 'react-native'

import theme from '../lib/theme'

import { Typography } from './Typography'

const styles = StyleSheet.create({
packageInfo: {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: theme.spacing(2),
},
})

type PackageInfoProps = {
packageInfo: {
version?: string
name?: string
}
}

export const PackageInfo: React.FC<PackageInfoProps> = ({
packageInfo: { version, name } = {},
}) => {
return (
<View style={styles.packageInfo}>
{name && (
<View>
<Typography variant="overline">Package</Typography>
<Typography variant="body1">{name}</Typography>
</View>
)}
{version && (
<View>
<Typography variant="overline">Version</Typography>
<Typography variant="body1">{version}</Typography>
</View>
)}
</View>
)
}
3 changes: 2 additions & 1 deletion src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({ navigation }) => {
async (res: NotificationResponse) => {
const data = res.notification.request.content.data as NotificationData

const { secretId, uniqueId, token } = data
const { secretId, uniqueId, token, packageInfo } = data

const secret = secrets.find(({ _id }) => _id === secretId)

Expand All @@ -104,6 +104,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({ navigation }) => {
token,
secretId,
uniqueId,
packageInfo,
})
},
[navigation, secrets]
Expand Down
4 changes: 3 additions & 1 deletion src/screens/OtpRequestScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useSecretSelector } from '../hooks/use-secret-selector'
import { LoadingSpinnerOverlay } from '../components/LoadingSpinnerOverlay'
import { usePrefs } from '../context/PrefsContext'
import { useCanUseLocalAuth } from '../hooks/use-can-use-local-auth'
import { PackageInfo } from '../components/PackageInfo'

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -52,7 +53,7 @@ export const OtpRequestScreen = ({ route, navigation }: Props) => {
const canUseLocalAuth = useCanUseLocalAuth()

const api = useMemo(() => apiFactory({ idToken: user.idToken }), [user])
const { token, secretId, uniqueId } = route.params
const { token, secretId, uniqueId, packageInfo } = route.params
const secret = useSecretSelector(secretId)
const tokenData = useTokenDataSelector(secretId, token)
const description = tokenData ? tokenData.description : ''
Expand Down Expand Up @@ -134,6 +135,7 @@ export const OtpRequestScreen = ({ route, navigation }: Props) => {
</Typography>
<Typography variant="body1">{description}</Typography>
</View>
{packageInfo && <PackageInfo packageInfo={packageInfo} />}
<View>
<Button style={styles.button} mode="outlined" onPress={handleReject}>
Reject
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export type NotificationData = {
secretId: string
uniqueId: string
token: string
packageInfo?: {
name?: string
version?: string
}
}

export type OpticNotification = Notification & {
Expand Down