From 31b2e920da55ee6b3d83264798b1aeb5798c98fb Mon Sep 17 00:00:00 2001 From: Valentine Date: Fri, 17 May 2024 10:33:01 +0000 Subject: [PATCH] exclude auctionNft assets from dashboard, send and swap (#1123) * remove auctionNft assets from dashboard, send and swap * Update apps/minifront/src/components/dashboard/assets-table/index.tsx Co-authored-by: Jesse Pinho * review fixes --------- Co-authored-by: Jesse Pinho --- .../dashboard/assets-table/helpers.ts | 17 +++++++++++++++++ .../dashboard/assets-table/index.tsx | 3 ++- apps/minifront/src/components/send/helpers.ts | 19 +++++++++++++++++++ .../src/components/send/send-form/index.tsx | 5 ++--- apps/minifront/src/components/swap/helpers.ts | 1 + 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 apps/minifront/src/components/dashboard/assets-table/helpers.ts diff --git a/apps/minifront/src/components/dashboard/assets-table/helpers.ts b/apps/minifront/src/components/dashboard/assets-table/helpers.ts new file mode 100644 index 0000000000..bf749fe040 --- /dev/null +++ b/apps/minifront/src/components/dashboard/assets-table/helpers.ts @@ -0,0 +1,17 @@ +import { assetPatterns } from '@penumbra-zone/types/assets'; +import { getDisplay } from '@penumbra-zone/getters/metadata'; +import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; +import { getMetadata } from '@penumbra-zone/getters/value-view'; + +// We don't have to disclose auctionNft to the user since it is a kind of utility asset needed only +// for the implementation of the Dutch auction +const hiddenAssetPatterns = [assetPatterns.auctionNft]; + +export const isUnknown = (balancesResponse: BalancesResponse) => + balancesResponse.balanceView?.valueView.case === 'unknownAssetId'; + +export const shouldDisplay = (balance: BalancesResponse) => + isUnknown(balance) || + hiddenAssetPatterns.every( + pattern => !pattern.matches(getDisplay(getMetadata(balance.balanceView))), + ); diff --git a/apps/minifront/src/components/dashboard/assets-table/index.tsx b/apps/minifront/src/components/dashboard/assets-table/index.tsx index b044806e77..ce7736d3fb 100644 --- a/apps/minifront/src/components/dashboard/assets-table/index.tsx +++ b/apps/minifront/src/components/dashboard/assets-table/index.tsx @@ -14,6 +14,7 @@ import { ValueViewComponent } from '@penumbra-zone/ui/components/ui/tx/view/valu import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax'; import { EquivalentValues } from './equivalent-values'; import { Fragment } from 'react'; +import { shouldDisplay } from './helpers'; export const AssetsLoader: LoaderFunction = async (): Promise => { await throwIfPraxNotConnectedTimeout(); @@ -64,7 +65,7 @@ export default function AssetsTable() { - {account.balances.map((assetBalance, index) => ( + {account.balances.filter(shouldDisplay).map((assetBalance, index) => ( diff --git a/apps/minifront/src/components/send/helpers.ts b/apps/minifront/src/components/send/helpers.ts index c689b76867..aa3ca64b28 100644 --- a/apps/minifront/src/components/send/helpers.ts +++ b/apps/minifront/src/components/send/helpers.ts @@ -1,5 +1,12 @@ import { isAddress } from '@penumbra-zone/bech32m/penumbra'; import { Validation } from '../shared/validation-result'; +import { assetPatterns } from '@penumbra-zone/types/assets'; +import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; +import { getDisplay } from '@penumbra-zone/getters/metadata'; +import { BalancesResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; +import { getBalances } from '../../fetchers/balances'; +import { getMetadata } from '@penumbra-zone/getters/value-view'; +import { isUnknown } from '../dashboard/assets-table/helpers'; export const penumbraAddrValidation = (): Validation => { return { @@ -8,3 +15,15 @@ export const penumbraAddrValidation = (): Validation => { checkFn: (addr: string) => Boolean(addr) && !isAddress(addr), }; }; + +const nonTransferableAssetPatterns = [assetPatterns.proposalNft, assetPatterns.auctionNft]; + +export const isTransferable = (metadata: Metadata) => + nonTransferableAssetPatterns.every(pattern => !pattern.matches(getDisplay(metadata))); + +export const getTransferableBalancesResponses = async (): Promise => { + const balancesResponses = await getBalances(); + return balancesResponses.filter( + balance => isUnknown(balance) || isTransferable(getMetadata(balance.balanceView)), + ); +}; diff --git a/apps/minifront/src/components/send/send-form/index.tsx b/apps/minifront/src/components/send/send-form/index.tsx index 3e5994244b..221afffc07 100644 --- a/apps/minifront/src/components/send/send-form/index.tsx +++ b/apps/minifront/src/components/send/send-form/index.tsx @@ -4,9 +4,8 @@ import { useStore } from '../../../state'; import { sendSelector, sendValidationErrors } from '../../../state/send'; import { InputBlock } from '../../shared/input-block'; import { LoaderFunction, useLoaderData } from 'react-router-dom'; -import { getBalances } from '../../../fetchers/balances'; import { useMemo } from 'react'; -import { penumbraAddrValidation } from '../helpers'; +import { getTransferableBalancesResponses, penumbraAddrValidation } from '../helpers'; import { throwIfPraxNotConnectedTimeout } from '@penumbra-zone/client/prax'; import InputToken from '../../shared/input-token'; import { useRefreshFee } from './use-refresh-fee'; @@ -22,7 +21,7 @@ export interface SendLoaderResponse { export const SendAssetBalanceLoader: LoaderFunction = async (): Promise => { await throwIfPraxNotConnectedTimeout(); - const assetBalances = await getBalances(); + const assetBalances = await getTransferableBalancesResponses(); if (assetBalances[0]) { // set initial account if accounts exist and asset if account has asset list diff --git a/apps/minifront/src/components/swap/helpers.ts b/apps/minifront/src/components/swap/helpers.ts index 0516a8c360..b181768efd 100644 --- a/apps/minifront/src/components/swap/helpers.ts +++ b/apps/minifront/src/components/swap/helpers.ts @@ -23,6 +23,7 @@ const nonSwappableAssetPatterns = [ assetPatterns.lpNft, assetPatterns.proposalNft, assetPatterns.votingReceipt, + assetPatterns.auctionNft, // In theory, these asset types are swappable, but we have removed them for now to get a better UX assetPatterns.delegationToken,