-
Notifications
You must be signed in to change notification settings - Fork 5
refactor: put reused codes into 2 components #1614
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider making the address prop required and more strictly typed.
Since this component is meant to display account information, the address should probably be required. Also, consider using a more specific type for the address string (e.g., a type that ensures it's a valid substrate address).