Skip to content
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

Shortened amount props for ValueViewComponent #1915

Merged
merged 4 commits into from
Nov 20, 2024
Merged

Conversation

grod220
Copy link
Collaborator

@grod220 grod220 commented Nov 19, 2024

Updating ValueViewComponent to support displaying for this view on the dex explorer:

Screenshot 2024-11-19 at 5 48 29 PM

At the moment those display raw numbers, but given the metadata of the assets, we need them to be ValueViewComponent to handle the display exponents.

Copy link

changeset-bot bot commented Nov 19, 2024

🦋 Changeset detected

Latest commit: 8737509

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@penumbra-zone/types Minor
@penumbra-zone/ui Minor
minifront Patch
node-status Patch
@penumbra-zone/crypto-web Major
@penumbra-zone/query Major
@penumbra-zone/services Major
@penumbra-zone/storage Major
@penumbra-zone/ui-deprecated Patch
@penumbra-zone/wasm Major
@repo/tailwind-config Patch
@penumbra-zone/perspective Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@grod220 grod220 force-pushed the value-view-additions branch from 0c29102 to 955e09a Compare November 19, 2024 16:50
Copy link
Contributor

github-actions bot commented Nov 19, 2024

Visit the preview URL for this PR (updated for commit 8737509):

https://penumbra-ui-preview--pr1915-value-view-additions-molvhrc8.web.app

(expires Wed, 27 Nov 2024 15:04:43 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 709d729610ef7a6369b23f1cb2b820a60cc685b1

Comment on lines +35 to +39
export function round({ value, decimals, roundingMode = 'round' }: RoundOptions): string {
const roundingFn = roundingStrategies[roundingMode];
const roundedNumber = roundingFn(value, decimals);
return roundedNumber.toFixed(decimals);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both round() and shortify() come from the dex explorer. However, expanded these quite a bit w/ testing as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, after publishing, will delete the local one in the dex explorer

Comment on lines 38 to 49
/**
* If true, the asset icon will be hidden.
*/
hideIcon?: boolean;
/**
* If true, the asset symbol will be hidden.
*/
hideSymbol?: boolean;
/**
* If true, the displayed amount will be shortened.
*/
abbreviate?: boolean;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if these kinds of props are in the spirit of the v2 UI component prop style

Copy link
Collaborator Author

@grod220 grod220 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also these design changes should be validated on the storybook preview link in the main page of the PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: validated storybook props in preview

Comment on lines +123 to +124
<div className='shrink grow' title={formattedAmount}>
<ValueText density={density}>{formattedAmount}</ValueText>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug fix, the min width made it too wide

Comment on lines 98 to 105
<span
className={cn(
density === 'sparse' ? technical : detailTechnical,
priority === 'primary' ? 'text-text-primary' : 'text-secondary-dark',
)}
>
{children}
</span>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to have this else branch as the Pill was giving the font/color in the other branch and this one wasn't getting any.

@grod220 grod220 requested a review from a team November 19, 2024 17:02
Comment on lines 38 to 49
/**
* If true, the asset icon will be hidden.
*/
hideIcon?: boolean;
/**
* If true, the asset symbol will be hidden.
*/
hideSymbol?: boolean;
/**
* If true, the displayed amount will be shortened.
*/
abbreviate?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: validated storybook props in preview

const formattedAmount = getFormattedAmtFromValueView(valueView, true);
let formattedAmount: string;
if (abbreviate) {
const amount = getFormattedAmtFromValueView(valueView, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: what if getFormattedAmtFromValueView returns something unparseable (eg. null, undefined)? should we add validation guards to shortify to prevent breakage?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function returns a string type, so all good.

</div>
<div className='min-w-[50px] shrink grow truncate' title={symbol}>
<ValueText density={density}>{symbol}</ValueText>
<div className='shrink grow' title={formattedAmount}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; using both shrink-0 and shrink in the same contexts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shrink-0 prevents the icon from shrinking, The uses of shrink on the other two say that is' ok to shrink.

Copy link
Collaborator Author

@grod220 grod220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to add a few more tweaks to better support the compact version

const formattedAmount = getFormattedAmtFromValueView(valueView, true);
let formattedAmount: string;
if (abbreviate) {
const amount = getFormattedAmtFromValueView(valueView, false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function returns a string type, so all good.

</div>
<div className='min-w-[50px] shrink grow truncate' title={symbol}>
<ValueText density={density}>{symbol}</ValueText>
<div className='shrink grow' title={formattedAmount}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shrink-0 prevents the icon from shrinking, The uses of shrink on the other two say that is' ok to shrink.

@grod220 grod220 merged commit 291bc7d into main Nov 20, 2024
8 checks passed
@grod220 grod220 deleted the value-view-additions branch November 20, 2024 15:12
@grod220 grod220 mentioned this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants