Skip to content

Commit

Permalink
exclude auctionNft assets from dashboard, send and swap (#1123)
Browse files Browse the repository at this point in the history
* remove auctionNft assets from dashboard, send and swap

* Update apps/minifront/src/components/dashboard/assets-table/index.tsx

Co-authored-by: Jesse Pinho <[email protected]>

* review fixes

---------

Co-authored-by: Jesse Pinho <[email protected]>
  • Loading branch information
Valentine1898 and jessepinho authored May 17, 2024
1 parent e4c9fce commit 31b2e92
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions apps/minifront/src/components/dashboard/assets-table/helpers.ts
Original file line number Diff line number Diff line change
@@ -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))),
);
Original file line number Diff line number Diff line change
Expand Up @@ -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<BalancesByAccount[]> => {
await throwIfPraxNotConnectedTimeout();
Expand Down Expand Up @@ -64,7 +65,7 @@ export default function AssetsTable() {
</TableRow>
</TableHeader>
<TableBody>
{account.balances.map((assetBalance, index) => (
{account.balances.filter(shouldDisplay).map((assetBalance, index) => (
<TableRow key={index}>
<TableCell>
<ValueViewComponent view={assetBalance.balanceView} />
Expand Down
19 changes: 19 additions & 0 deletions apps/minifront/src/components/send/helpers.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<BalancesResponse[]> => {
const balancesResponses = await getBalances();
return balancesResponses.filter(
balance => isUnknown(balance) || isTransferable(getMetadata(balance.balanceView)),
);
};
5 changes: 2 additions & 3 deletions apps/minifront/src/components/send/send-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,7 +21,7 @@ export interface SendLoaderResponse {

export const SendAssetBalanceLoader: LoaderFunction = async (): Promise<SendLoaderResponse> => {
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
Expand Down
1 change: 1 addition & 0 deletions apps/minifront/src/components/swap/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 31b2e92

Please sign in to comment.