-
Notifications
You must be signed in to change notification settings - Fork 2
Refactoring components and cleanup #13
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 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0e6f661
add Address, HashLink components; refactor tooltip
eugenebelov 25c2d62
refactor copy button to add animation like in cspr.live
eugenebelov a5933f6
refactor copy button
eugenebelov 3d93280
keep tooltip simple
eugenebelov fa9ce12
fix issues for components
eugenebelov a1b1e39
Update src/lib/utils/formatters.ts
eugenebelov a88ea2e
Update src/lib/components/copy/copy.tsx
eugenebelov 1a4d432
fix code review comments
eugenebelov 0775637
bump lib version
eugenebelov 66e59a5
refactor formatters
eugenebelov 203c26a
fix nameing
eugenebelov 85e29a8
sign commit
eugenebelov 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { Meta } from '@storybook/react'; | ||
| import { StoryObj } from '@storybook/react-vite'; | ||
| import { Address } from './address.tsx'; | ||
|
|
||
| const meta = { | ||
| component: Address, | ||
| title: 'Components/Display/Address', | ||
| // tags: ['autodocs', '!dev'], | ||
| args: { | ||
| publicKey: | ||
| '01f5f1fa995ab7e966428e5a1aed797526ad5b2454c50a63a7aaa2dfeae6a996c2', | ||
| minified: true, | ||
| tooltipCaption: 'public key', | ||
| avatarSize: 'default', | ||
| }, | ||
| argTypes: { | ||
| avatarSize: { | ||
| control: { type: 'select' }, | ||
| options: ['default', 'big', 'average', 'medium', 'small'], | ||
| description: 'The size of the avatar', | ||
| }, | ||
| publicKey: { control: 'text' }, | ||
| csprName: { control: 'text' }, | ||
| logo: { control: 'text' }, | ||
| name: { control: 'text' }, | ||
| tooltipCaption: { control: 'text' }, | ||
| minified: { control: 'boolean' }, | ||
| }, | ||
| } as Meta<typeof Address>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Primary: Story = {}; | ||
|
|
||
| export const withName: Story = { | ||
| args: { | ||
| name: 'Faucet', | ||
| csprName: 'faucet.cspr', | ||
| logo: 'https://cspr-image-proxy-cdn.dev.make.services/64,fit,ttl86400/https://casper-assets.s3.amazonaws.com/accounts/faucet.svg', | ||
| }, | ||
| }; | ||
|
|
||
| export const withLogo: Story = { | ||
| args: { | ||
| name: 'Casper Space DJ', | ||
| logo: 'https://image-proxy-cdn.make.services/64,fit,ttl86400/https://makegroup.io/wp-content/uploads/2024/04/logo.svg', | ||
| }, | ||
| }; |
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,172 @@ | ||
| import React from 'react'; | ||
| import { Avatar, AvatarProps } from '../avatar/avatar'; | ||
|
|
||
| import styled from 'styled-components'; | ||
| import BodyText from '../body-text/body-text.tsx'; | ||
| import Tooltip from '../tooltip/tooltip.tsx'; | ||
| import { HashLink } from '../hash-link/hash-link.tsx'; | ||
| import FlexRow from '../flex-row/flex-row.tsx'; | ||
| import FlexColumn from '../flex-column/flex-column.tsx'; | ||
| import { HashLength } from '../../utils/formatters.ts'; | ||
| import { Size } from '../../types.ts'; | ||
| import TruncateBox from '../truncate-box/truncate-box.tsx'; | ||
|
|
||
| interface AddressProps { | ||
| loading: boolean; | ||
| logo: string | null; | ||
| name: string | undefined; | ||
| csprName?: string | undefined; | ||
| publicKey: string | null | undefined; | ||
| tooltipCaption?: string; | ||
| navigateToPath?: string; | ||
| hashLength?: HashLength; | ||
| nameSize?: Size; | ||
| avatarSize?: AvatarProps['size']; | ||
| hashFontSize?: HashFontSize; | ||
| minified?: boolean; | ||
| /** @redundunt use navigateToPath instead */ | ||
| navigationPath?: keyof any; | ||
| /** @deprecated use minified instead */ | ||
| copyNotifyingStyle?: 'full' | 'tiny'; | ||
| } | ||
|
|
||
| const StyledTruncateBox = styled(TruncateBox)(() => ({ | ||
| height: '20px', | ||
| })); | ||
|
|
||
| export enum HashFontSize { | ||
| 'default' = 'default', | ||
| 'big' = 'big', | ||
| } | ||
|
|
||
| const StyledHashWrapper = ({ hashFontSize, ...props }) => { | ||
|
eugenebelov marked this conversation as resolved.
Outdated
|
||
| return ( | ||
| <BodyText | ||
| {...props} | ||
| size={3} | ||
| scale={hashFontSize === HashFontSize.big ? 'sm' : props.scale} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const shortenCsprName = ( | ||
| csprName: string, | ||
| visibleStringLength: HashLength = HashLength.SMALL, | ||
| ) => { | ||
| const [name, extension] = csprName.split(/(.cspr)$/); | ||
|
|
||
| const MIN_TRUNCATE_LENGTH = HashLength.TINY * 2 + 3; | ||
| const hashLength = name.length; | ||
|
|
||
| if (hashLength === HashLength.FULL || hashLength <= MIN_TRUNCATE_LENGTH) { | ||
| return csprName; | ||
| } | ||
|
|
||
| const firstPart = name.substring(0, visibleStringLength); | ||
| const secondPart = name.substring(hashLength - visibleStringLength); | ||
|
|
||
| return `${firstPart}...${secondPart}${extension}`; | ||
| }; | ||
|
|
||
| // Check usage of this component | ||
| export const Address = ({ | ||
| publicKey, | ||
| csprName, | ||
| logo, | ||
| name, | ||
| loading, | ||
| hashLength, | ||
| minified, | ||
| navigateToPath, | ||
| tooltipCaption, | ||
| nameSize = 5, | ||
| avatarSize = 'default', | ||
| hashFontSize = HashFontSize.default, | ||
| }: AddressProps) => { | ||
| if (loading || !publicKey) { | ||
| return ( | ||
| <FlexRow align="center" itemsSpacing={12}> | ||
| <Avatar hash={publicKey} loading={loading} size={avatarSize} /> | ||
| </FlexRow> | ||
| ); | ||
| } | ||
|
|
||
| if (publicKey === '00') { | ||
| // publicKey == '00' means that it is a Immediate Switch Block | ||
| // NOTE: as part of Casper network node v1.5, the node software now creates an "immediate switch block" on upgrades; | ||
| // there are no rewards for this block. it simply captures the information after application of the upgrade, | ||
| // which allows this to be deterministically detected | ||
| return ( | ||
| <FlexRow align="center" itemsSpacing={12}> | ||
| <Avatar hash={publicKey} loading={loading} size={avatarSize} /> | ||
| <FlexColumn> | ||
| <BodyText size={2} monotype> | ||
| {publicKey} | ||
| </BodyText> | ||
| <BodyText size={3} variation="darkGray" noWrap> | ||
| System | ||
| </BodyText> | ||
| </FlexColumn> | ||
| </FlexRow> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <FlexRow align="center" itemsSpacing={12}> | ||
| {logo ? ( | ||
| <Avatar | ||
| src={logo} | ||
| loading={loading} | ||
| size={avatarSize} | ||
| alt={'Account logo'} | ||
| /> | ||
| ) : ( | ||
| <Avatar hash={publicKey} loading={loading} size={avatarSize} /> | ||
| )} | ||
|
|
||
| <Tooltip caption={tooltipCaption} tooltipContent={publicKey}> | ||
| <FlexColumn> | ||
| {name ? ( | ||
| <> | ||
| <StyledHashWrapper | ||
| hashFontSize={hashFontSize} | ||
| monotype={!csprName} | ||
| > | ||
| <HashLink | ||
| minified={minified} | ||
| href={navigateToPath} | ||
| hash={publicKey} | ||
| csprName={ | ||
| csprName && shortenCsprName(csprName, HashLength.TINY) | ||
| } | ||
| hashLength={hashLength} | ||
| /> | ||
| </StyledHashWrapper> | ||
| <FlexRow itemsSpacing={6} align={'center'}> | ||
| <FlexRow> | ||
| <StyledTruncateBox size={nameSize}> | ||
| <BodyText size={3} variation="darkGray" noWrap> | ||
| {name} | ||
| </BodyText> | ||
| </StyledTruncateBox> | ||
| </FlexRow> | ||
| </FlexRow> | ||
| </> | ||
| ) : ( | ||
| <StyledHashWrapper hashFontSize={hashFontSize} monotype={!csprName}> | ||
| <HashLink | ||
| href={navigateToPath} | ||
| hash={publicKey} | ||
| csprName={ | ||
| csprName && shortenCsprName(csprName, HashLength.TINY) | ||
| } | ||
| hashLength={hashLength} | ||
| minified={minified} | ||
| /> | ||
| </StyledHashWrapper> | ||
| )} | ||
| </FlexColumn> | ||
| </Tooltip> | ||
| </FlexRow> | ||
| ); | ||
| }; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.