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 flow UI updates #6802

Merged
merged 12 commits into from
Jul 14, 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
15 changes: 0 additions & 15 deletions app/actions/recents/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Image, View, ViewPropTypes } from 'react-native';
/* eslint-disable react/prop-types */
import React, { memo } from 'react';
import { Image, ImageStyle, View } from 'react-native';
import { toDataUrl } from '../../../util/blockies';
import FadeIn from 'react-native-fade-in-image';
import Jazzicon from 'react-native-jazzicon';
import { connect } from 'react-redux';
import { useTheme } from '../../../util/theme';

/**
* UI component that renders an Identicon
* for now it's just a blockie
* but we could add more types in the future
*/
interface IdenticonProps {
/**
* Diameter that represents the size of the identicon
*/
diameter?: number;
/**
* Address used to render a specific identicon
*/
address?: string;
/**
* Custom style to apply to image
*/
customStyle?: ImageStyle;
/**
* True if render is happening without fade in
*/
noFadeIn?: boolean;
/**
* Show a BlockieIcon instead of JazzIcon
*/
useBlockieIcon?: boolean;
}

// eslint-disable-next-line react/display-name
const Identicon = React.memo((props) => {
const { diameter, address, customStyle, noFadeIn, useBlockieIcon } = props;
const Identicon: React.FC<IdenticonProps> = ({
diameter = 46,
address,
customStyle,
noFadeIn,
useBlockieIcon = true,
}) => {
const { colors } = useTheme();

if (!address) return null;

const uri = useBlockieIcon && toDataUrl(address);

const image = useBlockieIcon ? (
Expand All @@ -41,45 +64,18 @@ const Identicon = React.memo((props) => {
if (noFadeIn) {
return image;
}

return (
<FadeIn
placeholderStyle={{ backgroundColor: colors.background.alternative }}
>
{image}
</FadeIn>
);
});

Identicon.propTypes = {
/**
* Diameter that represents the size of the identicon
*/
diameter: PropTypes.number,
/**
* Address used to render a specific identicon
*/
address: PropTypes.string,
/**
* Custom style to apply to image
*/
customStyle: ViewPropTypes.style,
/**
* True if render is happening without fade in
*/
noFadeIn: PropTypes.bool,
/**
* Show a BlockieIcon instead of JazzIcon
*/
useBlockieIcon: PropTypes.bool,
};

Identicon.defaultProps = {
diameter: 46,
useBlockieIcon: true,
};

const mapStateToProps = (state) => ({
const mapStateToProps = (state: any) => ({
useBlockieIcon: state.settings.useBlockieIcon,
});

export default connect(mapStateToProps)(Identicon);
export default connect(mapStateToProps)(memo(Identicon));
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Colors } from '../../../../util/theme/models';
import { StyleSheet } from 'react-native';

const styleSheet = (colors: Colors) =>
StyleSheet.create({
addressElementWrapper: {
padding: 16,
flexDirection: 'row',
},
addressElementInformation: {
flex: 1,
flexDirection: 'column',
},
addressIdenticon: {
paddingRight: 16,
},
addressTextNickname: {
flex: 1,
color: colors.text.default,
},
addressTextAddress: {
color: colors.text.alternative,
},
});

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import renderWithProvider from '../../../../util/test/renderWithProvider';

import AddressElement from './';
import Engine from '../../../../core/Engine';
import { renderShortAddress } from '../../../../util/address';

const mockEngine = Engine;

jest.unmock('react-redux');

jest.mock('../../../../core/Engine', () => ({
init: () => mockEngine.init({}),
context: {
NetworkController: {
provider: {
sendAsync: () => null,
},
},
},
}));

const initialState = {
engine: {
backgroundState: {
NetworkController: {
network: '1',
},
},
},
};

const renderComponent = (state: any) =>
renderWithProvider(
<AddressElement
address={'0x1234567890abcdef'}
onAccountPress={() => null}
onAccountLongPress={() => null}
testID="address-element"
/>,
{ state },
);

describe('AddressElement', () => {
it('should render correctly', () => {
const { toJSON } = renderComponent(initialState);
expect(toJSON()).toMatchSnapshot();
});

it('should render the address', () => {
const address = '0x1234567890abcdef';
const { getByText } = renderComponent(initialState);
const addressText = getByText(renderShortAddress(address));
expect(addressText).toBeDefined();
});
});
85 changes: 85 additions & 0 deletions app/components/Views/SendFlow/AddressElement/AddressElement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* eslint-disable react/prop-types */

// Third-Party dependencies
import React, { useEffect, useState, useCallback } from 'react';
import { View, TouchableOpacity } from 'react-native';

// Exgernal dependencies
import { renderShortAddress } from '../../../../util/address';
import Identicon from '../../../UI/Identicon';
import { useSelector } from 'react-redux';
import { useTheme } from '../../../../util/theme';
import Text from '../../../../component-library/components/Texts/Text/Text';
import { TextVariant } from '../../../../component-library/components/Texts/Text';
import { selectNetwork } from '../../../../selectors/networkController';
import { doENSReverseLookup } from '../../../../util/ENSUtils';

// Internal dependecies
import styleSheet from './AddressElement.styles';
import { AddressElementProps } from './AddressElement.types';

const AddressElement: React.FC<AddressElementProps> = ({
name,
address,
onAccountPress,
onAccountLongPress,
...props
}) => {
const [displayName, setDisplayName] = useState(name);
const { colors } = useTheme();
const styles = styleSheet(colors);

const network = useSelector(selectNetwork);

const fetchENSName = useCallback(async () => {
if (!displayName) {
const ensName = await doENSReverseLookup(address, network);
setDisplayName(ensName);
}
}, [displayName, address, network]);

useEffect(() => {
fetchENSName();
}, [fetchENSName]);

const primaryLabel =
displayName && !displayName.startsWith(' ')
? displayName
: renderShortAddress(address);
const secondaryLabel =
displayName && !displayName.startsWith(' ') && renderShortAddress(address);

return (
<TouchableOpacity
onPress={() => onAccountPress(address)}
onLongPress={() => onAccountLongPress(address)}
key={address}
style={styles.addressElementWrapper}
{...props}
>
<View style={styles.addressIdenticon}>
<Identicon address={address} diameter={28} />
</View>
<View style={styles.addressElementInformation}>
<Text
variant={TextVariant.BodyMD}
style={styles.addressTextNickname}
numberOfLines={1}
>
{primaryLabel}
</Text>
{!!secondaryLabel && (
<Text
variant={TextVariant.BodyMD}
style={styles.addressTextAddress}
numberOfLines={1}
>
{secondaryLabel}
</Text>
)}
</View>
</TouchableOpacity>
);
};

export default AddressElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TouchableOpacityProps } from 'react-native';

export interface AddressElementProps extends TouchableOpacityProps {
/**
* Name to display
*/
name?: string;
/**
* Ethereum address
*/
address: string;
/**
* Callback on account press
*/
onAccountPress: (address: string) => void;
/**
* Callback on account long press
*/
onAccountLongPress: (address: string) => void;
}

Large diffs are not rendered by default.

This file was deleted.

Loading
Loading