Skip to content

Commit

Permalink
fix(no-tx-addr): fixed ui
Browse files Browse the repository at this point in the history
  • Loading branch information
BLuEScioN committed Jun 26, 2024
1 parent 172c144 commit eee1324
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 54 deletions.
27 changes: 1 addition & 26 deletions src/app/_components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ import { ErrorBoundary } from 'react-error-boundary';
import { ExplorerError } from '../../common/types/Error';
import { ErrorBox } from './ErrorBox';

export class ExpectedError extends Error {
constructor(message: string) {
super(message);
this.name = 'RetryableError';
}
}

export class RetryableError extends Error {
constructor(message: string) {
super(message);
this.name = 'RetryableError';
}
}

export class NonRetryableError extends Error {
constructor(message: string) {
super(message);
this.name = 'NonRetryableError';
}
}

interface ErrorBoundaryProps<WrapperProps extends PropsWithChildren<Record<string, unknown>>> {
Wrapper?: ComponentType<WrapperProps>;
wrapperProps?: WrapperProps;
Expand All @@ -48,10 +27,6 @@ export function ExplorerErrorBoundary<WrapperProps extends PropsWithChildren<unk
{({ reset }) => (
<ErrorBoundary
fallbackRender={({ error, resetErrorBoundary }) => {
let showTryAgain = tryAgainButton;
if (error instanceof NonRetryableError) {
showTryAgain = false;
}
return (
<Wrapper {...wrapperProps}>
{renderContent ? (
Expand All @@ -63,7 +38,7 @@ export function ExplorerErrorBoundary<WrapperProps extends PropsWithChildren<unk
reset();
resetErrorBoundary();
}}
tryAgainButton={showTryAgain}
tryAgainButton={tryAgainButton}
homeButton={homeButton}
/>
)}
Expand Down
10 changes: 4 additions & 6 deletions src/app/address/[principal]/PageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ export default function AddressPage({ params: { principal } }: any) {
/>
<AddressTxListTabs address={principal} />
</Stack>
{balance && (
<Stack gap={8}>
<StxBalance address={principal} />
<TokenBalanceCard address={principal} />
</Stack>
)}
<Stack gap={8}>
<StxBalance address={principal} />
<TokenBalanceCard address={principal} />
</Stack>
</AddressPageLayout>
</>
);
Expand Down
3 changes: 0 additions & 3 deletions src/app/address/[principal]/StxBalance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as React from 'react';
import { Circle } from '../../../../common/components/Circle';
import { Section } from '../../../../common/components/Section';
import { useAccountBalance } from '../../../../common/queries/useAccountBalance';
import { hasStxBalance } from '../../../../common/utils/accounts';
import { microToStacks } from '../../../../common/utils/utils';
import { Box } from '../../../../ui/Box';
import { Grid } from '../../../../ui/Grid';
Expand Down Expand Up @@ -65,8 +64,6 @@ function StxBalanceBase({ address }: StxBalanceProps) {
</Box>
);

if (!hasStxBalance(balance)) return null;

return (
<Section title={qrShowing ? 'Address QR code' : 'STX Balance'} topRight={TopRight}>
{!qrShowing ? (
Expand Down
6 changes: 3 additions & 3 deletions src/app/address/[principal]/TokenBalanceCard/FtBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const TokenAssetListItem = dynamic(
);

export const FtBalance: React.FC<{ balance: AddressBalanceResponse }> = ({ balance }) => {
const FTokens = Object.keys(balance.fungible_tokens).filter(
const ft = Object.keys(balance.fungible_tokens).filter(

Check warning on line 23 in src/app/address/[principal]/TokenBalanceCard/FtBalance.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/TokenBalanceCard/FtBalance.tsx#L23

Added line #L23 was not covered by tests
key => Number(balance.fungible_tokens[key]?.balance) > 0
);

return FTokens.length ? (
return ft.length > 0 ? (
<>
{FTokens?.map((key, index, arr) => (
{ft?.map((key, index, arr) => (
<TokenAssetListItem
amount={balance.fungible_tokens[key]?.balance || ''}
key={index}
Expand Down
11 changes: 2 additions & 9 deletions src/app/address/[principal]/TokenBalanceCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
'use client';

import * as React from 'react';
import { Fragment, useMemo } from 'react';
import { useMemo } from 'react';

Check warning on line 3 in src/app/address/[principal]/TokenBalanceCard/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/TokenBalanceCard/index.tsx#L3

Added line #L3 was not covered by tests

import { cvToJSON, hexToCV } from '@stacks/transactions';

import { Section } from '../../../../common/components/Section';
import {
useAccountBalance,
useSuspenseAccountBalance,
} from '../../../../common/queries/useAccountBalance';
import { useAccountBalance } from '../../../../common/queries/useAccountBalance';

Check warning on line 8 in src/app/address/[principal]/TokenBalanceCard/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/address/[principal]/TokenBalanceCard/index.tsx#L8

Added line #L8 was not covered by tests
import { useSuspenseNftHoldings } from '../../../../common/queries/useNftHoldings';
import { hasTokenBalance } from '../../../../common/utils/accounts';
import { hexToString } from '../../../../common/utils/utils';
import { Tab } from '../../../../ui/Tab';
import { TabList } from '../../../../ui/TabList';
Expand Down Expand Up @@ -52,8 +47,6 @@ function TokenBalanceCardBase({ address, ...rest }: TokenBalanceCardProps) {
[nftHoldings]
);

if (!hasTokenBalance(balance)) return null;

return (
<Section title="Holdings" {...rest}>
<Tabs isLazy>
Expand Down
17 changes: 11 additions & 6 deletions src/common/queries/useAccountBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import { AddressBalanceResponse } from '@stacks/stacks-blockchain-api-types';
import { useApi } from '../api/useApi';
import { ONE_MINUTE } from './query-stale-time';

const ACCOUNT_BALANCE_QUERY_KEY = 'accountBalance';

Check warning on line 13 in src/common/queries/useAccountBalance.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useAccountBalance.ts#L13

Added line #L13 was not covered by tests

export function useAccountBalance(
address?: string,
address: string,
options: Omit<UseQueryOptions<any, any, AddressBalanceResponse, any>, 'queryKey' | 'queryFn'> = {}
) {
const api = useApi();
return useQuery({
queryKey: ['accountBalance', address],
queryKey: [ACCOUNT_BALANCE_QUERY_KEY, address],
queryFn: () => {
return api.accountsApi.getAccountBalance({
principal: address!,
const response = api.accountsApi.getAccountBalance({

Check warning on line 23 in src/common/queries/useAccountBalance.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useAccountBalance.ts#L23

Added line #L23 was not covered by tests
principal: address,
});
return response;

Check warning on line 26 in src/common/queries/useAccountBalance.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useAccountBalance.ts#L26

Added line #L26 was not covered by tests
},
staleTime: ONE_MINUTE,
enabled: !!address,
Expand All @@ -38,11 +41,13 @@ export function useSuspenseAccountBalance(
const api = useApi();
if (!address) throw new Error('Address is required');
return useSuspenseQuery({
queryKey: ['accountBalance', address],
queryKey: [ACCOUNT_BALANCE_QUERY_KEY, address],
queryFn: () => {
return api.accountsApi.getAccountBalance({
const response = api.accountsApi.getAccountBalance({

Check warning on line 46 in src/common/queries/useAccountBalance.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useAccountBalance.ts#L46

Added line #L46 was not covered by tests
principal: address,
});

return response;

Check warning on line 50 in src/common/queries/useAccountBalance.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useAccountBalance.ts#L50

Added line #L50 was not covered by tests
},
staleTime: ONE_MINUTE,
...options,
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const getUsdValue = (
stxPrice: number,
isInMicroStacks = false
): string => {
if (!stxAmount || !stxPrice) return 'N/A';
if (!stxPrice) return 'N/A';
const amountInStx = isInMicroStacks ? microToStacks(stxAmount) : stxAmount;
const price = amountInStx * stxPrice;
return price > 0 && price < 0.01 ? '<$0.01' : usdFormatter.format(price);
Expand Down

0 comments on commit eee1324

Please sign in to comment.