Skip to content

Commit

Permalink
fix: unify solana and cardano missing symbol name length
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed May 8, 2024
1 parent 9be69a9 commit c817bdc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
12 changes: 9 additions & 3 deletions packages/blockchain-link-utils/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import type {
TransferType,
} from '@trezor/blockchain-link-types/src/common';

import { enhanceVinVout, filterTargets, sumVinVout, transformTarget } from './utils';
import {
enhanceVinVout,
filterTargets,
formatTokenSymbol,
sumVinVout,
transformTarget,
} from './utils';

export const transformUtxos = (utxos: BlockfrostUtxos[]): Utxo[] => {
const result: Utxo[] = [];
Expand Down Expand Up @@ -97,7 +103,7 @@ export const transformTokenInfo = (
type: 'BLOCKFROST',
name: token.fingerprint!, // this is safe as fingerprint is defined for all tokens except lovelace and lovelace is never included in account.tokens
contract: token.unit,
symbol: assetName || token.fingerprint!,
symbol: assetName || formatTokenSymbol(token.fingerprint!),
balance: token.quantity,
decimals: token.decimals,
};
Expand Down Expand Up @@ -159,7 +165,7 @@ export const filterTokenTransfers = (
transfers.push({
type,
name: asset.fingerprint,
symbol: assetName || asset.fingerprint,
symbol: assetName || formatTokenSymbol(asset.fingerprint),
contract: asset.unit,
decimals: asset.decimals,
amount: amount.toString(),
Expand Down
4 changes: 3 additions & 1 deletion packages/blockchain-link-utils/src/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import type {
import type { TokenInfo } from '@trezor/blockchain-link-types/src';
import { isCodesignBuild } from '@trezor/env-utils';

import { formatTokenSymbol } from './utils';

export type ApiTokenAccount = { account: AccountInfo<ParsedAccountData>; pubkey: PublicKey };

// Docs regarding solana programs: https://spl.solana.com/
Expand Down Expand Up @@ -56,7 +58,7 @@ export const getTokenNameAndSymbol = (mint: string, tokenDetailByMint: TokenDeta
? { name: tokenDetail.name, symbol: tokenDetail.symbol }
: {
name: mint,
symbol: `${mint.slice(0, 3)}...`,
symbol: formatTokenSymbol(mint),
};
};

Expand Down
8 changes: 8 additions & 0 deletions packages/blockchain-link-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ export const sortTxsFromLatest = (transactions: Transaction[]) => {

return txs;
};

// should be aligned with "formatTokenSymbol" in suite
export const formatTokenSymbol = (symbol: string) => {
const upperCasedSymbol = symbol.toUpperCase();
const isTokenSymbolLong = upperCasedSymbol.length > 7;

return isTokenSymbolLong ? `${upperCasedSymbol.slice(0, 7)}...` : upperCasedSymbol;
};
8 changes: 4 additions & 4 deletions packages/suite/src/utils/wallet/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export const enhanceTokensWithRates = (
return tokensWithRates;
};

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

return isTokenSymbolLong ? `${tokenSymbol.slice(0, 7)}...` : tokenSymbol;
return isTokenSymbolLong ? `${upperCasedSymbol.slice(0, 7)}...` : upperCasedSymbol;
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const buildTokenOptions = (
symbol: Account['symbol'],
coinDefinitions: TokenDefinitions['coin'],
) => {
// ETH option
// native token option
const result: Option[] = [
{
options: [{ value: null, fingerprint: undefined, label: symbol.toUpperCase() }],
Expand All @@ -61,7 +61,8 @@ export const buildTokenOptions = (
return;
}

const tokenSymbol = formatTokenSymbol(token.symbol);
// if symbol is missing, use start of contract address
const tokenSymbol = formatTokenSymbol(token.symbol || token.contract);

if (
!hasCoinDefinitions ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ export const Amount = ({ output, outputId }: AmountProps) => {
const values = getValues();
const fiatCurrency = values?.outputs?.[0]?.currency;

const tokenSymbol = formatTokenSymbol(token?.symbol);

const currentRate = useSelector(state =>
selectFiatRatesByFiatRateKey(
state,
Expand Down Expand Up @@ -227,7 +225,7 @@ export const Amount = ({ output, outputId }: AmountProps) => {
const isTokenSelected = !!token;
const tokenBalance = isTokenSelected ? (
<HiddenPlaceholder>
<TokenBalanceValue>{`${token.balance} ${tokenSymbol}`}</TokenBalanceValue>
<TokenBalanceValue>{`${token.balance} ${formatTokenSymbol(token?.symbol || token.contract)}`}</TokenBalanceValue>
</HiddenPlaceholder>
) : undefined;

Expand Down

0 comments on commit c817bdc

Please sign in to comment.