-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat(ui): updates for address view #1941
Merged
+69
−23
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d80a198
address view v2 scaffolding
TalDerei 9e815ce
changeset:
TalDerei 071a99d
apply truncation to parent and pass props to text component
TalDerei e7fc796
add padding to storybook componenet
TalDerei 0055896
tailwind css linting
TalDerei 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 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,5 @@ | ||
--- | ||
'@penumbra-zone/ui': minor | ||
--- | ||
|
||
Update Address View component to match the latest designs |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,49 +4,85 @@ import { bech32mAddress } from '@penumbra-zone/bech32m/penumbra'; | |
import { CopyToClipboardButton } from '../CopyToClipboardButton'; | ||
import { AddressIcon } from './AddressIcon'; | ||
import { Text } from '../Text'; | ||
import { Density, useDensity } from '../utils/density'; | ||
|
||
export interface AddressViewProps { | ||
addressView: AddressView | undefined; | ||
copyable?: boolean; | ||
hideIcon?: boolean; | ||
truncate?: boolean; | ||
} | ||
|
||
export const getIconSize = (density: Density): number => { | ||
if (density === 'compact') { | ||
return 16; | ||
} | ||
if (density === 'slim') { | ||
return 12; | ||
} | ||
return 24; | ||
}; | ||
|
||
// Renders an address or an address view. | ||
// If the view is given and is "visible", the account information will be displayed instead. | ||
export const AddressViewComponent = ({ | ||
addressView, | ||
copyable = true, | ||
hideIcon, | ||
truncate = false, | ||
}: AddressViewProps) => { | ||
const density = useDensity(); | ||
|
||
if (!addressView?.addressView.value?.address) { | ||
return null; | ||
} | ||
|
||
const addressIndex = getAddressIndex.optional(addressView); | ||
|
||
// a randomized index has nonzero randomizer bytes | ||
// A randomized index has nonzero randomizer bytes | ||
const isRandomized = addressIndex?.randomizer.some(v => v); | ||
|
||
const encodedAddress = bech32mAddress(addressView.addressView.value.address); | ||
|
||
// Sub-account selector logic | ||
const getAccountLabel = (index: number) => | ||
index === 0 ? 'Main Account' : `Sub-Account ${index}`; | ||
|
||
return ( | ||
<div className='flex items-center gap-2 text-text-primary'> | ||
<div className={'flex items-center gap-2 text-text-primary'}> | ||
{!hideIcon && ( | ||
<div className='shrink'> | ||
<AddressIcon address={addressView.addressView.value.address} size={24} /> | ||
<AddressIcon | ||
address={addressView.addressView.value.address} | ||
size={getIconSize(density)} | ||
/> | ||
</div> | ||
)} | ||
|
||
{addressIndex ? ( | ||
<Text strong truncate> | ||
{isRandomized && 'IBC Deposit Address for '} | ||
{`Sub-Account #${addressIndex.account}`} | ||
</Text> | ||
) : ( | ||
<Text technical truncate> | ||
{encodedAddress} | ||
</Text> | ||
)} | ||
<div className={truncate ? 'max-w-[150px] truncate' : ''}> | ||
{/* eslint-disable-next-line no-nested-ternary -- can alternatively use dynamic prop object like {...fontProps} */} | ||
{addressIndex ? ( | ||
density === 'sparse' ? ( | ||
<Text strong-bold truncate={truncate}> | ||
{isRandomized && 'IBC Deposit Address for '} | ||
{getAccountLabel(addressIndex.account)} | ||
</Text> | ||
) : ( | ||
<Text small truncate={truncate}> | ||
{isRandomized && 'IBC Deposit Address for '} | ||
{getAccountLabel(addressIndex.account)} | ||
</Text> | ||
Comment on lines
+66
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: this makes me think of creating an alternative prop that would simply accept a string |
||
) | ||
) : density === 'sparse' ? ( | ||
<Text strong-bold truncate={truncate}> | ||
{encodedAddress} | ||
</Text> | ||
) : ( | ||
<Text small truncate={truncate}> | ||
{encodedAddress} | ||
</Text> | ||
)} | ||
</div> | ||
|
||
{copyable && !isRandomized && ( | ||
<div className='shrink'> | ||
|
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
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.
praise: thanks for covering all style cases in the docs 👍