forked from PolkaGate/extension
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: put reused codes into 2 components (PolkaGate#1614)
* refactor: put reused codes into 2 components * style: decrease identicon size in FS
- Loading branch information
Showing
5 changed files
with
145 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/AccountBodyFs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* eslint-disable react/jsx-first-prop-new-line */ | ||
/* eslint-disable react/jsx-max-props-per-line */ | ||
|
||
import { Grid, IconButton, useTheme } from '@mui/material'; | ||
import React, { useCallback } from 'react'; | ||
|
||
import { noop } from '@polkadot/util'; | ||
|
||
import { Identity, Infotip, OptionalCopyButton, ShortAddress2, VaadinIcon } from '../../../components'; | ||
import { useIdentity, useInfo, useTranslation } from '../../../hooks'; | ||
import { showAccount } from '../../../messaging'; | ||
|
||
export const EyeIconFullScreen = ({ isHidden, onClick }: { isHidden: boolean | undefined, onClick?: React.MouseEventHandler<HTMLButtonElement> | undefined }) => { | ||
const { t } = useTranslation(); | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<Infotip text={isHidden ? t('This account is hidden from websites') : t('This account is visible to websites')}> | ||
<IconButton onClick={onClick} sx={{ height: '20px', ml: '7px', mt: '13px', p: 0, width: '28px' }}> | ||
<VaadinIcon icon={isHidden ? 'vaadin:eye-slash' : 'vaadin:eye'} style={{ color: `${theme.palette.secondary.light}`, height: '20px' }} /> | ||
</IconButton> | ||
</Infotip> | ||
); | ||
}; | ||
|
||
interface Props { | ||
address: string | undefined; | ||
goToDetails?: () => void; | ||
gridSize?: number; | ||
} | ||
|
||
function AccountBodyFs ({ address, goToDetails = noop, gridSize }: Props): React.ReactElement { | ||
const { account, api, chain, formatted, genesisHash } = useInfo(address); | ||
|
||
const accountInfo = useIdentity(genesisHash, formatted); | ||
|
||
const toggleVisibility = useCallback((): void => { | ||
address && showAccount(address, account?.isHidden || false).catch(console.error); | ||
}, [account?.isHidden, address]); | ||
|
||
return ( | ||
<Grid container direction='column' item sx={{ borderRight: '1px solid', borderRightColor: 'divider', px: '7px' }} xs={gridSize}> | ||
<Grid container item justifyContent='space-between'> | ||
<Identity | ||
accountInfo={accountInfo} | ||
address={address} | ||
api={api} | ||
chain={chain} | ||
noIdenticon | ||
onClick={goToDetails} | ||
style={{ width: 'calc(100% - 40px)' }} | ||
subIdOnly | ||
/> | ||
<Grid item width='40px'> | ||
<EyeIconFullScreen | ||
isHidden={account?.isHidden} | ||
onClick={toggleVisibility} | ||
/> | ||
</Grid> | ||
</Grid> | ||
<Grid alignItems='center' container item> | ||
<Grid container item sx={{ '> div div:last-child': { width: 'auto' } }} xs> | ||
<ShortAddress2 address={formatted || address} charsCount={40} style={{ fontSize: '10px', fontWeight: 300 }} /> | ||
</Grid> | ||
<Grid container item width='fit-content'> | ||
<OptionalCopyButton address={address} /> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
); | ||
} | ||
|
||
export default React.memo(AccountBodyFs); |
40 changes: 40 additions & 0 deletions
40
...es/extension-polkagate/src/fullscreen/homeFullScreen/partials/AccountIdenticonIconsFS.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
/* eslint-disable react/jsx-max-props-per-line */ | ||
|
||
import { Grid } from '@mui/material'; | ||
import React from 'react'; | ||
|
||
import { Identicon } from '../../../components'; | ||
import { useIdentity, useInfo } from '../../../hooks'; | ||
import AccountIconsFs from '../../accountDetails/components/AccountIconsFs'; | ||
|
||
interface Props { | ||
address: string | undefined; | ||
} | ||
|
||
function AccountIdenticonIconsFS ({ address }: Props): React.ReactElement { | ||
const { chain, formatted, genesisHash } = useInfo(address); | ||
|
||
const accountInfo = useIdentity(genesisHash, formatted); | ||
|
||
return ( | ||
<Grid container item sx={{ borderRight: '1px solid', borderRightColor: 'divider', pr: '8px', width: 'fit-content' }}> | ||
<Grid container item pr='7px' sx={{ '> div': { height: 'fit-content' }, m: 'auto', width: 'fit-content' }}> | ||
<Identicon | ||
iconTheme={chain?.icon ?? 'polkadot'} | ||
prefix={chain?.ss58Format ?? 42} | ||
size={55} | ||
value={formatted || address} | ||
/> | ||
</Grid> | ||
<AccountIconsFs | ||
accountInfo={accountInfo} | ||
address={address} | ||
/> | ||
</Grid> | ||
); | ||
} | ||
|
||
export default React.memo(AccountIdenticonIconsFS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters