Skip to content

Commit

Permalink
Add account_network section to re-designed confirmation page
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Oct 9, 2024
1 parent a11ee59 commit 5cd6b9a
Show file tree
Hide file tree
Showing 26 changed files with 1,179 additions and 17 deletions.
3 changes: 1 addition & 2 deletions app/components/Views/confirmations/Confirm/Confirm.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const styleSheet = (params: { theme: Theme }) => {
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
paddingBottom: Device.isIphoneX() ? 20 : 0,
alignItems: 'center',
justifyContent: 'space-between'
justifyContent: 'space-between',
},
});
};
Expand Down
2 changes: 2 additions & 0 deletions app/components/Views/confirmations/Confirm/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { View } from 'react-native';

import { useStyles } from '../../../../component-library/hooks';
import BottomModal from '../components/UI/BottomModal';
import AccountNetworkInfo from '../components/Confirm/AccountNetworkInfo';
import Footer from '../components/Confirm/Footer';
import Info from '../components/Confirm/Info';
import Title from '../components/Confirm/Title';
Expand All @@ -22,6 +23,7 @@ const Confirm = () => {
<View style={styles.container}>
<View>
<Title />
<AccountNetworkInfo />
<Info />
</View>
<Footer />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StyleSheet } from 'react-native';

const styleSheet = () =>
StyleSheet.create({
container: {
marginBottom: 24,
},
});
export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import renderWithProvider from '../../../../../../util/test/renderWithProvider';
import { personalSignatureConfirmationState } from '../../../../../../util/test/confirm-data-helpers';
import AccountNetworkInfo from './AccountNetworkInfo';

describe('AccountNetworkInfo', () => {
it('should match snapshot for personal sign', async () => {
const container = renderWithProvider(<AccountNetworkInfo />, {
state: personalSignatureConfirmationState,
});
expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import { View } from 'react-native';

import { strings } from '../../../../../../../locales/i18n';
import { useStyles } from '../../../../../../component-library/hooks';
import useApprovalRequest from '../../../hooks/useApprovalRequest';
import ExpandableSection from '../../UI/ExpandableSection';
import AccountNetworkInfoCollapsed from './AccountNetworkInfoCollapsed';
import AccountNetworkInfoExpanded from './AccountNetworkInfoExpanded';
import styleSheet from './AccountNetworkInfo.styles';

const AccountNetworkInfo = () => {
const { approvalRequest } = useApprovalRequest();
const { styles } = useStyles(styleSheet, {});

if (!approvalRequest) {
return null;
}

return (
<View style={styles.container}>
<ExpandableSection
collapsedContent={<AccountNetworkInfoCollapsed />}
expandedContent={<AccountNetworkInfoExpanded />}
modalTitle={strings('confirm.details')}
/>
</View>
);
};

export default AccountNetworkInfo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { StyleSheet } from 'react-native';

import { Theme } from '../../../../../../../util/theme/models';
import { fontStyles } from '../../../../../../../styles/common';

const styleSheet = (params: { theme: Theme }) => {
const { theme } = params;

return StyleSheet.create({
container: {
display: 'flex',
flexDirection: 'row',
},
badgeWrapper: {
marginRight: 16,
alignSelf: 'center',
},
accountName: {
color: theme.colors.text.default,
...fontStyles.normal,
fontSize: 14,
fontWeight: '500',
},
networkName: {
color: theme.colors.text.default,
...fontStyles.normal,
fontSize: 14,
fontWeight: '400',
},
});
};

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import renderWithProvider from '../../../../../../../util/test/renderWithProvider';
import { personalSignatureConfirmationState } from '../../../../../../../util/test/confirm-data-helpers';
import AccountNetworkInfoCollapsed from './AccountNetworkInfoCollapsed';

describe('AccountNetworkInfoCollapsed', () => {
it('should match snapshot for personal sign', async () => {
const container = renderWithProvider(<AccountNetworkInfoCollapsed />, {
state: personalSignatureConfirmationState,
});
expect(container).toMatchSnapshot(); //
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { Text, View } from 'react-native';
import { useSelector } from 'react-redux';

import Avatar, {
AvatarAccountType,
AvatarVariant,
} from '../../../../../../../component-library/components/Avatars/Avatar';
import Badge, {
BadgeVariant,
} from '../../../../../../../component-library/components/Badges/Badge';
import BadgeWrapper from '../../../../../../../component-library/components/Badges/BadgeWrapper';
import { RootState } from '../../../../../../UI/BasicFunctionality/BasicFunctionalityModal/BasicFunctionalityModal.test';
import { useStyles } from '../../../../../../../component-library/hooks';
import {
selectNetworkImageSource,
selectNetworkName,
} from '../../../../../../../selectors/networkInfos';
import useAccountInfo from '../../../../hooks/useAccountInfo';
import useApprovalRequest from '../../../../hooks/useApprovalRequest';
import styleSheet from './AccountNetworkInfoCollapsed.styles';

const AccountNetworkInfoCollapsed = () => {
const { approvalRequest } = useApprovalRequest();
const networkName = useSelector(selectNetworkName);
const networkImage = useSelector(selectNetworkImageSource);
const useBlockieIcon = useSelector(
(state: RootState) => state.settings.useBlockieIcon,
);
const fromAddress = approvalRequest?.requestData?.from;
const { accountName } = useAccountInfo(fromAddress);
const { styles } = useStyles(styleSheet, {});

return (
<View style={styles.container}>
<BadgeWrapper
badgeElement={
<Badge
variant={BadgeVariant.Network}
name={networkName}
imageSource={networkImage}
/>
}
style={styles.badgeWrapper}
>
<Avatar
variant={AvatarVariant.Account}
type={
useBlockieIcon
? AvatarAccountType.Blockies
: AvatarAccountType.JazzIcon
}
accountAddress={fromAddress}
/>
</BadgeWrapper>
<View>
<Text style={styles.accountName}>{accountName}</Text>
<Text style={styles.networkName}>{networkName}</Text>
</View>
</View>
);
};

export default AccountNetworkInfoCollapsed;

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AccountNetworkInfoCollapsed';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StyleSheet } from 'react-native';

const styleSheet = () =>
StyleSheet.create({
container: {
display: 'flex',
},
});

export default styleSheet;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

import renderWithProvider from '../../../../../../../util/test/renderWithProvider';
import { personalSignatureConfirmationState } from '../../../../../../../util/test/confirm-data-helpers';
import AccountNetworkInfoExpanded from './AccountNetworkInfoExpanded';

describe('AccountNetworkInfoExpanded', () => {
it('should match snapshot for personal sign', async () => {
const container = renderWithProvider(<AccountNetworkInfoExpanded />, {
state: personalSignatureConfirmationState,
});
expect(container).toMatchSnapshot(); //
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { View } from 'react-native';
import { useSelector } from 'react-redux';

import { strings } from '../../../../../../../../locales/i18n';
import { selectRpcUrl } from '../../../../../../../selectors/networkController';
import { useStyles } from '../../../../../../../component-library/hooks';
import { selectNetworkName } from '../../../../../../../selectors/networkInfos';
import useAccountInfo from '../../../../hooks/useAccountInfo';
import useApprovalRequest from '../../../../hooks/useApprovalRequest';
import styleSheet from './AccountNetworkInfoExpanded.styles';
import InfoSection from '../../../UI/InfoRow/InfoSection';
import InfoRow from '../../../UI/InfoRow';
import InfoURL from '../../../UI/InfoRow/InfoValue/InfoURL';

const AccountNetworkInfoExpanded = () => {
const { approvalRequest } = useApprovalRequest();
const networkName = useSelector(selectNetworkName);
const networkRpcUrl = useSelector(selectRpcUrl);
const fromAddress = approvalRequest?.requestData?.from;
const { accountAddress, addressBalance } = useAccountInfo(fromAddress);
const { styles } = useStyles(styleSheet, {});

return (
<View style={styles.container}>
<InfoSection>
<InfoRow label={strings('confirm.account')}>{accountAddress}</InfoRow>
<InfoRow label={strings('confirm.balance')}>{addressBalance}</InfoRow>
</InfoSection>
<InfoSection>
<InfoRow
label={strings('confirm.network')}
tooltip={strings('confirm.network')}
>
{networkName}
</InfoRow>
<InfoRow label={strings('confirm.rpc_url')}>
<InfoURL url={networkRpcUrl} />
</InfoRow>
</InfoSection>
</View>
);
};

export default AccountNetworkInfoExpanded;
Loading

0 comments on commit 5cd6b9a

Please sign in to comment.