feat(explorer): simplify party accounts page (#5240)

This commit is contained in:
Edd 2023-11-15 11:15:25 +00:00 committed by GitHub
parent 96658134ee
commit c10084d441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import { useAssetDataProvider } from '@vegaprotocol/assets'; import { useAssetDataProvider } from '@vegaprotocol/assets';
import { addDecimalsFormatNumber } from '@vegaprotocol/utils'; import { addDecimalsFixedFormatNumber } from '@vegaprotocol/utils';
import { AssetLink } from '../links'; import { AssetLink } from '../links';
export type AssetBalanceProps = { export type AssetBalanceProps = {
@ -23,12 +23,12 @@ const AssetBalance = ({
const label = const label =
!loading && asset && asset.decimals !loading && asset && asset.decimals
? addDecimalsFormatNumber(price, asset.decimals) ? addDecimalsFixedFormatNumber(price, asset.decimals)
: price; : price;
return ( return (
<div className="inline-block"> <div className="inline-block">
<span>{label}</span>{' '} <span className="font-mono">{label}</span>{' '}
{showAssetLink && asset?.id ? ( {showAssetLink && asset?.id ? (
<AssetLink showAssetSymbol={showAssetSymbol} assetId={assetId} /> <AssetLink showAssetSymbol={showAssetSymbol} assetId={assetId} />
) : null} ) : null}

View File

@ -1,6 +1,7 @@
import { AccountManager } from '@vegaprotocol/accounts'; import { useExplorerPartyAssetsQuery } from '../__generated__/Party-assets';
import { useCallback } from 'react'; import { AssetLink, MarketLink } from '../../../../components/links';
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets'; import AssetBalance from '../../../../components/asset-balance/asset-balance';
import { AccountTypeMapping } from '@vegaprotocol/types';
interface PartyAccountsProps { interface PartyAccountsProps {
partyId: string; partyId: string;
@ -12,21 +13,71 @@ interface PartyAccountsProps {
* appearing first and... tbd * appearing first and... tbd
*/ */
export const PartyAccounts = ({ partyId }: PartyAccountsProps) => { export const PartyAccounts = ({ partyId }: PartyAccountsProps) => {
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore(); const { data } = useExplorerPartyAssetsQuery({
const onClickAsset = useCallback( variables: { partyId },
(assetId?: string) => { });
assetId && openAssetDetailsDialog(assetId);
}, const party = data?.partiesConnection?.edges[0]?.node;
[openAssetDetailsDialog] const accounts =
); party?.accountsConnection?.edges?.filter((edge) => edge?.node) || [];
return ( return (
<div className="block min-h-44 h-60 4 w-full border-red-800 relative"> <div className="block min-h-44 h-60 4 w-full border-red-800 relative">
<AccountManager <table>
partyId={partyId} <thead>
onClickAsset={onClickAsset} <tr>
isReadOnly={true} <th className="text-right px-4">Balance</th>
/> <th className="text-left px-4">Type</th>
<th className="text-left px-4">Market</th>
<th className="text-left px-4">Asset</th>
</tr>
</thead>
<tbody>
{accounts
.sort((a, b) => {
// Sort by asset id, then market id, with general accounts first
if (!a) {
return 1;
}
if (!b) {
return -1;
}
if (a.node.asset.id !== b.node.asset.id) {
return a.node.asset.id.localeCompare(b.node.asset.id);
}
if (a.node.type === 'ACCOUNT_TYPE_GENERAL') return -1;
if (b.node.type === 'ACCOUNT_TYPE_GENERAL') return 1;
if (a.node.market && b.node.market) {
return a.node.market.id.localeCompare(b.node.market.id);
} else {
return a.node.type.localeCompare(b.node.type);
}
})
.map((e) => {
if (!e) return null;
const { type, asset, balance, market } = e.node;
return (
<tr className="border-t border-neutral-300 dark:border-neutral-600">
<td className="px-4 text-right">
<AssetBalance
assetId={asset.id}
price={balance}
showAssetSymbol={true}
/>
</td>
<td className="px-4">{AccountTypeMapping[type]}</td>
<td className="px-4">
{market?.id ? <MarketLink id={market.id} /> : '-'}
</td>
<td className="px-4">
<AssetLink assetId={asset.id} />
</td>
</tr>
);
})}
</tbody>
</table>
</div> </div>
); );
}; };