-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flask] Use permissions controller as source of truth for Snaps Permi…
…ssions UI (#6533) * create custom component for snaps cell * rendering permissions from permissions controller * bip32 * testing * use a switch statement * dont check for the types * handler functions * fix snapsettings test * cleanup * function to check the types * readme update
- Loading branch information
1 parent
ec12c11
commit ff739b5
Showing
14 changed files
with
1,023 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/components/Views/Snaps/components/SnapPermissionCell/SnapPermissionCell.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { Theme } from '../../../../../util/theme/models'; | ||
|
||
/** | ||
* | ||
* @param params Style sheet params. | ||
* @param params.theme App theme from ThemeContext. | ||
* @param params.vars Inputs that the style sheet depends on. | ||
* @returns StyleSheet object. | ||
*/ | ||
const styleSheet = (params: { theme: Theme }) => { | ||
const { theme } = params; | ||
const { colors } = theme; | ||
return StyleSheet.create({ | ||
permissionCell: { | ||
borderRadius: 10, | ||
borderWidth: 0, | ||
}, | ||
cellBase: { | ||
flexDirection: 'row', | ||
}, | ||
cellBaseInfo: { | ||
flex: 1, | ||
alignItems: 'flex-start', | ||
}, | ||
secondaryText: { | ||
color: colors.text.alternative, | ||
}, | ||
iconWrapper: { | ||
marginTop: 16, | ||
marginRight: 16, | ||
width: 32, | ||
height: 32, | ||
borderRadius: 16, | ||
backgroundColor: colors.background.alternative, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); | ||
}; | ||
export default styleSheet; |
69 changes: 69 additions & 0 deletions
69
app/components/Views/Snaps/components/SnapPermissionCell/SnapPermissionCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useMemo } from 'react'; | ||
import { View } from 'react-native'; | ||
import { useStyles } from '../../../../hooks/useStyles'; | ||
import stylesheet from './SnapPermissionCell.styles'; | ||
import { | ||
SNAP_PERMISSIONS_DATE, | ||
SNAP_PERMISSIONS_TITLE, | ||
SNAP_PERMISSION_CELL, | ||
} from '../../../../../constants/test-ids'; | ||
import Icon, { | ||
IconColor, | ||
IconName, | ||
IconSize, | ||
} from '../../../../../component-library/components/Icons/Icon'; | ||
import Card from '../../../../../component-library/components/Cards/Card'; | ||
import Text, { | ||
TextVariant, | ||
} from '../../../../../component-library/components/Texts/Text'; | ||
import { strings } from '../../../../../../locales/i18n'; | ||
import { toDateFormat } from '../../../../../util/date'; | ||
|
||
interface SnapPermissionCellProps { | ||
title: string; | ||
date: number; | ||
} | ||
|
||
const SnapPermissionCell = ({ title, date }: SnapPermissionCellProps) => { | ||
const snapInstalledDate: string = useMemo( | ||
() => | ||
strings('app_settings.snaps.snap_permissions.approved_date', { | ||
date: toDateFormat(date), | ||
}), | ||
[date], | ||
); | ||
|
||
const { styles } = useStyles(stylesheet, {}); | ||
return ( | ||
<Card style={styles.permissionCell}> | ||
<View testID={SNAP_PERMISSION_CELL} style={styles.cellBase}> | ||
<View style={styles.iconWrapper}> | ||
<Icon | ||
name={IconName.Key} | ||
size={IconSize.Md} | ||
color={IconColor.Muted} | ||
/> | ||
</View> | ||
<View style={styles.cellBaseInfo}> | ||
<Text | ||
testID={SNAP_PERMISSIONS_TITLE} | ||
numberOfLines={2} | ||
variant={TextVariant.HeadingSMRegular} | ||
> | ||
{title} | ||
</Text> | ||
<Text | ||
testID={SNAP_PERMISSIONS_DATE} | ||
numberOfLines={1} | ||
variant={TextVariant.BodyMD} | ||
style={styles.secondaryText} | ||
> | ||
{snapInstalledDate} | ||
</Text> | ||
</View> | ||
</View> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default React.memo(SnapPermissionCell); |
4 changes: 4 additions & 0 deletions
4
app/components/Views/Snaps/components/SnapPermissionCell/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import SnapPermissionCell from './SnapPermissionCell'; | ||
|
||
export { SnapPermissionCell }; |
51 changes: 51 additions & 0 deletions
51
app/components/Views/Snaps/components/SnapPermissionCell/test/SnapPermissionCell.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import SnapPermissionCell from '../SnapPermissionCell'; | ||
import { | ||
SNAP_PERMISSIONS_DATE, | ||
SNAP_PERMISSIONS_TITLE, | ||
SNAP_PERMISSION_CELL, | ||
} from '../../../../../../constants/test-ids'; | ||
|
||
describe('SnapPermissionCell', () => { | ||
const defaultProps = { | ||
title: 'Permission Title', | ||
date: 1686005090788, | ||
}; | ||
|
||
const setup = (props = defaultProps) => { | ||
const utils = render(<SnapPermissionCell {...props} />); | ||
const permissionCell = utils.getByTestId(SNAP_PERMISSION_CELL); | ||
const permissionTitle = utils.getByTestId(SNAP_PERMISSIONS_TITLE); | ||
const permissionDate = utils.getByTestId(SNAP_PERMISSIONS_DATE); | ||
|
||
return { | ||
...utils, | ||
permissionCell, | ||
permissionTitle, | ||
permissionDate, | ||
}; | ||
}; | ||
|
||
test('renders correctly', () => { | ||
const { permissionCell, permissionTitle, permissionDate } = setup(); | ||
|
||
const expectedDate = 'Approved on Jun 5 at 6:44 pm'; | ||
|
||
expect(permissionCell).toBeDefined(); | ||
expect(permissionTitle.props.children).toEqual(defaultProps.title); | ||
expect(permissionDate.props.children).toEqual(expectedDate); | ||
}); | ||
|
||
test('displays custom title and secondary text', () => { | ||
const customProps = { | ||
title: 'Custom Title', | ||
date: 1686005090788, | ||
}; | ||
const expectedDate = 'Approved on Jun 5 at 6:44 pm'; | ||
const { permissionTitle, permissionDate } = setup(customProps); | ||
|
||
expect(permissionTitle.props.children).toEqual(customProps.title); | ||
expect(permissionDate.props.children).toEqual(expectedDate); | ||
}); | ||
}); |
Oops, something went wrong.