-
Notifications
You must be signed in to change notification settings - Fork 17
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
Prettify action details in several action views #767
Changes from all commits
2ec0610
f18deeb
8585227
ec555ac
14cbc87
67aa4b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ export interface CardProps extends React.HTMLAttributes<HTMLDivElement> { | |
|
||
const Card = React.forwardRef<HTMLDivElement, CardProps>( | ||
({ className, gradient, children, ...props }, ref) => { | ||
const baseClasses = 'bg-charcoal rounded-lg shadow-sm p-[30px]'; | ||
const baseClasses = 'bg-charcoal rounded-lg shadow-sm p-[30px] overflow-hidden'; | ||
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. To ensure truncating strings works |
||
return ( | ||
<div | ||
ref={ref} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,23 +12,41 @@ import { ReactNode } from 'react'; | |
* </ActionDetails> | ||
* ``` | ||
*/ | ||
export const ActionDetails = ({ children }: { children: ReactNode }) => { | ||
return <div className='flex flex-col gap-2'>{children}</div>; | ||
export const ActionDetails = ({ children, label }: { children: ReactNode; label?: string }) => { | ||
return ( | ||
<div className='flex flex-col gap-2'> | ||
{!!label && <div className='font-bold'>{label}</div>} | ||
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. |
||
|
||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
const Separator = () => ( | ||
// eslint-disable-next-line tailwindcss/no-unnecessary-arbitrary-value | ||
<div className='mx-2 h-px min-w-8 grow border-b-[1px] border-dotted border-light-brown' /> | ||
); | ||
|
||
const ActionDetailsRow = ({ label, children }: { label: string; children: ReactNode }) => { | ||
const ActionDetailsRow = ({ | ||
label, | ||
children, | ||
truncate, | ||
}: { | ||
label: string; | ||
children: ReactNode; | ||
/** | ||
* If `children` is a string, passing `truncate` will automatically truncate | ||
* the text if it doesn't fit in a single line. | ||
*/ | ||
truncate?: boolean; | ||
}) => { | ||
return ( | ||
<div className='flex items-center justify-between'> | ||
<span className='break-keep'>{label}</span> | ||
<span className='whitespace-nowrap break-keep'>{label}</span> | ||
|
||
<Separator /> | ||
|
||
{children} | ||
{truncate ? <span className='truncate'>{children}</span> : children} | ||
</div> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,38 @@ import { Delegate } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/ | |
import { ViewBox } from './viewbox'; | ||
import { joinLoHiAmount } from '@penumbra-zone/types/src/amount'; | ||
import { bech32IdentityKey } from '@penumbra-zone/types/src/identity-key'; | ||
import { ActionDetails } from './action-details'; | ||
|
||
/** | ||
* Render a `Delegate` action. | ||
* | ||
* @todo: Make this nicer :) | ||
*/ | ||
export const DelegateComponent = ({ value }: { value: Delegate }) => { | ||
return ( | ||
<ViewBox | ||
label='Delegate' | ||
visibleContent={ | ||
<div className='flex flex-col gap-2'> | ||
<div> | ||
<span className='font-bold'>Epoch index:</span> {value.epochIndex.toString()} | ||
</div> | ||
<ActionDetails> | ||
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. |
||
<ActionDetails.Row label='Epoch index'>{value.epochIndex.toString()}</ActionDetails.Row> | ||
|
||
{!!value.delegationAmount && ( | ||
<div> | ||
<span className='font-bold'>Delegation amount:</span>{' '} | ||
<ActionDetails.Row label='Delegation amount'> | ||
{joinLoHiAmount(value.delegationAmount).toString()} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
|
||
{!!value.unbondedAmount && ( | ||
<div> | ||
<span className='font-bold'>Unbonded amount:</span>{' '} | ||
<ActionDetails.Row label='Unbonded amount'> | ||
{joinLoHiAmount(value.unbondedAmount).toString()} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
|
||
{/** @todo: Render validator name/etc. after fetching? */} | ||
{!!value.validatorIdentity && ( | ||
<div> | ||
<span className='font-bold'>Validator identity:</span>{' '} | ||
<ActionDetails.Row label='Validator identity' truncate> | ||
{bech32IdentityKey(value.validatorIdentity)} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
</div> | ||
</ActionDetails> | ||
} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
import { ViewBox } from './viewbox'; | ||
import { SwapView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/dex/v1/dex_pb'; | ||
import { bech32Address } from '@penumbra-zone/types/src/address'; | ||
import { fromBaseUnitAmount, joinLoHiAmount } from '@penumbra-zone/types/src/amount'; | ||
import { uint8ArrayToBase64 } from '@penumbra-zone/types/src/base64'; | ||
import { ActionDetails } from './action-details'; | ||
import { AddressView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb'; | ||
import { AddressViewComponent } from './address-view'; | ||
|
||
export const SwapViewComponent = ({ value }: { value: SwapView }) => { | ||
if (value.swapView.case === 'visible') { | ||
const { tradingPair, delta1I, delta2I, claimFee, claimAddress } = | ||
value.swapView.value.swapPlaintext!; | ||
|
||
const encodedAddress = bech32Address(claimAddress!); | ||
const addressView = new AddressView({ | ||
addressView: { case: 'decoded', value: { address: claimAddress } }, | ||
}); | ||
|
||
return ( | ||
<ViewBox | ||
label='Swap' | ||
visibleContent={ | ||
<div className='flex flex-col gap-2'> | ||
<div> | ||
<b>Asset 1:</b> | ||
<div className='ml-5'> | ||
<b>ID: </b> | ||
<div className='flex flex-col gap-8'> | ||
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. 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. (In follow-up PR(s), this will move closer to this proposed design.) |
||
<ActionDetails label='Asset 1'> | ||
<ActionDetails.Row label='ID' truncate> | ||
{uint8ArrayToBase64(tradingPair!.asset1!.inner)} | ||
</div> | ||
<div className='ml-5'> | ||
<b>Amount: </b> | ||
<span className='font-mono'>{joinLoHiAmount(delta1I!).toString()}</span> | ||
</div> | ||
</div> | ||
<div> | ||
<b>Asset 2:</b> | ||
<div className='ml-5'> | ||
<b>ID: </b> | ||
</ActionDetails.Row> | ||
<ActionDetails.Row label='Amount'> | ||
{joinLoHiAmount(delta1I!).toString()} | ||
</ActionDetails.Row> | ||
</ActionDetails> | ||
|
||
<ActionDetails label='Asset 2'> | ||
<ActionDetails.Row label='ID' truncate> | ||
{uint8ArrayToBase64(tradingPair!.asset2!.inner)} | ||
</div> | ||
<div className='ml-5'> | ||
<b>Amount: </b> | ||
<span className='font-mono'>{joinLoHiAmount(delta2I!).toString()}</span> | ||
</div> | ||
</div> | ||
<div> | ||
<b>Claim:</b> | ||
<div className='ml-5'> | ||
<b>Address: </b> | ||
{encodedAddress} | ||
</div> | ||
<div className='ml-5'> | ||
<b>Fee: </b> | ||
<span className='font-mono'> | ||
{fromBaseUnitAmount(claimFee!.amount!, 0).toFormat()} upenumbra | ||
</span> | ||
</div> | ||
</div> | ||
</ActionDetails.Row> | ||
<ActionDetails.Row label='Amount'> | ||
{joinLoHiAmount(delta2I!).toString()} | ||
</ActionDetails.Row> | ||
</ActionDetails> | ||
|
||
<ActionDetails label='Claim'> | ||
<ActionDetails.Row label='Address'> | ||
<AddressViewComponent view={addressView} /> | ||
</ActionDetails.Row> | ||
<ActionDetails.Row label='Fee'> | ||
{fromBaseUnitAmount(claimFee!.amount!, 0).toFormat()} upenumbra | ||
</ActionDetails.Row> | ||
</ActionDetails> | ||
</div> | ||
} | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,40 @@ import { Undelegate } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/cor | |
import { ViewBox } from './viewbox'; | ||
import { joinLoHiAmount } from '@penumbra-zone/types/src/amount'; | ||
import { bech32IdentityKey } from '@penumbra-zone/types/src/identity-key'; | ||
import { ActionDetails } from './action-details'; | ||
|
||
/** | ||
* Render an `Undelegate` action. | ||
* | ||
* @todo: Make this nicer :) | ||
*/ | ||
export const UndelegateComponent = ({ value }: { value: Undelegate }) => { | ||
return ( | ||
<ViewBox | ||
label='Undelegate' | ||
visibleContent={ | ||
<div className='flex flex-col gap-2'> | ||
<div> | ||
<span className='font-bold'>Epoch index:</span> {value.startEpochIndex.toString()} | ||
</div> | ||
<ActionDetails> | ||
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. |
||
<ActionDetails.Row label='Epoch index'> | ||
{value.startEpochIndex.toString()} | ||
</ActionDetails.Row> | ||
|
||
{!!value.delegationAmount && ( | ||
<div> | ||
<span className='font-bold'>Delegation amount:</span>{' '} | ||
<ActionDetails.Row label='Delegation amount'> | ||
{joinLoHiAmount(value.delegationAmount).toString()} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
|
||
{!!value.unbondedAmount && ( | ||
<div> | ||
<span className='font-bold'>Unbonded amount:</span>{' '} | ||
<ActionDetails.Row label='Unbonded amount'> | ||
{joinLoHiAmount(value.unbondedAmount).toString()} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
|
||
{/** @todo: Render validator name/etc. after fetching? */} | ||
{!!value.validatorIdentity && ( | ||
<div> | ||
<span className='font-bold'>Validator identity:</span>{' '} | ||
<ActionDetails.Row label='Validator identity' truncate> | ||
{bech32IdentityKey(value.validatorIdentity)} | ||
</div> | ||
</ActionDetails.Row> | ||
)} | ||
</div> | ||
</ActionDetails> | ||
} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ export interface ViewBoxProps { | |
visibleContent?: React.ReactElement; | ||
} | ||
|
||
const Label = ({ label }: { label: string }) => <span className='text-lg'>{label}</span>; | ||
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. Just making the label a little bigger, to differentiate from the view box's contents |
||
|
||
export const ViewBox = ({ label, visibleContent }: ViewBoxProps) => { | ||
return ( | ||
<div | ||
|
@@ -19,11 +21,11 @@ export const ViewBox = ({ label, visibleContent }: ViewBoxProps) => { | |
> | ||
<div className='flex items-center gap-2 self-start'> | ||
<span className={cn('text-base font-bold', !visibleContent ? 'text-gray-600' : '')}> | ||
{visibleContent && label} | ||
{visibleContent && <Label label={label} />} | ||
{!visibleContent && ( | ||
<div className='flex gap-2'> | ||
<IncognitoIcon fill='#4b5563' /> | ||
<span>{label}</span> | ||
<Label label={label} /> | ||
</div> | ||
)} | ||
</span> | ||
|
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.
<AddressComponent />
no longer shortens addresses to a specific number of characters — instead, it's more flexible, expanding or contracting to fit its container. So we'll manually narrow it via a parent<div />
here.