Skip to content

Commit

Permalink
Error display fixes & Hide tokens with 0 balances in Source Asset Pic…
Browse files Browse the repository at this point in the history
…ker (#2662)

* fix: hide empty balance tokens in source AssetPicker

* fix: hide errors when form is not filled
  • Loading branch information
nikarm22 authored Sep 23, 2024
1 parent 208c5d4 commit f43d006
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion wormhole-connect/src/hooks/useAmountValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Props = {
quotesMap: Record<string, QuoteResult | undefined>;
tokenSymbol: string;
isLoading: boolean;
disabled?: boolean;
};

export const useAmountValidation = (props: Props): HookReturn => {
Expand Down Expand Up @@ -57,7 +58,7 @@ export const useAmountValidation = (props: Props): HookReturn => {
const numAmount = Number.parseFloat(amount);

// Don't show errors when no amount is set or it's loading
if (!amount || !numAmount || props.isLoading) {
if (!amount || !numAmount || props.isLoading || props.disabled) {
return {};
}

Expand Down
27 changes: 24 additions & 3 deletions wormhole-connect/src/views/v2/Bridge/AssetPicker/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ const TokenList = (props: Props) => {
return;
}

// Exclude tokens with no balance on source list
if (props.isSource && !balance && props.wallet?.address) {
return;
}

// Exclude wormhole-wrapped tokens with no balance
if (
props.isSource &&
Expand Down Expand Up @@ -159,14 +164,30 @@ const TokenList = (props: Props) => {
return tokens;
}, [balances, props.tokenList, props.sourceToken]);

const noTokensMessage = useMemo(
() => (
<Typography variant="body2" color={theme.palette.grey.A400}>
No supported tokens found in wallet
</Typography>
),
[],
);

const shouldShowEmptyMessage =
sortedTokens.length === 0 && !isFetchingTokenBalances && !props.isFetching;

const searchList = (
<SearchableList<TokenConfig>
searchPlaceholder="Search for a token"
className={classes.tokenList}
listTitle={
<Typography fontSize={14} color={theme.palette.text.secondary}>
Tokens on {props.selectedChainConfig.displayName}
</Typography>
shouldShowEmptyMessage ? (
noTokensMessage
) : (
<Typography fontSize={14} color={theme.palette.text.secondary}>
Tokens on {props.selectedChainConfig.displayName}
</Typography>
)
}
loading={
props.isFetching && (
Expand Down
11 changes: 2 additions & 9 deletions wormhole-connect/src/views/v2/Bridge/Routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { makeStyles } from 'tss-react/mui';
import config from 'config';
import { RoutesConfig } from 'config/routes';
import SingleRoute from 'views/v2/Bridge/Routes/SingleRoute';
import AlertBannerV2 from 'components/v2/AlertBanner';

import type { RootState } from 'store';
import { RouteState } from 'store/transferInput';
Expand Down Expand Up @@ -128,14 +127,8 @@ const Routes = ({ ...props }: Props) => {
}, [routes, props.quotes]);

if (walletsConnected && supportedRoutes.length === 0 && Number(amount) > 0) {
return (
<AlertBannerV2
error
show
content="No route found for this transaction"
style={{ justifyContent: 'center' }}
/>
);
// Errors are displayed in AmountInput
return;
}

if (supportedRoutes.length === 0 || !walletsConnected || props.hasError) {
Expand Down
9 changes: 9 additions & 0 deletions wormhole-connect/src/views/v2/Bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,22 @@ const Bridge = () => {
sourceTokenArray,
);

const disableValidation =
!sendingWallet.address ||
!receivingWallet.address ||
!sourceChain ||
!sourceToken ||
!destChain ||
!destToken;

// Validate amount
const amountValidation = useAmountValidation({
balance: balances[sourceToken]?.balance,
routes: allSupportedRoutes,
quotesMap,
tokenSymbol: config.tokens[sourceToken]?.symbol ?? '',
isLoading: isFetchingBalances || isFetchingQuotes,
disabled: disableValidation,
});

// Get input validation result
Expand Down

0 comments on commit f43d006

Please sign in to comment.