Skip to content

feat: base account details #33277

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { Box, Text } from '../../component-library';
import { BackgroundColor, Display, JustifyContent, AlignItems, TextColor } from '../../../helpers/constants/design-system';

type AccountDetailsRowProps = {
label: string;
value: string;
endAccessory: React.ReactNode;
style?: React.CSSProperties;
};

export const AccountDetailsRow = ({
label,
value,
endAccessory,
style,
}: AccountDetailsRowProps) => {
return (
<Box
backgroundColor={BackgroundColor.backgroundAlternative}
display={Display.Flex}
justifyContent={JustifyContent.spaceBetween}
style={{ ...style, height: '48px' }}
paddingLeft={4}
paddingRight={4}
alignItems={AlignItems.center}
>
<Text color={TextColor.textDefault}>{label}</Text>
<Box display={Display.Flex} alignItems={AlignItems.center}>
<Text color={TextColor.textAlternative}>{value}</Text>
{endAccessory}
</Box>
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AccountDetailsRow } from './account-details-row';
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { AppSliceState } from '../../../ducks/app/app';
import { getInternalAccountByAddress, getUseBlockie } from '../../../selectors';
import {
AvatarAccount,
AvatarAccountSize,
AvatarAccountVariant,
Box,
ButtonIcon,
ButtonIconSize,
} from '../../component-library';
import { Content, Header, Page } from '../../multichain/pages/page';
import {
BackgroundColor,
IconColor,
} from '../../../helpers/constants/design-system';
import { ACCOUNT_DETAILS_QR_CODE_ROUTE, DEFAULT_ROUTE } from '../../../helpers/constants/routes';
import { IconName } from '../../component-library/icon';
import { useHistory } from 'react-router-dom';
import { isEvmAccountType } from '@metamask/keyring-api';
import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils';
import { shortenAddress } from '../../../helpers/utils/util';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { AccountDetailsRow } from '../account-details-row';
import { EditAccountNameModal } from '../edit-account-name-modal';

type BaseAccountDetailsProps = {
children: React.ReactNode | React.ReactNode[];
};

export const BaseAccountDetails = ({ children }: BaseAccountDetailsProps) => {
const address = useSelector(
(state: AppSliceState) => state.appState.accountDetailsAddress,
);
const useBlockie = useSelector(getUseBlockie);
const history = useHistory();
const t = useI18nContext();
const account = useSelector((state) =>
getInternalAccountByAddress(state, address),
);
const {
metadata: { name },
type,
} = account;
const formattedAddress = isEvmAccountType(type)
? toChecksumHexAddress(address)?.toLowerCase()
: address;
const shortenedAddress = shortenAddress(formattedAddress);

const [isEditingAccountName, setIsEditingAccountName] = useState(false);

const handleShowAddress = () => {
history.push(`${ACCOUNT_DETAILS_QR_CODE_ROUTE}`);
}

return (
<Page backgroundColor={BackgroundColor.backgroundDefault}>
<Header
backgroundColor={BackgroundColor.backgroundDefault}
startAccessory={
<ButtonIcon
ariaLabel="Back"
iconName={IconName.ArrowLeft}
size={ButtonIconSize.Sm}
onClick={() => history.push(DEFAULT_ROUTE)}
/>
}
>
{name}
</Header>
<Content>
<AvatarAccount
address={address}
variant={
useBlockie
? AvatarAccountVariant.Blockies
: AvatarAccountVariant.Jazzicon
}
size={AvatarAccountSize.Lg}
style={{ margin: '0 auto' }}
/>
<Box className="multichain-account-details__section">
<AccountDetailsRow
label={t('accountName')}
value={name}
endAccessory={
<ButtonIcon
iconName={IconName.Edit}
color={IconColor.iconAlternative}
size={ButtonIconSize.Md}
ariaLabel={t('edit')}
onClick={handleShowAddress}
marginLeft={2}
/>
}
style={{
marginBottom: '1px',
borderTopLeftRadius: '8px',
borderTopRightRadius: '8px',
}}
/>
<AccountDetailsRow
label={t('address')}
value={shortenedAddress}
endAccessory={
<ButtonIcon
iconName={IconName.ArrowRight}
color={IconColor.iconAlternative}
size={ButtonIconSize.Md}
ariaLabel={t('next')}
onClick={handleShowAddress}
marginLeft={2}
/>
}
style={{
borderBottomLeftRadius: '8px',
borderBottomRightRadius: '8px',
}}
/>
</Box>
{children}
{isEditingAccountName && (
<EditAccountNameModal
isOpen={isEditingAccountName}
onClose={() => setIsEditingAccountName(false)}
currentAccountName={name}
address={address}
/>
)}
</Content>
</Page>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useState } from 'react';
import {
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalBody,
ModalFooter,
FormTextField,
} from '../../component-library';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { setAccountLabel } from '../../../store/actions';
import { useDispatch } from 'react-redux';

type EditAccountNameModalProps = {
isOpen: boolean;
onClose: () => void;
currentAccountName: string;
address: string;
};

export const EditAccountNameModal = ({
isOpen,
onClose,
currentAccountName,
address,
}: EditAccountNameModalProps) => {
const [accountName, setAccountName] = useState('');
const t = useI18nContext();
const dispatch = useDispatch();

const handleSaveAccountName = () => {
onClose();
dispatch(setAccountLabel(address, accountName));
};

return (
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader onBack={onClose} onClose={onClose}>
{t('editAccountName')}
</ModalHeader>
<ModalBody>
<FormTextField
label={t('name')}
value={accountName}
onChange={(e) => setAccountName(e.target.value)}
placeholder={currentAccountName}
helpText={address}
/>
</ModalBody>
<ModalFooter
onSubmit={handleSaveAccountName}
submitButtonProps={{ children: t('save'), disabled: !accountName }}
/>
</ModalContent>
</Modal>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EditAccountNameModal } from './edit-account-name-modal';
6 changes: 6 additions & 0 deletions ui/helpers/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ PATH_NAME_MAP[CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE] =
export const NEW_ACCOUNT_ROUTE = '/new-account';
PATH_NAME_MAP[NEW_ACCOUNT_ROUTE] = 'New Account Page';

export const ACCOUNT_DETAILS_ROUTE = '/account-details';
PATH_NAME_MAP[ACCOUNT_DETAILS_ROUTE] = 'Account Details Page';

export const ACCOUNT_DETAILS_QR_CODE_ROUTE = '/account-details/qr-code';
PATH_NAME_MAP[ACCOUNT_DETAILS_QR_CODE_ROUTE] = 'Account Details QR Code Page';

export const CONFIRM_ADD_SUGGESTED_NFT_ROUTE = '/confirm-add-suggested-nft';
PATH_NAME_MAP[CONFIRM_ADD_SUGGESTED_NFT_ROUTE] =
'Confirm Add Suggested NFT Page';
Expand Down
Loading