Skip to content

Commit

Permalink
fix(suite): format long token symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Apr 17, 2024
1 parent 1a3a6c1 commit f859f33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions packages/suite/src/utils/wallet/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ export const enhanceTokensWithRates = (

return tokensWithRates;
};

export const formatTokenSymbol = (symbol?: string) => {
const tokenSymbol = symbol?.toUpperCase() || 'N/A';
const isTokenSymbolLong = tokenSymbol.length > 7;

return isTokenSymbolLong ? `${tokenSymbol.slice(0, 7)}...` : tokenSymbol;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import BigNumber from 'bignumber.js';
import { Timestamp, TokenAddress, TokenDefinitions } from '@suite-common/wallet-types';
import { TooltipSymbol, Translation } from 'src/components/suite';
import { NetworkSymbol, getNetworkFeatures } from '@suite-common/wallet-config';
import { enhanceTokensWithRates, sortTokensWithRates } from 'src/utils/wallet/tokenUtils';
import {
enhanceTokensWithRates,
formatTokenSymbol,
sortTokensWithRates,
} from 'src/utils/wallet/tokenUtils';
import { getShortFingerprint } from '@suite-common/wallet-utils';
import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer';
import { FiatCurrencyCode } from '@suite-common/suite-config';
Expand Down Expand Up @@ -57,21 +61,21 @@ export const buildTokenOptions = (
return;
}

const tokenName = token.symbol || 'N/A';
const tokenSymbol = formatTokenSymbol(token.symbol);

if (
!hasCoinDefinitions ||
isTokenDefinitionKnown(coinDefinitions?.data, symbol, token.contract)
) {
result[0].options.push({
value: token.contract,
label: tokenName.toUpperCase(),
label: tokenSymbol,
fingerprint: token.name,
});
} else {
unknownTokens.push({
value: token.contract,
label: `${tokenName.toUpperCase().slice(0, 7)}…`,
label: tokenSymbol,
fingerprint: token.name,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { breakpointMediaQueries } from '@trezor/styles';
import { selectFiatRatesByFiatRateKey } from '@suite-common/wallet-core';
import { TokenAddress } from '@suite-common/wallet-types';
import { FiatCurrencyCode } from '@suite-common/suite-config';
import { formatTokenSymbol } from 'src/utils/wallet/tokenUtils';

const Row = styled.div`
position: relative;
Expand Down Expand Up @@ -136,11 +137,11 @@ export const Amount = ({ output, outputId }: AmountProps) => {
const values = getValues();
const fiatCurrency = values?.outputs?.[0]?.currency;

const tokenSymbol = formatTokenSymbol(token?.symbol);

const tokenBalance = token ? (
<HiddenPlaceholder>
<TokenBalanceValue>{`${
token.balance
} ${token.symbol!.toUpperCase()}`}</TokenBalanceValue>
<TokenBalanceValue>{`${token.balance} ${tokenSymbol}`}</TokenBalanceValue>
</HiddenPlaceholder>
) : undefined;

Expand Down

0 comments on commit f859f33

Please sign in to comment.