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

Show equivalent values in the assets table #886

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ValueView } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { asValueView } from '@penumbra-zone/getters/src/equivalent-value';
import {
getDisplayDenomFromView,
getEquivalentValues,
} from '@penumbra-zone/getters/src/value-view';
import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/value';

export const EquivalentValues = ({ valueView }: { valueView?: ValueView }) => {
const equivalentValuesAsValueViews = (getEquivalentValues.optional()(valueView) ?? []).map(
asValueView,
);

return equivalentValuesAsValueViews.map(equivalentValueAsValueView => (
<ValueViewComponent
key={getDisplayDenomFromView(equivalentValueAsValueView)}
view={equivalentValueAsValueView}
variant='equivalent'
/>
));
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { LoaderFunction, useLoaderData } from 'react-router-dom';
import { AddressIcon } from '@penumbra-zone/ui/components/ui/address-icon';
import { AddressComponent } from '@penumbra-zone/ui/components/ui/address-component';
import { BalancesByAccount, getBalancesByAccount } from '../../fetchers/balances/by-account';
import { BalancesByAccount, getBalancesByAccount } from '../../../fetchers/balances/by-account';
import { Table, TableBody, TableCell, TableRow } from '@penumbra-zone/ui/components/ui/table';
import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/value';
import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client';
import { EquivalentValues } from './equivalent-values';

export const AssetsLoader: LoaderFunction = async (): Promise<BalancesByAccount[]> => {
await throwIfPraxNotConnectedTimeout();
Expand Down Expand Up @@ -52,7 +53,10 @@ export default function AssetsTable() {
{a.balances.map((assetBalance, index) => (
<TableRow key={index}>
<TableCell>
<ValueViewComponent view={assetBalance.balanceView} />
<div className='flex flex-wrap gap-2'>
<ValueViewComponent view={assetBalance.balanceView} />
<EquivalentValues valueView={assetBalance.balanceView} />
</div>
</TableCell>
</TableRow>
))}
Expand Down
50 changes: 32 additions & 18 deletions packages/ui/components/ui/tx/view/value/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { CopyIcon } from '@radix-ui/react-icons';
import { Amount } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/num/v1/num_pb';
import { fromBaseUnitAmount } from '@penumbra-zone/types/src/amount';
import { Pill } from '../../../pill';
import { ConditionalWrap } from '../../../conditional-wrap';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../../../tooltip';

interface ValueViewProps {
view: ValueView | undefined;
Expand Down Expand Up @@ -41,24 +43,36 @@ export const ValueViewComponent = ({
const symbol = metadata.symbol || 'Unknown Asset';

return (
<Pill variant={variant === 'default' ? 'default' : 'dashed'}>
<div className='flex min-w-0 items-center gap-1'>
{showIcon && (
<div className='-ml-2 mr-1 flex size-6 items-center justify-center rounded-full'>
<AssetIcon metadata={metadata} />
</div>
)}
{showValue && (
<span className='leading-[15px]'>
{variant === 'equivalent' && <>~ </>}
{formattedAmount}
</span>
)}
{showDenom && (
<span className='truncate font-mono text-xs text-muted-foreground'>{symbol}</span>
)}
</div>
</Pill>
<ConditionalWrap
condition={variant === 'equivalent'}
wrap={children => (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>{children}</TooltipTrigger>
<TooltipContent>Estimated equivalent value</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
>
<Pill variant={variant === 'default' ? 'default' : 'dashed'}>
<div className='flex min-w-0 items-center gap-1'>
{showIcon && (
<div className='-ml-2 mr-1 flex size-6 items-center justify-center rounded-full'>
<AssetIcon metadata={metadata} />
</div>
)}
{showValue && (
<span className='leading-[15px]'>
{variant === 'equivalent' && <>~ </>}
{formattedAmount}
</span>
)}
{showDenom && (
<span className='truncate font-mono text-xs text-muted-foreground'>{symbol}</span>
)}
</div>
</Pill>
</ConditionalWrap>
);
}

Expand Down
Loading