Skip to content

Commit

Permalink
Component: Contract Box Update (#5328)
Browse files Browse the repository at this point in the history
* can press contract address
  • Loading branch information
blackdevelopa authored Dec 1, 2022
1 parent 8d47108 commit 09b2cbc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export const CONTRACT_COPY_ADDRESS = () => {
export const CONTRACT_EXPORT_ADDRESS = () => {
console.log('export address');
};

export const CONTRACT_ON_PRESS = () => {
console.log('contract pressed');
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CONTRACT_LOCAL_IMAGE,
CONTRACT_COPY_ADDRESS,
CONTRACT_EXPORT_ADDRESS,
CONTRACT_ON_PRESS,
} from './ContractBox.constants';

storiesOf('Component Library / Contract Box', module)
Expand All @@ -19,6 +20,7 @@ storiesOf('Component Library / Contract Box', module)
contractLocalImage={CONTRACT_LOCAL_IMAGE}
onCopyAddress={CONTRACT_COPY_ADDRESS}
onExportAddress={CONTRACT_EXPORT_ADDRESS}
onContractPress={CONTRACT_ON_PRESS}
/>
))
.add('Saved Address', () => (
Expand All @@ -28,5 +30,6 @@ storiesOf('Component Library / Contract Box', module)
contractLocalImage={CONTRACT_LOCAL_IMAGE}
onCopyAddress={CONTRACT_COPY_ADDRESS}
onExportAddress={CONTRACT_EXPORT_ADDRESS}
onContractPress={CONTRACT_ON_PRESS}
/>
));
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CONTRACT_LOCAL_IMAGE,
CONTRACT_COPY_ADDRESS,
CONTRACT_EXPORT_ADDRESS,
CONTRACT_ON_PRESS,
} from './ContractBox.constants';

describe('ContractBox', () => {
Expand All @@ -20,6 +21,7 @@ describe('ContractBox', () => {
contractLocalImage={CONTRACT_LOCAL_IMAGE}
onCopyAddress={CONTRACT_COPY_ADDRESS}
onExportAddress={CONTRACT_EXPORT_ADDRESS}
onContractPress={CONTRACT_ON_PRESS}
/>,
);
const singleSelectComponent = wrapper.findWhere(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ContractBox = ({
contractLocalImage,
onExportAddress,
onCopyAddress,
onContractPress,
}: ContractBoxProps) => (
<View testID={CONTRACT_BOX_TEST_ID}>
<Card style={styles.container}>
Expand All @@ -21,6 +22,7 @@ const ContractBox = ({
contractLocalImage={contractLocalImage}
onExportAddress={onExportAddress}
onCopyAddress={onCopyAddress}
onContractPress={onContractPress}
/>
</Card>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Text, { TextVariants } from '../../../components/Texts/Text';
import { formatAddress } from '../../../../util/address';
import Icon, { IconName, IconSize } from '../../../components/Icon';
import { useStyles } from '../../../hooks';
import ButtonLink from '../../../components/Buttons/Button/variants/ButtonLink';

// Internal dependencies.
import { ContractBoxBaseProps, IconViewProps } from './ContractBoxBase.types';
Expand All @@ -28,6 +29,7 @@ const ContractBoxBase = ({
contractPetName,
onCopyAddress,
onExportAddress,
onContractPress,
}: ContractBoxBaseProps) => {
const formattedAddress = formatAddress(contractAddress, 'short');
const { styles } = useStyles(styleSheet, {});
Expand All @@ -47,17 +49,21 @@ const ContractBoxBase = ({
imageSource={contractLocalImage}
/>
{contractPetName ? (
<View>
<Pressable onPress={onContractPress}>
<Text style={styles.header} variant={TextVariants.sHeadingMD}>
{contractPetName}
</Text>
<Text variant={TextVariants.sBodyMD}>{formattedAddress}</Text>
</View>
</Pressable>
) : (
<View testID={CONTRACT_BOX_NO_PET_NAME_TEST_ID}>
<Text style={styles.header} variant={TextVariants.sHeadingMD}>
<ButtonLink
textVariants={TextVariants.sHeadingMD}
style={styles.header}
onPress={onContractPress}
>
{formattedAddress}
</Text>
</ButtonLink>
</View>
)}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export interface ContractBoxBaseProps {
*/
onCopyAddress: () => void;
/**
* function that opens contract in block explorer
* function that opens contract in block explorer if present
*/
onExportAddress: () => void;
onExportAddress?: () => void;
/**
* functions that called when the user clicks on the contract name
*/
onContractPress: () => void;
}

export interface IconViewProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`Component ContractBoxBase should render correctly 1`] = `
size="48"
variant="Token"
/>
<View>
<Component>
<Text
style={
Object {
Expand All @@ -44,7 +44,7 @@ exports[`Component ContractBoxBase should render correctly 1`] = `
>
0x2990...a21a
</Text>
</View>
</Component>
</View>
<View
style={
Expand Down

0 comments on commit 09b2cbc

Please sign in to comment.