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: Create Permit Simulation #12606

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
87b746e
feat: Permit Simulation
digiwand Dec 6, 2024
60086e1
refactor: PermitSimulation const name
digiwand Dec 6, 2024
ae2a2cb
fix: label_change_type i18n
digiwand Dec 9, 2024
5b5d094
feat: add PermitSimulation metrics
digiwand Dec 9, 2024
dfc086f
feat: create ButtonPill component
digiwand Dec 10, 2024
d96f9aa
feat: PermitSimulation token value BottomModal
digiwand Dec 12, 2024
a665679
Merge branch 'main' into feat-permit-simulation
digiwand Dec 13, 2024
518e51d
feat: Add Permit Simulation to TypedSignV3V4 redesign
digiwand Dec 16, 2024
f069e37
refactor: cleanup
digiwand Dec 17, 2024
fe15f12
chore: update todo ValueDisplay shorten comment
digiwand Dec 17, 2024
6777319
refactor: update useGetTokenStandardAndDetails import
digiwand Dec 18, 2024
4bc90e0
fix: PermitSimulation changeType
digiwand Dec 18, 2024
b65adf3
test: PermitSimulation
digiwand Dec 18, 2024
a79f2cd
fix: useTrackERC20WithoutDecimalInformation should run once
digiwand Dec 18, 2024
a5d96ec
fix: include typedSignV4ConfirmationState for PermitSimulation test
digiwand Dec 18, 2024
05669d3
test: create PermitSimulationValueDisplay test
digiwand Dec 18, 2024
bcccb06
fix: TS lint signature util
digiwand Dec 19, 2024
22f754f
Merge branch 'main' into feat-permit-simulation
digiwand Jan 7, 2025
567fc66
fix: readd dep to useTrackERC20WithoutDecimalInformation
digiwand Jan 7, 2025
0c215c4
chore: update useTrackERC20WithoutDecimalInformation TS metricLocation
digiwand Jan 7, 2025
1683123
test: ValueDisplay test
digiwand Jan 7, 2025
79a4003
fix: test allow style param InfoAddress
digiwand Jan 7, 2025
aa43eb9
test:fix: OrderDetails allow undefined style param
digiwand Jan 7, 2025
8577591
test:fix: include InfoAddress undefined style param
digiwand Jan 7, 2025
d53035f
chore: ButtonPill pressed -> isPressed
digiwand Jan 7, 2025
2bdb950
build: mv ButtonPill files -> components-temp
digiwand Jan 7, 2025
1ffe22e
test: create confirmations/utils/signature test
digiwand Jan 9, 2025
779f36f
test: add parseTypedDataMessage tests
digiwand Jan 9, 2025
5852d87
test: add shortenString tests for skipCharacterInEnd + update TS
digiwand Jan 9, 2025
fce5367
Merge branch 'main' into feat-permit-simulation
digiwand Jan 11, 2025
f0cc923
build: mv permit simulation files
digiwand Jan 11, 2025
98d89c7
build: rn path Simulation/Permit -> Simulation/TypedSignPermit
digiwand Jan 11, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Third party dependencies.
import { StyleSheet } from 'react-native';

// External dependencies.
import { Theme } from '../../../../util/theme/models';

/**
* Style sheet input parameters.
*/
export interface ButtonPillStyleSheetVars {
pressed: boolean;
digiwand marked this conversation as resolved.
Show resolved Hide resolved
isDisabled: boolean;
}

/**
* Style sheet function for ButtonPill component
*
* @param params Style sheet params
* @param params.theme Theme object
* @param params.vars Arbitrary inputs this style sheet depends on
* @returns StyleSheet object
*/
const styleSheet = (params: {
theme: Theme;
vars: ButtonPillStyleSheetVars;
}) => {
const {
theme: { colors },
vars: { pressed, isDisabled }
} = params;

return StyleSheet.create({
base: {
backgroundColor: colors.background.alternative,
color: colors.text.default,
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 8,
paddingVertical: 4,
borderRadius: 99,
opacity: isDisabled ? 0.5 : 1,
...(pressed && {
backgroundColor: colors.background.alternativePressed,
}),
},
});
};

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Third party dependencies.
import React from 'react';
import { render } from '@testing-library/react-native';

// Internal dependencies.
import ButtonPill from './ButtonPill';

describe('ButtonPill', () => {
it('should render correctly', () => {
const { toJSON } = render(
<ButtonPill onPress={jest.fn} />,
);
expect(toJSON()).toMatchSnapshot();
});
});
69 changes: 69 additions & 0 deletions app/component-library/components/Buttons/ButtonPill/ButtonPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Third party dependencies.
import React, { useCallback, useState } from 'react';
import { GestureResponderEvent, TouchableOpacity, TouchableOpacityProps } from 'react-native';

// External dependencies.
import { useStyles } from '../../../hooks';

// Internal dependencies.
import stylesheet from './ButtonPill.styles';

/**
* ButtonPill component props.
*/
export interface ButtonPillProps extends TouchableOpacityProps {
/**
* Optional param to disable the button.
*/
isDisabled?: boolean;
}

const ButtonPill = ({
onPress,
onPressIn,
onPressOut,
style,
isDisabled = false,
children,
...props
}: ButtonPillProps) => {
const [pressed, setPressed] = useState(false);
const { styles } = useStyles(stylesheet, {
style,
pressed,
isDisabled,
});

const triggerOnPressedIn = useCallback(
(e: GestureResponderEvent) => {
setPressed(true);
onPressIn?.(e);
},
[setPressed, onPressIn],
);

const triggerOnPressedOut = useCallback(
(e: GestureResponderEvent) => {
setPressed(false);
onPressOut?.(e);
},
[setPressed, onPressOut],
);

return (
<TouchableOpacity
style={styles.base}
onPress={!isDisabled ? onPress : undefined}
onPressIn={!isDisabled ? triggerOnPressedIn : undefined}
onPressOut={!isDisabled ? triggerOnPressedOut : undefined}
accessible
activeOpacity={1}
disabled={isDisabled}
{...props}
>
{children}
</TouchableOpacity>
);
};

export default ButtonPill;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ButtonPill should render correctly 1`] = `
<TouchableOpacity
accessible={true}
activeOpacity={1}
disabled={false}
onPress={[Function]}
onPressIn={[Function]}
onPressOut={[Function]}
style={
{
"alignItems": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"color": "#141618",
"justifyContent": "center",
"opacity": 1,
"paddingHorizontal": 8,
"paddingVertical": 4,
}
}
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ButtonPill';
12 changes: 7 additions & 5 deletions app/components/UI/Name/Name.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */
import React from 'react';
import { TextProps, View } from 'react-native';
import { TextProps, View, ViewStyle } from 'react-native';

import { useStyles } from '../../../component-library/hooks';
import Text, {
Expand Down Expand Up @@ -34,11 +34,12 @@ const NameLabel: React.FC<{
);
};

const UnknownEthereumAddress: React.FC<{ address: string }> = ({ address }) => {
const UnknownEthereumAddress: React.FC<{ address: string, style?: ViewStyle }> = ({ address, style }) => {
const displayNameVariant = DisplayNameVariant.Unknown;
const { styles } = useStyles(styleSheet, { displayNameVariant });

return (
<View style={styles.base}>
<View style={[styles.base, style]}>
<Icon name={IconName.Question} />
<NameLabel displayNameVariant={displayNameVariant} ellipsizeMode="middle">
{renderShortAddress(address, 5)}
Expand All @@ -52,6 +53,7 @@ const Name: React.FC<NameProperties> = ({
type,
value,
variation,
style,
}) => {
if (type !== NameType.EthereumAddress) {
throw new Error('Unsupported NameType: ' + type);
Expand All @@ -69,11 +71,11 @@ const Name: React.FC<NameProperties> = ({
});

if (variant === DisplayNameVariant.Unknown) {
return <UnknownEthereumAddress address={value} />;
return <UnknownEthereumAddress address={value} style={style} />;
}

return (
<View style={styles.base}>
<View style={[styles.base, style]}>
<Identicon
address={value}
diameter={16}
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/Name/Name.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ViewProps } from 'react-native';
import { ViewProps, ViewStyle } from 'react-native';

/**
* The name types supported by the NameController.
Expand All @@ -15,4 +15,5 @@ export interface NameProperties extends ViewProps {
type: NameType;
value: string;
variation: string;
style?: ViewStyle;
}
75 changes: 42 additions & 33 deletions app/components/UI/Name/__snapshots__/Name.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
exports[`Name recognized address should render image 1`] = `
<View
style={
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
}
[
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
},
undefined,
]
}
>
<View
Expand Down Expand Up @@ -102,17 +105,20 @@ exports[`Name recognized address should render image 1`] = `
exports[`Name recognized address should return name 1`] = `
<View
style={
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
}
[
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
},
undefined,
]
}
>
<View
Expand Down Expand Up @@ -201,17 +207,20 @@ exports[`Name recognized address should return name 1`] = `
exports[`Name unknown address displays checksummed address 1`] = `
<View
style={
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
}
[
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#f2f4f6",
"borderRadius": 99,
"flexDirection": "row",
"gap": 5,
"paddingLeft": 8,
"paddingRight": 8,
"paddingVertical": 4,
},
undefined,
]
}
>
<SvgMock
Expand Down
Loading
Loading